skillmkt 0.4.36 → 0.4.38

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.
@@ -1,18 +1,21 @@
1
1
  // audit [name|--all] — 重跑静态审核刷新 scans/;--llm 附加语义审(批次6 全量)
2
2
  import path from 'node:path';
3
3
  import fs from 'node:fs';
4
- import { auditDir, writeScan } from '../lib/audit.js';
4
+ import { auditDir, writeScan, verdictOf, RULE_IDS } from '../lib/audit.js';
5
5
  import { llmAudit } from '../lib/ai.js';
6
6
  import { walk } from '../lib/package.js';
7
7
  import { ok, warn, fail, info, auditTag } from '../lib/render.js';
8
+ import { readLibrary, writeLibrary } from '../lib/hub.js';
9
+ import { readYAML } from '../../pipeline/lib/util.js';
8
10
  import { L } from '../lib/i18n.js';
9
11
 
10
12
  export async function run(ctx) {
11
13
  const flags = ctx.flags.raw;
12
14
  const skills = ctx.library.skills || {};
15
+ if (flags.allow && !RULE_IDS.includes(flags.allow)) { fail(L(`未知规则 id: ${flags.allow}(可选: ${RULE_IDS.join(' ')})`, `unknown rule id: ${flags.allow} (one of: ${RULE_IDS.join(' ')})`)); return 1; }
13
16
  if (flags.all && ctx.args.length) { fail(L('--all 和指定名字只能二选一', '--all and specific names are mutually exclusive')); return 1; }
14
17
  const names = flags.all ? Object.keys(skills) : ctx.args;
15
- if (!names.length) { fail(L('用法: skillmkt audit <名字|--all> [--llm]', 'usage: skillmkt audit <name|--all> [--llm]')); return 1; }
18
+ if (!names.length) { fail(L('用法: skillmkt audit <名字|--all> [--llm] [--allow <规则id>]', 'usage: skillmkt audit <name|--all> [--llm] [--allow <rule-id>]')); return 1; }
16
19
  let worst = 'clean';
17
20
  const order = { clean: 0, suspicious: 1, stripped: 1, malicious: 2 };
18
21
  for (const name of names) {
@@ -27,9 +30,20 @@ export async function run(ctx) {
27
30
  if (lr) { r.llm = lr; info(` llm: ${lr.verdict}${lr.reasons?.length ? ` — ${lr.reasons.join('; ')}` : ''}`); }
28
31
  else warn(L(' LLM 审核不可用——沿用静态检查结论', ' llm audit unavailable — keeping static verdict'));
29
32
  }
30
- writeScan(ctx.hub, name, r);
33
+ // 豁免:历史 allow + 本次 --allow;豁免的 finding 标 allowed 不定罪但留档
34
+ const old = readYAML(path.join(ctx.hub, 'scans', `${name}.yml`)) || {};
35
+ const allow = [...new Set([...(old.allow || []), ...(flags.allow ? [flags.allow] : [])])];
36
+ for (const f of r.findings) if (allow.includes(f.rule)) f.allowed = true;
37
+ r.verdict = verdictOf(r.findings, r.stripped);
38
+ writeScan(ctx.hub, name, r, { llm: r.llm || null, allow });
39
+ // library 里的审核标记跟着最新结论走
40
+ if (skills[name] && skills[name].audit !== r.verdict) {
41
+ const lib = readLibrary(ctx.hub);
42
+ if (lib.skills?.[name]) { lib.skills[name].audit = r.verdict; writeLibrary(ctx.hub, lib); }
43
+ }
31
44
  if (order[r.verdict] > order[worst]) worst = r.verdict;
32
- info(`${name}: ${auditTag(r.verdict)}${r.findings.length ? L(`(${r.findings.length} 处发现)`, ` (${r.findings.length} findings)`) : ''}`);
45
+ const waived = r.findings.filter((f) => f.doc || f.allowed).length;
46
+ info(`${name}: ${auditTag(r.verdict)}${r.findings.length ? L(`(${r.findings.length} 处发现${waived ? `,${waived} 处豁免` : ''})`, ` (${r.findings.length} findings${waived ? `, ${waived} waived` : ''})`) : ''}`);
33
47
  }
34
48
  ok(L('审核完成', 'audit done'));
35
49
  return worst === 'malicious' ? 2 : 0;
@@ -5,6 +5,9 @@ import { walk } from './package.js';
5
5
  import { writeYAMLFile } from './hub.js';
6
6
 
7
7
  const TEXT_EXT = /\.(md|txt|json|ya?ml|toml|mjs|cjs|js|ts|sh|py|html?|css)$/i;
8
+ const DOC_EXT = /\.(md|markdown|txt|rst|adoc)$/i;
9
+ // 文档语境豁免只对"下载型"curl 生效——真危险的是这些(管道执行/反弹shell/编码绕过)
10
+ const EGRESS_DANGER = /\|\s*(?:sudo\s+)?(?:ba|z)?sh\b|\bnc\b\s+-|\/dev\/tcp\/|\bbase64\b/i;
8
11
  const STRIP_DIRS = /^(scripts?|bin|tools?|hooks?|install|\.github\/workflows)$/i;
9
12
  const EXEC_EXT = /\.(sh|bash|zsh|exe|bat|cmd|ps1|com|dll|so|dylib|app)$/i;
10
13
 
@@ -52,23 +55,30 @@ export function auditDir(dir, { strip = true } = {}) {
52
55
  lines.forEach((line, i) => {
53
56
  if (rule.re.test(line)) {
54
57
  const severe = rule.severe === true ? true : !!rule.severe?.test?.(line);
55
- findings.push({ rule: rule.id, file: rel, line: i + 1, excerpt: line.trim().slice(0, 120), severe });
58
+ // 文档里的"下载型"curl 降级为 doc——记录但不单独定罪(维护说明/用户手册常见)
59
+ const doc = rule.id === 'egress-cmd' && DOC_EXT.test(base) && !EGRESS_DANGER.test(line);
60
+ findings.push({ rule: rule.id, file: rel, line: i + 1, excerpt: line.trim().slice(0, 120), severe, ...(doc ? { doc: true } : {}) });
56
61
  }
57
62
  });
58
63
  }
59
64
  }
60
65
 
61
- // verdict 归并(代码判定,不是模型)
62
- const has = (id) => findings.some((f) => f.rule === id);
63
- const severe = findings.some((f) => f.severe);
64
- const suspiciousCount = findings.reduce((n, f) => n + (RULES.find((r) => r.id === f.rule)?.weight ?? 1), 0);
65
- let verdict = 'clean';
66
- if (has('pii-harvest') || severe || (has('secret-pattern') && has('egress-cmd')) || suspiciousCount >= 5) verdict = 'malicious';
67
- else if (findings.length || stripped.length) verdict = 'suspicious';
66
+ return { verdict: verdictOf(findings, stripped), findings, stripped: strip ? stripped : [] };
67
+ }
68
68
 
69
- return { verdict, findings, stripped: strip ? stripped : [] };
69
+ // verdict 归并(代码判定,不是模型)。doc=文档语境误报,allowed=用户人工豁免——都不定罪但仍记录
70
+ export function verdictOf(findings, stripped = []) {
71
+ const live = findings.filter((f) => !f.doc && !f.allowed);
72
+ const has = (id) => live.some((f) => f.rule === id);
73
+ const severe = live.some((f) => f.severe);
74
+ const suspiciousCount = live.reduce((n, f) => n + (RULES.find((r) => r.id === f.rule)?.weight ?? 1), 0);
75
+ if (has('pii-harvest') || severe || (has('secret-pattern') && has('egress-cmd')) || suspiciousCount >= 5) return 'malicious';
76
+ if (live.length || stripped.length) return 'suspicious';
77
+ return 'clean';
70
78
  }
71
79
 
80
+ export const RULE_IDS = RULES.map((r) => r.id);
81
+
72
82
  // 剥离:copy 时排除 stripped 相对路径
73
83
  export function stripFilter(stripped) {
74
84
  const set = new Set(stripped);
@@ -76,12 +86,13 @@ export function stripFilter(stripped) {
76
86
  return (rel) => !set.has(rel) && !tops.has(rel.split('/')[0]);
77
87
  }
78
88
 
79
- export function writeScan(hub, name, result, { llm = null } = {}) {
89
+ export function writeScan(hub, name, result, { llm = null, allow = [] } = {}) {
80
90
  writeYAMLFile(path.join(hub, 'scans', `${name}.yml`), {
81
91
  name,
82
92
  scanned_at: new Date().toISOString(),
83
93
  static: { findings: result.findings, stripped: result.stripped },
84
94
  verdict: result.verdict,
95
+ ...(allow.length ? { allow } : {}),
85
96
  ...(llm ? { llm } : {}),
86
97
  });
87
98
  }
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', 'policy']);
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', 'allow']);
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) {
@@ -118,12 +118,15 @@ const H = {
118
118
  --dry-run reports without writing (also lists newly detected agents).`,
119
119
  },
120
120
  audit: {
121
- zh: `用法: skillmkt audit <名字|--all> [--llm] [--json]
121
+ zh: `用法: skillmkt audit <名字|--all> [--llm] [--allow <规则id>] [--json]
122
122
  安全审核:scripts/密钥模式/外联指令等确定性检查;--llm 追加本地模型分析。
123
- 结论词:干净 / 可疑 / 已剔除 / 恶意 / 已隔离。`,
124
- en: `usage: skillmkt audit <name|--all> [--llm] [--json]
123
+ --allow 豁免误报规则(该 skill 的重审/升级都认;规则 id: egress-cmd 等)。
124
+ 文档里的下载型 curl 自动降级不计罪。结论词:干净 / 可疑 / 已剔除 / 恶意 / 已隔离。`,
125
+ en: `usage: skillmkt audit <name|--all> [--llm] [--allow <rule-id>] [--json]
125
126
  Security audit: deterministic checks for scripts/secret patterns/outbound
126
127
  instructions; --llm adds local-model analysis.
128
+ --allow suppresses a false-positive rule (sticks across re-audits/upgrades).
129
+ Download-style curl in docs is downgraded automatically.
127
130
  Verdicts: clean / suspicious / stripped / malicious / quarantined.`,
128
131
  },
129
132
  update: {
@@ -251,6 +251,10 @@ async function render() {
251
251
 
252
252
  if (tab === 'skills') {
253
253
  const skills = Object.entries(S.library.skills || {});
254
+ // 先取数据再拼整页——innerHTML 只能赋一次;分段 += 会重建 DOM 冲掉已绑事件
255
+ const ext = await api('/scan');
256
+ const up = S.upstream.skills || {};
257
+ const outs = Object.entries(up).filter(([, u]) => u.outdated);
254
258
  app.innerHTML = `<h2>${t('sk_h', skills.length)}</h2>
255
259
  <p class="desc">${t('sk_desc')}</p>`
256
260
  + (skills.map(([n, s]) => `
@@ -259,7 +263,17 @@ async function render() {
259
263
  <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>
260
264
  <div class="tgbox" data-box="${esc(n)}" style="display:none;margin-top:10px"></div>
261
265
  <div class="dtbox" data-dbox="${esc(n)}" style="display:none;margin-top:10px"></div></div>`).join('')
262
- || `<div class="empty">${t('sk_empty')}</div>`);
266
+ || `<div class="empty">${t('sk_empty')}</div>`)
267
+ + `<h2>${t('agents_h')}</h2>
268
+ <p class="desc">${t('agents_desc')}</p>`
269
+ + (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('')
270
+ + `<h2>${t('maint_h')}</h2>
271
+ <div class="card row"><button id="m-upd">${t('upd_refresh')}</button><button id="m-sync">${t('sync_btn')}</button>
272
+ ${outs.length ? `<button id="m-upg" class="primary">${t('upd_all')}(${outs.length})</button>` : ''}<span id="m-out" class="mut"></span></div>`
273
+ + (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('') : '')
274
+ + (ext?.length ? `<h2>${t('ext_h', ext.length)}</h2><p class="desc">${t('ext_desc')}</p>`
275
+ + ext.map((e) => `<div class="card row"><b>${esc(e.name)}</b><span class="mut">${esc(e.where)} · ${esc(e.dir)}</span>
276
+ <button class="adopt" data-d="${esc(e.path || '')}" style="margin-left:auto">${t('ext_adopt')}</button><span class="aout mut"></span></div>`).join('') : '');
263
277
  // 移除:两段式确认(第一下变确认文案,3 秒内再点才真删)
264
278
  app.querySelectorAll('[data-rm]').forEach((b) => {
265
279
  let armed = false, timer = null;
@@ -311,15 +325,6 @@ async function render() {
311
325
  refresh();
312
326
  };
313
327
  });
314
- app.innerHTML += `<h2>${t('agents_h')}</h2>
315
- <p class="desc">${t('agents_desc')}</p>`
316
- + (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('');
317
- const up = S.upstream.skills || {};
318
- const outs = Object.entries(up).filter(([, u]) => u.outdated);
319
- app.innerHTML += `<h2>${t('maint_h')}</h2>
320
- <div class="card row"><button id="m-upd">${t('upd_refresh')}</button><button id="m-sync">${t('sync_btn')}</button>
321
- ${outs.length ? `<button id="m-upg" class="primary">${t('upd_all')}(${outs.length})</button>` : ''}<span id="m-out" class="mut"></span></div>`
322
- + (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('') : '');
323
328
  const runOp = async (btn, path, body) => {
324
329
  btn.disabled = true; const old = btn.textContent; btn.textContent = t('op_busy');
325
330
  const r = await api(path, { method: 'POST', body: JSON.stringify(body || {}) });
@@ -329,34 +334,27 @@ async function render() {
329
334
  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(); };
330
335
  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); };
331
336
  app.querySelector('#m-upg')?.addEventListener('click', async (e) => { await runOp(e.target, '/upgrade'); refresh(); });
332
- app.querySelectorAll('.upg').forEach((b) => b.onclick = async (e) => {
337
+ app.querySelectorAll('.upg').forEach((b) => b.onclick = async () => {
333
338
  const r = await runOp(e.target, '/upgrade', { name: b.dataset.n });
334
339
  const o = b.parentElement.querySelector('.uout'); if (o) o.textContent = r.code === 0 ? t('op_done') : (r.out || '').slice(0, 100);
335
340
  if (r.code === 0) refresh();
336
341
  });
337
-
338
- // 收编区:agent 目录里没收编的 skill(主动拉 /api/scan 才显示)
339
- const ext = await api('/scan');
340
- if (ext?.length) {
341
- app.innerHTML += `<h2>${t('ext_h', ext.length)}</h2><p class="desc">${t('ext_desc')}</p>`
342
- + ext.map((e) => `<div class="card row"><b>${esc(e.name)}</b><span class="mut">${esc(e.where)} · ${esc(e.dir)}</span>
343
- <button class="adopt" data-d="${esc(e.path || '')}" style="margin-left:auto">${t('ext_adopt')}</button><span class="aout mut"></span></div>`).join('');
344
- app.querySelectorAll('.adopt').forEach((b) => b.onclick = async () => {
345
- b.disabled = true; b.textContent = t('op_busy');
346
- const permissive = b.dataset.perm === '1';
347
- const r = await api('/install', { method: 'POST', body: JSON.stringify({ ref: b.dataset.d, permissive }) });
348
- const o = b.parentElement.querySelector('.aout');
349
- if (r.code === 0) { if (o) o.textContent = t('op_done'); refresh(); return; }
350
- b.disabled = false;
351
- if (isSuspicious(r.out) && !permissive) {
352
- b.dataset.perm = '1'; b.textContent = t('ext_force');
353
- if (o) o.textContent = t('mk_susp');
354
- } else {
355
- b.textContent = t('ext_adopt');
356
- if (o) o.textContent = (r.out || '').split('\n').filter((l) => l.trim()).pop()?.slice(0, 100);
357
- }
358
- });
359
- }
342
+ // 收编:可疑→"仍要收编"知情确认
343
+ app.querySelectorAll('.adopt').forEach((b) => b.onclick = async () => {
344
+ b.disabled = true; b.textContent = t('op_busy');
345
+ const permissive = b.dataset.perm === '1';
346
+ const r = await api('/install', { method: 'POST', body: JSON.stringify({ ref: b.dataset.d, permissive }) });
347
+ const o = b.parentElement.querySelector('.aout');
348
+ if (r.code === 0) { if (o) o.textContent = t('op_done'); refresh(); return; }
349
+ b.disabled = false;
350
+ if (isSuspicious(r.out) && !permissive) {
351
+ b.dataset.perm = '1'; b.textContent = t('ext_force');
352
+ if (o) o.textContent = t('mk_susp');
353
+ } else {
354
+ b.textContent = t('ext_adopt');
355
+ if (o) o.textContent = (r.out || '').split('\n').filter((l) => l.trim()).pop()?.slice(0, 100);
356
+ }
357
+ });
360
358
  }
361
359
 
362
360
  if (tab === 'market') {
@@ -521,6 +519,10 @@ async function render() {
521
519
  + (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>
522
520
  <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('')
523
521
  || `<div class="empty">${t('rv_empty')}</div>`);
522
+ const decs = (S.decisions || []).filter((d) => d.status === 'active');
523
+ if (decs.length) app.innerHTML += `<h2>${t('dec_h', decs.length)}</h2>
524
+ <p class="desc">${t('dec_desc')}</p>`
525
+ + 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('');
524
526
  app.querySelectorAll('.ra').forEach((b) => b.onclick = async () => {
525
527
  b.disabled = true; const old = b.textContent; b.textContent = t('op_busy');
526
528
  const r = await api('/audit', { method: 'POST', body: JSON.stringify({ name: b.dataset.n }) });
@@ -528,10 +530,6 @@ async function render() {
528
530
  b.parentElement.querySelector('.raout').textContent = (r.out || '').split('\n').pop().slice(0, 80);
529
531
  if (r.code === 0) refresh();
530
532
  });
531
- const decs = (S.decisions || []).filter((d) => d.status === 'active');
532
- if (decs.length) app.innerHTML += `<h2>${t('dec_h', decs.length)}</h2>
533
- <p class="desc">${t('dec_desc')}</p>`
534
- + 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('');
535
533
  }
536
534
 
537
535
  if (tab === 'setup') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillmkt",
3
- "version": "0.4.36",
3
+ "version": "0.4.38",
4
4
  "type": "module",
5
5
  "description": "Local-first agent skill manager: install, audit, merge, distribute.",
6
6
  "license": "MIT",