skillmkt 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +213 -2
- package/client/bin/skillmkt.js +84 -0
- package/client/commands/audit.js +34 -0
- package/client/commands/build.js +61 -0
- package/client/commands/config.js +34 -0
- package/client/commands/conflicts.js +14 -0
- package/client/commands/decide.js +19 -0
- package/client/commands/diff.js +52 -0
- package/client/commands/doctor.js +109 -0
- package/client/commands/download.js +35 -0
- package/client/commands/init.js +82 -0
- package/client/commands/install.js +169 -0
- package/client/commands/list.js +56 -0
- package/client/commands/merge.js +49 -0
- package/client/commands/outdated.js +34 -0
- package/client/commands/registry.js +42 -0
- package/client/commands/remove.js +48 -0
- package/client/commands/resolve.js +76 -0
- package/client/commands/rollback.js +30 -0
- package/client/commands/search.js +46 -0
- package/client/commands/serve.js +99 -0
- package/client/commands/show.js +52 -0
- package/client/commands/sync.js +54 -0
- package/client/commands/targets.js +75 -0
- package/client/commands/update.js +39 -0
- package/client/commands/upgrade.js +75 -0
- package/client/lib/ai.js +67 -0
- package/client/lib/audit.js +87 -0
- package/client/lib/autoarb.js +26 -0
- package/client/lib/conflicts.js +65 -0
- package/client/lib/ctx.js +68 -0
- package/client/lib/daemon.js +47 -0
- package/client/lib/dashboard.js +29 -0
- package/client/lib/decide.js +43 -0
- package/client/lib/evidence.js +56 -0
- package/client/lib/githash.js +36 -0
- package/client/lib/hub.js +125 -0
- package/client/lib/llm.js +85 -0
- package/client/lib/package.js +73 -0
- package/client/lib/project.js +97 -0
- package/client/lib/prompt.js +22 -0
- package/client/lib/ref.js +37 -0
- package/client/lib/registries/github.js +106 -0
- package/client/lib/registries/index.js +37 -0
- package/client/lib/registries/rfc.js +42 -0
- package/client/lib/registries/skillssh.js +59 -0
- package/client/lib/render.js +53 -0
- package/client/lib/rules.js +36 -0
- package/client/lib/scanner.js +158 -0
- package/client/lib/state.js +50 -0
- package/client/lib/yamlls.js +14 -0
- package/client/public/app.js +63 -0
- package/client/public/index.html +21 -0
- package/package.json +44 -4
- package/pipeline/lib/env.js +40 -0
- package/pipeline/lib/gh.js +53 -0
- package/pipeline/lib/llm.js +108 -0
- package/pipeline/lib/util.js +103 -0
- package/skill/SKILL.md +270 -0
- package/skill/references/a11y.md +82 -0
- package/skill/references/code.md +415 -0
- package/skill/references/color.md +84 -0
- package/skill/references/copy.md +197 -0
- package/skill/references/imagery.md +157 -0
- package/skill/references/layout.md +404 -0
- package/skill/references/motion.md +104 -0
- package/skill/references/process.md +303 -0
- package/skill/references/type.md +84 -0
- package/skill/rules-manifest.yml +13092 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// project.js — copy 投影(hub 权威)+ drift 校验;--link 可选 symlink
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { treeHash, copyDir, rmDir, readSkillDir } from './package.js';
|
|
5
|
+
import { primaryDir } from './scanner.js';
|
|
6
|
+
|
|
7
|
+
// 投影单个 skill 到目标目录 → {target, hash, action}
|
|
8
|
+
export function projectSkill(srcDir, name, targetDir, { mode = 'copy', dryRun = false, force = false, lockEntry = null } = {}) {
|
|
9
|
+
const dest = path.join(targetDir, name);
|
|
10
|
+
const srcHash = treeHash(srcDir);
|
|
11
|
+
|
|
12
|
+
if (fs.existsSync(dest)) {
|
|
13
|
+
const destHash = treeHash(dest);
|
|
14
|
+
if (destHash === srcHash) return { target: dest, hash: srcHash, action: 'skipped', mode };
|
|
15
|
+
// 漂移:lock 记的是旧版 → 正常更新;lock 记的与现场不符 → 手动改过的 unmanaged 内容
|
|
16
|
+
const managedDrift = lockEntry && lockEntry.hash === destHash;
|
|
17
|
+
if (!managedDrift && !force) {
|
|
18
|
+
return { target: dest, hash: srcHash, action: 'conflict', mode, detail: 'unmanaged content differs — --force to overwrite' };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (dryRun) return { target: dest, hash: srcHash, action: fs.existsSync(dest) ? 'would-update' : 'would-create', mode };
|
|
23
|
+
rmDir(dest);
|
|
24
|
+
if (mode === 'link') {
|
|
25
|
+
try {
|
|
26
|
+
fs.symlinkSync(srcDir, dest, 'dir');
|
|
27
|
+
return { target: dest, hash: srcHash, action: 'linked', mode };
|
|
28
|
+
} catch { /* 降级 copy */ }
|
|
29
|
+
}
|
|
30
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
31
|
+
copyDir(srcDir, dest);
|
|
32
|
+
return { target: dest, hash: srcHash, action: 'copied', mode: 'copy' };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function unproject(name, targetDir, { dryRun = false } = {}) {
|
|
36
|
+
const dest = path.join(targetDir, name);
|
|
37
|
+
if (!fs.existsSync(dest)) return { target: dest, action: 'absent' };
|
|
38
|
+
if (!dryRun) rmDir(dest);
|
|
39
|
+
return { target: dest, action: dryRun ? 'would-remove' : 'removed' };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// lock vs 实测漂移(doctor/sync --dry-run 共用)
|
|
43
|
+
export function checkDrift(ctx) {
|
|
44
|
+
const drift = [];
|
|
45
|
+
for (const [name, entry] of Object.entries(ctx.lock.skills || {})) {
|
|
46
|
+
for (const [target, t] of Object.entries(entry.targets || {})) {
|
|
47
|
+
const dir = targetDirFor(ctx, target, name);
|
|
48
|
+
if (!dir) continue;
|
|
49
|
+
const skillDir = path.join(dir, name);
|
|
50
|
+
if (!fs.existsSync(skillDir)) { drift.push({ name, target, issue: 'missing' }); continue; }
|
|
51
|
+
if (treeHash(skillDir) !== t.hash) drift.push({ name, target, issue: 'content-differs' });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return drift;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// target 标识 → 物理目录(harness id 或 custom:<abs> 或 project:<abs>)
|
|
58
|
+
export function targetDirFor(ctx, target, _name) {
|
|
59
|
+
if (target.startsWith('custom:')) return target.slice(7);
|
|
60
|
+
if (target.startsWith('project:')) return target.slice(8);
|
|
61
|
+
const h = ctx.harnesses.find((x) => x.id === target);
|
|
62
|
+
return h ? primaryDir(h) : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 解析目标集:--to/--target/--scope/default_targets
|
|
66
|
+
export function resolveTargets(ctx, { allowAdopted = null } = {}) {
|
|
67
|
+
const f = ctx.flags.raw;
|
|
68
|
+
if (f.to && f.target) throw new Error('--to 与 --target 互斥');
|
|
69
|
+
if (f.to) return [{ id: `custom:${path.resolve(expandTilde(f.to))}`, dir: path.resolve(expandTilde(f.to)), mode: f.link ? 'link' : 'copy' }];
|
|
70
|
+
if (f.scope === 'project' || f.scope === 'repo') {
|
|
71
|
+
if (!ctx.project) throw new Error('--scope project 需在仓库目录内运行');
|
|
72
|
+
const out = [];
|
|
73
|
+
for (const h of ctx.harnesses) {
|
|
74
|
+
if (h.detectOnly) continue;
|
|
75
|
+
for (const pd of h.projectDirs || []) {
|
|
76
|
+
const dir = path.join(ctx.project.root, pd);
|
|
77
|
+
out.push({ id: `project:${dir}`, dir, mode: 'copy' });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return dedup(out);
|
|
81
|
+
}
|
|
82
|
+
const ids = f.target ? String(f.target).split(',') : (ctx.config.default_targets.length ? ctx.config.default_targets : allowAdopted);
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const id of ids || []) {
|
|
85
|
+
if (id.startsWith('custom:')) { out.push({ id, dir: id.slice(7), mode: 'copy' }); continue; }
|
|
86
|
+
const custom = ctx.config.targets[id];
|
|
87
|
+
if (custom) { out.push({ id: `custom:${path.resolve(expandTilde(custom.path))}`, dir: path.resolve(expandTilde(custom.path)), mode: custom.transport === 'link' ? 'link' : 'copy' }); continue; }
|
|
88
|
+
const h = ctx.harnesses.find((x) => x.id === id);
|
|
89
|
+
if (!h) { if (ids) throw new Error(`unknown target: ${id}`); continue; }
|
|
90
|
+
const dir = primaryDir(h);
|
|
91
|
+
if (dir) out.push({ id, dir, mode: 'copy' });
|
|
92
|
+
}
|
|
93
|
+
return dedup(out);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const dedup = (arr) => [...new Map(arr.map((t) => [t.dir, t])).values()];
|
|
97
|
+
const expandTilde = (p) => (p.startsWith('~') ? path.join(process.env.HOME || '', p.slice(1)) : p);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// prompt.js — TTY 确认/选择(非 TTY 一律安全默认)
|
|
2
|
+
import readline from 'node:readline';
|
|
3
|
+
|
|
4
|
+
export async function confirm(question, { defaultYes = false } = {}) {
|
|
5
|
+
if (!process.stdin.isTTY) return defaultYes;
|
|
6
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
7
|
+
const ans = await new Promise((res) => rl.question(`${question} [${defaultYes ? 'Y/n' : 'y/N'}] `, res));
|
|
8
|
+
rl.close();
|
|
9
|
+
const a = ans.trim().toLowerCase();
|
|
10
|
+
return a === '' ? defaultYes : a === 'y' || a === 'yes';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function choose(question, options) {
|
|
14
|
+
if (!process.stdin.isTTY) return options[0];
|
|
15
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
16
|
+
process.stderr.write(`${question}\n`);
|
|
17
|
+
options.forEach((o, i) => process.stderr.write(` ${i + 1}. ${o.label || o}\n`));
|
|
18
|
+
const ans = await new Promise((res) => rl.question('> ', res));
|
|
19
|
+
rl.close();
|
|
20
|
+
const n = parseInt(ans, 10);
|
|
21
|
+
return options[n - 1] ?? options[0];
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// ref.js — install 引用语法解析(§6)
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { expandHome } from './hub.js';
|
|
5
|
+
import { harnessDirOf } from './scanner.js';
|
|
6
|
+
|
|
7
|
+
const GH_SHORT = /^([\w.-]+)\/([\w.-]+)(?:@([^\s]+))?$/;
|
|
8
|
+
const GH_URL = /^(?:https?:\/\/|git@)github\.com[:/]([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:#(\S+))?$/;
|
|
9
|
+
|
|
10
|
+
export function parseRef(input, flags = {}, { harnesses = [], registries = [] } = {}) {
|
|
11
|
+
// 1. 本地路径(存在即 local/harness)
|
|
12
|
+
const expanded = path.resolve(expandHome(input));
|
|
13
|
+
if (fs.existsSync(expanded) && fs.statSync(expanded).isDirectory()) {
|
|
14
|
+
const h = harnessDirOf(harnesses, expanded);
|
|
15
|
+
return h ? { kind: 'harness', absPath: expanded, harnessId: h.harnessId, dir: h.dir }
|
|
16
|
+
: { kind: 'local', absPath: expanded };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 2. git URL
|
|
20
|
+
const urlM = input.match(GH_URL);
|
|
21
|
+
if (urlM) return { kind: 'github', owner: urlM[1], repo: urlM[2], ref: urlM[3] || null, path: flags.path || null };
|
|
22
|
+
|
|
23
|
+
// 3. registry 前缀 corp:name
|
|
24
|
+
const colon = input.match(/^([\w-]+):([\w./@-]+)$/);
|
|
25
|
+
if (colon && registries.some((r) => (r.name || r.type) === colon[1])) {
|
|
26
|
+
return { kind: 'named', name: colon[2], registry: colon[1] };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 4. owner/repo[@ref](--path 定位子目录)
|
|
30
|
+
const ghM = input.match(GH_SHORT);
|
|
31
|
+
if (ghM && !input.startsWith('-')) {
|
|
32
|
+
return { kind: 'github', owner: ghM[1], repo: ghM[2], ref: ghM[3] || null, path: flags.path || null };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 5. 裸名——默认 skills.sh 索引(可 --from 换 registry)
|
|
36
|
+
return { kind: 'named', name: input, registry: flags.from || 'skillssh' };
|
|
37
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// github.js — owner/repo[@ref] 拉取:gh api tarball → codeload(+mirror) → jsdelivr 逐文件
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { treeHash, copyDir } from '../package.js';
|
|
7
|
+
|
|
8
|
+
const sh = (cmd, args) => execFileSync(cmd, args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();
|
|
9
|
+
|
|
10
|
+
function haveGh() {
|
|
11
|
+
try { sh('gh', ['--version']); return true; } catch { return false; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function headSha(owner, repo, ref = null) {
|
|
15
|
+
if (haveGh()) {
|
|
16
|
+
try {
|
|
17
|
+
const r = ref || 'HEAD';
|
|
18
|
+
return sh('gh', ['api', `repos/${owner}/${repo}/commits/${r}`, '--jq', '.sha']);
|
|
19
|
+
} catch { /* fallthrough */ }
|
|
20
|
+
}
|
|
21
|
+
return ref;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function fetchTarball(owner, repo, ref, { mirror = null } = {}) {
|
|
25
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'skillmkt-gh-'));
|
|
26
|
+
const tar = path.join(tmp, 'pkg.tar.gz');
|
|
27
|
+
const urls = [
|
|
28
|
+
`https://codeload.github.com/${owner}/${repo}/tar.gz/${ref}`,
|
|
29
|
+
...(mirror ? [`${mirror.replace(/\/+$/, '')}/https://codeload.github.com/${owner}/${repo}/tar.gz/${ref}`] : []),
|
|
30
|
+
];
|
|
31
|
+
if (haveGh()) {
|
|
32
|
+
try {
|
|
33
|
+
execFileSync('gh', ['api', `repos/${owner}/${repo}/tarball/${ref}`, '-H', 'Accept: application/vnd.github+json'], { stdio: ['ignore', fs.openSync(tar, 'w'), 'pipe'] });
|
|
34
|
+
if (fs.statSync(tar).size > 100) return { tmp, tar, via: 'gh' };
|
|
35
|
+
} catch { /* fallthrough to codeload */ }
|
|
36
|
+
}
|
|
37
|
+
for (const url of urls) {
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(url, { redirect: 'follow' });
|
|
40
|
+
if (!res.ok) continue;
|
|
41
|
+
fs.writeFileSync(tar, Buffer.from(await res.arrayBuffer()));
|
|
42
|
+
if (fs.statSync(tar).size > 100) return { tmp, tar, via: url.includes('codeload') && !mirror ? 'codeload' : 'mirror' };
|
|
43
|
+
} catch { /* next */ }
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// fetch → {dir: 解压后 skill 根目录(含 SKILL.md 或其子目录), provenance}
|
|
49
|
+
export async function fetchSkill({ owner, repo, ref = null, path: sub = null, mirror = null }) {
|
|
50
|
+
const sha = headSha(owner, repo, ref) || ref || 'HEAD';
|
|
51
|
+
const got = await fetchTarball(owner, repo, sha, { mirror });
|
|
52
|
+
if (!got) throw new Error(`fetch failed: ${owner}/${repo}@${sha}(直连与镜像均不可达)`);
|
|
53
|
+
execFileSync('tar', ['xzf', got.tar, '-C', got.tmp]);
|
|
54
|
+
const root = fs.readdirSync(got.tmp).find((d) => d.startsWith(`${owner.replace(/\W/g, '')}`) || d.includes('-'))
|
|
55
|
+
?? fs.readdirSync(got.tmp).find((d) => fs.statSync(path.join(got.tmp, d)).isDirectory());
|
|
56
|
+
let dir = path.join(got.tmp, root);
|
|
57
|
+
if (sub) {
|
|
58
|
+
// slug 与仓库路径不总一致(skills.sh slug 常省略 skills/ 前缀)——多级回退定位
|
|
59
|
+
const topDirs = fs.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
60
|
+
const cands = [sub, `skills/${sub}`, ...topDirs.map((d) => `${d}/${sub}`)];
|
|
61
|
+
const hit = cands.find((c) => fs.existsSync(path.join(dir, c, 'SKILL.md')))
|
|
62
|
+
?? cands.find((c) => fs.existsSync(path.join(dir, c)));
|
|
63
|
+
if (!hit) throw new Error(`repo 内找不到: ${sub}(试了 ${cands.slice(0, 4).join(', ')} …)`);
|
|
64
|
+
dir = path.join(dir, hit);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
dir, tmp: got.tmp, sha,
|
|
68
|
+
provenance: { registry: 'github', ref: `${owner}/${repo}`, path: sub, pin: sha, via: got.via },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 远端 git/trees → subtree 的 git-tree-hash(update/outdated 免下载对比)
|
|
73
|
+
import { remoteTreeHash } from '../githash.js';
|
|
74
|
+
export async function remoteTree(owner, repo, ref, sub = null) {
|
|
75
|
+
if (!haveGh()) throw new Error('gh CLI required for remote tree');
|
|
76
|
+
const sha = headSha(owner, repo, ref);
|
|
77
|
+
const tree = JSON.parse(sh('gh', ['api', `repos/${owner}/${repo}/git/trees/${sha}?recursive=1`])).tree;
|
|
78
|
+
return { sha, tree_hash: remoteTreeHash(tree, sub) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function versionsSkill() { return []; } // TODO: tags/releases
|
|
82
|
+
|
|
83
|
+
// jsdelivr 逐文件兜底(data.jsdelivr.com 列目录)——mirror 全挂时的最后手段
|
|
84
|
+
export async function fetchViaJsdelivr(owner, repo, ref, sub, destDir) {
|
|
85
|
+
const api = `https://data.jsdelivr.com/v1/packages/gh/${owner}/${repo}@${ref}`;
|
|
86
|
+
const tree = await (await fetch(api)).json();
|
|
87
|
+
const files = [];
|
|
88
|
+
const walkJs = (node, prefix) => {
|
|
89
|
+
for (const f of node.files || []) {
|
|
90
|
+
const p = prefix ? `${prefix}/${f.name}` : f.name;
|
|
91
|
+
if (f.type === 'directory') walkJs(f, p);
|
|
92
|
+
else files.push(p);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
walkJs(tree, '');
|
|
96
|
+
const base = `https://fastly.jsdelivr.net/gh/${owner}/${repo}@${ref}/`;
|
|
97
|
+
for (const f of files) {
|
|
98
|
+
if (sub && !f.startsWith(`${sub}/`) && f !== sub) continue;
|
|
99
|
+
const rel = sub ? f.slice(sub.length + 1) : f;
|
|
100
|
+
const res = await fetch(base + f);
|
|
101
|
+
if (!res.ok) continue;
|
|
102
|
+
const dest = path.join(destDir, rel);
|
|
103
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
104
|
+
fs.writeFileSync(dest, Buffer.from(await res.arrayBuffer()));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// registries/index.js — 按 ref/type 路由适配器 + fetch mirror 前缀
|
|
2
|
+
import * as github from './github.js';
|
|
3
|
+
import * as skillssh from './skillssh.js';
|
|
4
|
+
import * as rfc from './rfc.js';
|
|
5
|
+
|
|
6
|
+
export const ADAPTERS = { github, skillssh, rfc, clawhub: null };
|
|
7
|
+
|
|
8
|
+
export function adapterFor(type) {
|
|
9
|
+
const a = ADAPTERS[type];
|
|
10
|
+
if (!a) throw new Error(`registry adapter 未实现: ${type}(二期)`);
|
|
11
|
+
return a;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function fetchMirror(ctx) {
|
|
15
|
+
return ctx.config._raw?.fetch_mirror || process.env.SKILLMKT_FETCH_MIRROR || null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 统一拉取入口:named → skillssh 解析为 github 坐标
|
|
19
|
+
export async function fetchRef(ref, ctx) {
|
|
20
|
+
const mirror = fetchMirror(ctx);
|
|
21
|
+
if (ref.kind === 'github') {
|
|
22
|
+
return github.fetchSkill({ ...ref, mirror });
|
|
23
|
+
}
|
|
24
|
+
if (ref.kind === 'named' && (!ref.registry || ref.registry === 'skillssh' || ref.registry === 'github')) {
|
|
25
|
+
const coord = await skillssh.resolveNamed(ref.name, ctx);
|
|
26
|
+
if (!coord) throw new Error(`skills.sh 索引未收录: ${ref.name}——可试 skillmkt install owner/repo 直指`);
|
|
27
|
+
return github.fetchSkill({ ...coord, ref: null, mirror });
|
|
28
|
+
}
|
|
29
|
+
if (ref.registry) {
|
|
30
|
+
const reg = ctx.config.registries.find((r) => (r.name || r.type) === ref.registry);
|
|
31
|
+
if (!reg) throw new Error(`未配置 registry: ${ref.registry}`);
|
|
32
|
+
const a = adapterFor(reg.type);
|
|
33
|
+
if (!a.fetchSkill) throw new Error(`registry ${reg.type} 不支持 fetch`);
|
|
34
|
+
return a.fetchSkill(ref, ctx, reg);
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`无法解析引用: ${JSON.stringify(ref)}`);
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// rfc.js — Cloudflare Agent Skills Discovery RFC v0.2(只读):.well-known/index.json + sha256 校验
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import crypto from 'node:crypto';
|
|
6
|
+
import { execFileSync } from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
export async function fetchIndex(reg) {
|
|
9
|
+
const url = `${reg.url.replace(/\/+$/, '')}/.well-known/agent-skills/index.json`;
|
|
10
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(8000) });
|
|
11
|
+
if (!res.ok) throw new Error(`rfc index ${res.status}: ${url}`);
|
|
12
|
+
const idx = await res.json();
|
|
13
|
+
return idx.skills || idx.entries || (Array.isArray(idx) ? idx : []);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function search(query, ctx, reg) {
|
|
17
|
+
const entries = await fetchIndex(reg);
|
|
18
|
+
const q = query.toLowerCase();
|
|
19
|
+
return entries.filter((e) => (e.name || '').toLowerCase().includes(q) || (e.description || '').toLowerCase().includes(q))
|
|
20
|
+
.map((e) => ({ name: e.name, slug: e.name, source: reg.url, installs: 0, url: e.url }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function fetchSkill(ref, ctx, reg) {
|
|
24
|
+
const entries = await fetchIndex(reg);
|
|
25
|
+
const entry = entries.find((e) => e.name === ref.name);
|
|
26
|
+
if (!entry) throw new Error(`rfc index 无此 skill: ${ref.name}`);
|
|
27
|
+
const res = await fetch(entry.url, { signal: AbortSignal.timeout(20000) });
|
|
28
|
+
if (!res.ok) throw new Error(`rfc fetch ${res.status}: ${entry.url}`);
|
|
29
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
30
|
+
if (entry.digest) {
|
|
31
|
+
const want = entry.digest.replace(/^sha256[:=]/, '');
|
|
32
|
+
const got = crypto.createHash('sha256').update(buf).digest('hex');
|
|
33
|
+
if (got !== want) throw new Error(`digest mismatch: ${ref.name}(${want.slice(0, 12)} ≠ ${got.slice(0, 12)})`);
|
|
34
|
+
}
|
|
35
|
+
// 落 tmp:tar.gz 解压或当 zip;单文件 SKILL.md 也可
|
|
36
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'skillmkt-rfc-'));
|
|
37
|
+
const tar = path.join(tmp, 'pkg');
|
|
38
|
+
fs.writeFileSync(tar, buf);
|
|
39
|
+
try { execFileSync('tar', ['xzf', tar, '-C', tmp]); } catch { /* 非 tar */ }
|
|
40
|
+
const dir = fs.readdirSync(tmp).find((d) => fs.statSync(path.join(tmp, d)).isDirectory());
|
|
41
|
+
return { dir: dir ? path.join(tmp, dir) : tmp, tmp, provenance: { registry: 'rfc', ref: reg.url, pin: entry.digest || null } };
|
|
42
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// skillssh.js — skills.sh 官方 /api/search 消费(npx skills 同款)+ 多词降级归并
|
|
2
|
+
const DEFAULT_BASE = 'https://skills.sh';
|
|
3
|
+
const MIN_EXACT = 10, MAX_TERMS = 6, MAX_MERGED = 25;
|
|
4
|
+
|
|
5
|
+
export function searchBase(ctx) {
|
|
6
|
+
return (process.env.SKILLMKT_SEARCH_API || process.env.SKILLS_API_URL
|
|
7
|
+
|| ctx.config._raw?.skills_api || DEFAULT_BASE).replace(/\/+$/, '');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function api(base, q, owner) {
|
|
11
|
+
const params = new URLSearchParams({ q });
|
|
12
|
+
if (owner) params.set('owner', owner);
|
|
13
|
+
const res = await fetch(`${base}/api/search?${params}`, { signal: AbortSignal.timeout(8000) });
|
|
14
|
+
if (!res.ok) return [];
|
|
15
|
+
const data = await res.json();
|
|
16
|
+
return (data.skills || []).map((s) => ({
|
|
17
|
+
name: s.name, slug: s.id, source: s.source || '', installs: s.installs || 0,
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 官方同款归并:精确<10 且 2-6 词 → 丢词子查询按 hits+rank+installs 归并
|
|
22
|
+
export async function searchRemote(query, ctx, { owner = null } = {}) {
|
|
23
|
+
const base = searchBase(ctx);
|
|
24
|
+
const exact = await api(base, query, owner);
|
|
25
|
+
const terms = [...new Set(query.trim().split(/\s+/).filter(Boolean))];
|
|
26
|
+
if (exact.length >= MIN_EXACT || terms.length < 2 || terms.length > MAX_TERMS) {
|
|
27
|
+
return { skills: exact, exactCount: exact.length, base };
|
|
28
|
+
}
|
|
29
|
+
const subs = terms.map((_, i) => terms.filter((__, j) => j !== i).join(' '));
|
|
30
|
+
const lists = await Promise.all(subs.map((q) => api(base, q, owner)));
|
|
31
|
+
const seen = new Set(exact.map((s) => s.slug));
|
|
32
|
+
const cand = new Map();
|
|
33
|
+
for (const list of lists) list.forEach((s, rank) => {
|
|
34
|
+
if (seen.has(s.slug)) return;
|
|
35
|
+
const e = cand.get(s.slug);
|
|
36
|
+
if (e) { e.hits++; e.bestRank = Math.min(e.bestRank, rank); }
|
|
37
|
+
else cand.set(s.slug, { skill: s, hits: 1, bestRank: rank });
|
|
38
|
+
});
|
|
39
|
+
const partial = [...cand.values()]
|
|
40
|
+
.sort((a, b) => b.hits - a.hits || a.bestRank - b.bestRank || b.skill.installs - a.skill.installs)
|
|
41
|
+
.slice(0, MAX_MERGED - exact.length).map((e) => e.skill);
|
|
42
|
+
return { skills: [...exact, ...partial], exactCount: exact.length, base };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 裸名 → skills.sh 索引定位 {owner/repo + path}(slug="owner/repo/skill-id")
|
|
46
|
+
export async function resolveNamed(name, ctx) {
|
|
47
|
+
const { skills } = await searchRemote(name, ctx);
|
|
48
|
+
const hit = skills.find((s) => s.name === name || s.slug.endsWith(`/${name}`))
|
|
49
|
+
?? skills[0];
|
|
50
|
+
if (!hit) return null;
|
|
51
|
+
const parts = hit.slug.split('/');
|
|
52
|
+
if (parts.length >= 3) {
|
|
53
|
+
return { owner: parts[0], repo: parts[1], path: parts.slice(2).join('/'), meta: hit };
|
|
54
|
+
}
|
|
55
|
+
const src = (hit.source || '').split('/');
|
|
56
|
+
return src.length >= 2
|
|
57
|
+
? { owner: src[0], repo: src[1], path: hit.slug.split('/').pop(), meta: hit }
|
|
58
|
+
: null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// render.js — 终端表格/卡片/仪表盘;装饰全走 stderr,--json 时 stdout 纯数据
|
|
2
|
+
const err = (...a) => console.error(...a);
|
|
3
|
+
|
|
4
|
+
export function table(rows, cols) {
|
|
5
|
+
const widths = cols.map((c) => Math.max(c.title.length, ...rows.map((r) => String(r[c.key] ?? '').length)));
|
|
6
|
+
const line = (cells) => ' ' + cells.map((c, i) => String(c ?? '').padEnd(widths[i])).join(' ').trimEnd();
|
|
7
|
+
err(line(cols.map((c) => c.title)));
|
|
8
|
+
for (const r of rows) err(line(cols.map((c) => r[c.key])));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function out(data, { json = false, human = null } = {}) {
|
|
12
|
+
if (json) {
|
|
13
|
+
console.log(JSON.stringify(data, null, 2));
|
|
14
|
+
} else if (human) {
|
|
15
|
+
human();
|
|
16
|
+
} else {
|
|
17
|
+
console.log(typeof data === 'string' ? data : JSON.stringify(data, null, 2));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const ok = (s) => err(`✓ ${s}`);
|
|
22
|
+
export const warn = (s) => err(`⚠ ${s}`);
|
|
23
|
+
export const fail = (s) => err(`✗ ${s}`);
|
|
24
|
+
export const info = (s) => err(` ${s}`);
|
|
25
|
+
|
|
26
|
+
// 裸跑仪表盘:只摆"需要注意力"的信息
|
|
27
|
+
export function dashboard({ hub, library, scan, upstream, conflicts, llm, project }) {
|
|
28
|
+
const skills = Object.keys(library.skills || {});
|
|
29
|
+
const updates = Object.keys(upstream?.skills || {}).filter(
|
|
30
|
+
(n) => upstream.skills[n]?.tree_hash !== (scan.managedHash?.[n] ?? null) && upstream.skills[n]
|
|
31
|
+
).length;
|
|
32
|
+
const pending = conflicts.filter((c) => c.status === 'pending').length;
|
|
33
|
+
const externals = scan.rows.filter((r) => r.state === 'external').length;
|
|
34
|
+
const audits = skills.map((n) => library.skills[n].audit);
|
|
35
|
+
const bad = audits.filter((a) => a === 'suspicious' || a === 'quarantined').length;
|
|
36
|
+
|
|
37
|
+
err(`skillmkt · hub ${hub}${llm ? ` · llm ${llm.model} ✓` : ''}`);
|
|
38
|
+
err('');
|
|
39
|
+
err(`skills ${skills.length} installed${updates ? ` · ${updates} update available` : ''} · audit ${audits.length - bad}✓${bad ? `/${bad}⚠` : ''}`);
|
|
40
|
+
const hs = scan.harnesses.filter((h) => h.state !== 'absent')
|
|
41
|
+
.map((h) => `${h.id}${h.state === 'installed' ? '●' : h.state === 'available' ? '○available' : '~likely'}`);
|
|
42
|
+
if (hs.length) err(`harnesses ${hs.join(' ')}`);
|
|
43
|
+
if (project) err(`project ${project.root}`);
|
|
44
|
+
if (pending) err(`conflicts ${pending} pending — 需要裁决`);
|
|
45
|
+
if (externals) err(`external ${externals} 未收编 — install <path> 纳入管理`);
|
|
46
|
+
err('');
|
|
47
|
+
const hints = [];
|
|
48
|
+
if (pending) hints.push('skillmkt conflicts --ui 裁决冲突(开面板看图)');
|
|
49
|
+
if (updates) hints.push('skillmkt outdated 看可更新项');
|
|
50
|
+
if (externals) hints.push('skillmkt list 查看 ◌external 路径');
|
|
51
|
+
hints.push('skillmkt list 安装矩阵', 'skillmkt --help 全部命令');
|
|
52
|
+
hints.slice(0, 4).forEach((h) => err(h));
|
|
53
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// rules.js — 任意 skill 静态抽规则候选(去固定域):节标题 slug=动态域 + severity 词表
|
|
2
|
+
// 静态兜底版;LLM 精抽(自由 domain 标签)批次 6 替换 extractRules 内部
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { ruleHash } from '../../pipeline/lib/util.js';
|
|
6
|
+
|
|
7
|
+
const SEV = [
|
|
8
|
+
[/never|must not|do not|禁止|绝不|不得|no exceptions|hard rule/i, 'floor'],
|
|
9
|
+
[/prefer|recommend|should|建议|推荐|优先/i, 'standard'],
|
|
10
|
+
[/can|may|consider|optional|可|酌情/i, 'reflex'],
|
|
11
|
+
];
|
|
12
|
+
const sevOf = (t) => SEV.find(([re]) => re.test(t))?.[1] || 'standard';
|
|
13
|
+
const slug = (s) => s.toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/gi, '-').replace(/^-|-$/g, '').slice(0, 12) || 'misc';
|
|
14
|
+
|
|
15
|
+
// SKILL.md → [{id, source, domain, severity, text, hash}]:每节按 bullet/句子切,≤220 字符
|
|
16
|
+
export function extractRules(dir, sourceName) {
|
|
17
|
+
const f = path.join(dir, 'SKILL.md');
|
|
18
|
+
if (!fs.existsSync(f)) return [];
|
|
19
|
+
const lines = fs.readFileSync(f, 'utf8').split('\n');
|
|
20
|
+
const rules = [];
|
|
21
|
+
let domain = 'misc', i = 0;
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
const h = line.match(/^#{1,3}\s+(.+)/);
|
|
24
|
+
if (h) { domain = slug(h[1]); continue; }
|
|
25
|
+
if (/^#{4,}/.test(line) || /^(```|<!--|\s*$)/.test(line)) continue;
|
|
26
|
+
const bullet = line.replace(/^\s*[-*•>\d.)\s]+/, '').trim();
|
|
27
|
+
if (bullet.length < 12 || bullet.length > 500) continue;
|
|
28
|
+
// 长段切句,每段最多取 3 条
|
|
29
|
+
for (const sent of bullet.split(/(?<=[.。!!??])\s+/).slice(0, 3)) {
|
|
30
|
+
const text = sent.trim();
|
|
31
|
+
if (text.length < 12 || text.length > 220) continue;
|
|
32
|
+
rules.push({ id: `${sourceName.slice(0, 6)}-${String(++i).padStart(3, '0')}`, source: sourceName, domain, severity: sevOf(text), text, hash: ruleHash(text) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return rules;
|
|
36
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// scanner.js — harness 探测矩阵(每次运行活探)+ skill 目录扫描 + external 发现
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { expandHome } from './hub.js';
|
|
5
|
+
import { readSkillDir } from './package.js';
|
|
6
|
+
|
|
7
|
+
// §5 探测表——新增 harness = 加一行
|
|
8
|
+
export const HARNESSES = [
|
|
9
|
+
{ id: 'claude', bins: ['claude'], envs: ['CLAUDE_CONFIG_DIR'],
|
|
10
|
+
dirs: ['~/.claude/skills'], projectDirs: ['.claude/skills'] },
|
|
11
|
+
{ id: 'codex', bins: ['codex'], envs: ['CODEX_HOME'],
|
|
12
|
+
dirs: ['~/.codex/skills', '~/.agents/skills'], projectDirs: ['.agents/skills'] },
|
|
13
|
+
{ id: 'opencode', bins: ['opencode'], envs: ['OPENCODE_CONFIG_DIR'],
|
|
14
|
+
dirs: ['~/.config/opencode/skills'], projectDirs: ['.opencode'] },
|
|
15
|
+
{ id: 'pi', bins: ['pi', 'dsh'], envs: [],
|
|
16
|
+
dirs: ['~/.pi/agent/skills'], projectDirs: ['.pi'] },
|
|
17
|
+
{ id: 'devin', bins: ['devin'], envs: ['DEVIN_CONFIG_DIR'],
|
|
18
|
+
dirs: ['~/.config/devin/skills', '~/.agents/skills'], projectDirs: ['.devin/skills'] },
|
|
19
|
+
{ id: 'gemini', bins: ['gemini'], envs: ['GEMINI_HOME'],
|
|
20
|
+
dirs: ['~/.gemini/skills'], projectDirs: ['.gemini'] },
|
|
21
|
+
{ id: 'cursor', bins: ['cursor'], envs: [],
|
|
22
|
+
dirs: ['~/.cursor/skills'], projectDirs: ['.cursor'] },
|
|
23
|
+
{ id: 'windsurf', bins: ['windsurf'], envs: [],
|
|
24
|
+
dirs: ['~/.codeium/windsurf'], projectDirs: [], detectOnly: true },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
const EXE_EXT = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
28
|
+
|
|
29
|
+
export function binInPath(bin) {
|
|
30
|
+
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
31
|
+
if (!dir) continue;
|
|
32
|
+
for (const ext of EXE_EXT) {
|
|
33
|
+
const p = path.join(dir, bin + ext);
|
|
34
|
+
try { if (fs.statSync(p).isFile()) return p; } catch { /* skip */ }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// env override:值是 harness 根目录,skill 目录 = <root>/skills
|
|
41
|
+
function envDirs(h) {
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const v of h.envs) {
|
|
44
|
+
const val = process.env[v];
|
|
45
|
+
if (val) out.push({ dir: path.join(expandHome(val), 'skills'), viaEnv: v });
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 四态:installed=bin∧dir / available=bin∧!dir / likely=dir∧!bin / absent=双无
|
|
51
|
+
export function detectHarnesses() {
|
|
52
|
+
const seen = new Map(); // 共享目录去重:abs path → owners[]
|
|
53
|
+
return HARNESSES.map((h) => {
|
|
54
|
+
const bin = h.bins.map(binInPath).find(Boolean) || null;
|
|
55
|
+
const dirs = [
|
|
56
|
+
...envDirs(h).map((d) => ({ path: expandHome(d.dir), viaEnv: d.viaEnv })),
|
|
57
|
+
...h.dirs.map((d) => ({ path: expandHome(d), viaEnv: null })),
|
|
58
|
+
].map((d) => {
|
|
59
|
+
const exists = fs.existsSync(d.path);
|
|
60
|
+
const owners = seen.get(d.path) || [];
|
|
61
|
+
owners.push(h.id);
|
|
62
|
+
seen.set(d.path, owners);
|
|
63
|
+
return { ...d, exists };
|
|
64
|
+
});
|
|
65
|
+
const anyDir = dirs.some((d) => d.exists);
|
|
66
|
+
const state = bin && anyDir ? 'installed' : bin ? 'available' : anyDir ? 'likely' : 'absent';
|
|
67
|
+
return { id: h.id, bin, state, dirs, detectOnly: !!h.detectOnly, projectDirs: h.projectDirs };
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 每 harness 的主投影目录:首个存在的,否则首个(扫描吃全部 dirs,投影只投主目录)
|
|
72
|
+
export function primaryDir(h) {
|
|
73
|
+
return (h.dirs.find((d) => d.exists) ?? h.dirs[0])?.path ?? null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 共享目录去重后的投影目标:[{harnessId, dir}]——一个物理目录一条
|
|
77
|
+
export function projectionDirs(harnesses, ids = null) {
|
|
78
|
+
const out = [];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
for (const h of harnesses) {
|
|
81
|
+
if (h.detectOnly || h.state === 'absent' || h.state === 'likely') continue;
|
|
82
|
+
if (ids && !ids.includes(h.id)) continue;
|
|
83
|
+
const dir = primaryDir(h);
|
|
84
|
+
if (dir && !seen.has(dir)) { seen.add(dir); out.push({ harnessId: h.id, dir }); }
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function scanSkillDir(dir) {
|
|
90
|
+
const skills = [];
|
|
91
|
+
if (!fs.existsSync(dir)) return skills;
|
|
92
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
93
|
+
if (!e.isDirectory()) continue;
|
|
94
|
+
const p = path.join(dir, e.name);
|
|
95
|
+
const s = readSkillDir(p);
|
|
96
|
+
if (s) skills.push(s);
|
|
97
|
+
}
|
|
98
|
+
return skills;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// 全量库存:hub skills + 每个 harness 目录 + project——managed 判定留给调用方;按物理路径去重(共享目录只报一次)
|
|
102
|
+
export function scanAll(hub, harnesses, library, projectRoot = null) {
|
|
103
|
+
const managed = new Set(Object.keys(library.skills || {}));
|
|
104
|
+
const rows = [];
|
|
105
|
+
const seen = new Set();
|
|
106
|
+
const push = (s) => { if (!seen.has(s.path)) { seen.add(s.path); rows.push(s); } };
|
|
107
|
+
const hubSkills = scanSkillDir(path.join(hub, 'skills'));
|
|
108
|
+
for (const s of hubSkills) {
|
|
109
|
+
push({ ...s, where: 'hub', state: managed.has(s.name) ? 'managed' : 'hub-untracked' });
|
|
110
|
+
}
|
|
111
|
+
for (const h of harnesses) {
|
|
112
|
+
if (h.detectOnly) continue;
|
|
113
|
+
for (const d of h.dirs) {
|
|
114
|
+
if (!d.exists) continue;
|
|
115
|
+
for (const s of scanSkillDir(d.path)) {
|
|
116
|
+
push({ ...s, where: h.id, targetDir: d.path, state: managed.has(s.name) ? 'managed' : 'external' });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (projectRoot) {
|
|
121
|
+
for (const h of harnesses) {
|
|
122
|
+
for (const pd of h.projectDirs || []) {
|
|
123
|
+
const dir = path.join(projectRoot, pd);
|
|
124
|
+
for (const s of scanSkillDir(dir)) {
|
|
125
|
+
push({ ...s, where: 'project', targetDir: dir, state: managed.has(s.name) ? 'managed' : 'external' });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return rows;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// harness 目录归属判定:absPath 是否位于某 harness skills dir 下
|
|
134
|
+
export function harnessDirOf(harnesses, absPath) {
|
|
135
|
+
const target = path.resolve(absPath);
|
|
136
|
+
for (const h of harnesses) {
|
|
137
|
+
for (const d of h.dirs) {
|
|
138
|
+
if (path.dirname(target) === path.resolve(d.path)) return { harnessId: h.id, dir: d.path };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// cwd 向上找项目根(.git 或任一 harness projectDir)
|
|
145
|
+
export function detectProject(cwd) {
|
|
146
|
+
let cur = path.resolve(cwd);
|
|
147
|
+
for (;;) {
|
|
148
|
+
if (fs.existsSync(path.join(cur, '.git'))) return { root: cur };
|
|
149
|
+
for (const h of HARNESSES) {
|
|
150
|
+
for (const pd of h.projectDirs) {
|
|
151
|
+
if (fs.existsSync(path.join(cur, pd))) return { root: cur };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const parent = path.dirname(cur);
|
|
155
|
+
if (parent === cur) return null;
|
|
156
|
+
cur = parent;
|
|
157
|
+
}
|
|
158
|
+
}
|