@uncarved/jade 0.3.1 → 0.4.1
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/README.md +1 -0
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +39 -5
- package/dist/host.js.map +1 -1
- package/dist/remote.js +5 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +7 -0
- package/dist/session.js +490 -29
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +36 -14
- package/plugins/approval/policy.ts +15 -10
- package/plugins/approval/review.ts +9 -5
- package/plugins/checks/checks.ts +10 -7
- package/plugins/checks/index.ts +13 -13
- package/plugins/checks/plugin.json +1 -1
- package/plugins/checks/project.ts +37 -38
- package/plugins/commands/index.ts +27 -3
- package/plugins/compact/compact.ts +13 -5
- package/plugins/compact/index.ts +20 -3
- package/plugins/compact/style.ts +13 -14
- package/plugins/completions/index.ts +35 -0
- package/plugins/completions/plugin.json +7 -0
- package/plugins/copy/index.ts +46 -0
- package/plugins/copy/plugin.json +7 -0
- package/plugins/editor/index.ts +10 -4
- package/plugins/fs/diff.ts +7 -6
- package/plugins/fs/fs.ts +8 -4
- package/plugins/fs/grep.ts +42 -9
- package/plugins/fs/index.ts +2 -7
- package/plugins/fs/plugin.json +1 -1
- package/plugins/fs/renderers.ts +16 -15
- package/plugins/fs/style.ts +16 -15
- package/plugins/hooks/index.ts +3 -2
- package/plugins/keys/index.ts +5 -1
- package/plugins/mcp/index.ts +197 -78
- package/plugins/mcp/install.ts +5 -3
- package/plugins/mcp/mcp.ts +163 -11
- package/plugins/mcp/plugin.json +2 -1
- package/plugins/mcp/project.ts +47 -50
- package/plugins/memory/index.ts +4 -4
- package/plugins/memory/style.ts +13 -14
- package/plugins/mentions/candidates.ts +67 -0
- package/plugins/mentions/index.ts +12 -5
- package/plugins/mentions/plugin.json +1 -1
- package/plugins/mentions/style.ts +13 -14
- package/plugins/models/configure.ts +47 -12
- package/plugins/models/index.ts +27 -1
- package/plugins/models/provider.ts +24 -0
- package/plugins/models/saved.ts +1 -1
- package/plugins/modes/index.ts +13 -2
- package/plugins/print/index.ts +7 -4
- package/plugins/prompts/index.ts +0 -0
- package/plugins/renderers/index.ts +10 -5
- package/plugins/repeats/index.ts +8 -8
- package/plugins/schedule/index.ts +5 -1
- package/plugins/screenshot/browser.ts +10 -0
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +27 -28
- package/plugins/shell/plugin.json +1 -1
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +3 -1
- package/plugins/skills/index.ts +28 -19
- package/plugins/skills/project.ts +12 -7
- package/plugins/steer/index.ts +5 -4
- package/plugins/task/index.ts +80 -50
- package/plugins/task/plugin.json +6 -2
- package/plugins/task/style.ts +13 -14
- package/plugins/task/subagent.ts +67 -184
- package/plugins/todo/index.ts +39 -9
- package/plugins/tools/index.ts +9 -2
- package/plugins/tui/frontend.ts +139 -89
- package/plugins/tui/index.ts +2 -3
- package/plugins/tui/mentions.ts +11 -80
- package/plugins/tui/plugin.json +1 -1
- package/plugins/tui/screen.ts +55 -5
- package/plugins/tui/transcript.ts +17 -7
- package/plugins/tui/tui.ts +337 -101
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +8 -4
- package/plugins/undo/index.ts +170 -31
- package/plugins/undo/plugin.json +1 -0
- package/plugins/undo/snapshot.ts +87 -14
- package/plugins/undo/style.ts +13 -14
- package/plugins/web/index.ts +7 -18
- package/plugins/web/plugin.json +1 -1
- package/plugins-dist/approval/index.js +363 -418
- package/plugins-dist/approval/policy.js +391 -508
- package/plugins-dist/approval/review.js +132 -158
- package/plugins-dist/approval/schema.js +50 -55
- package/plugins-dist/ask/index.js +115 -129
- package/plugins-dist/budget/index.js +27 -31
- package/plugins-dist/checks/checks.js +293 -329
- package/plugins-dist/checks/index.js +119 -139
- package/plugins-dist/checks/plugin.json +2 -1
- package/plugins-dist/checks/project.js +57 -65
- package/plugins-dist/commands/index.js +47 -29
- package/plugins-dist/compact/compact.js +233 -249
- package/plugins-dist/compact/index.js +98 -95
- package/plugins-dist/compact/style.js +9 -14
- package/plugins-dist/completions/index.js +30 -0
- package/plugins-dist/completions/plugin.json +9 -0
- package/plugins-dist/continue/index.js +40 -52
- package/plugins-dist/copy/index.js +40 -0
- package/plugins-dist/copy/plugin.json +9 -0
- package/plugins-dist/cost/index.js +98 -115
- package/plugins-dist/custom-commands/index.js +55 -72
- package/plugins-dist/editor/index.js +64 -72
- package/plugins-dist/fs/diff.js +111 -124
- package/plugins-dist/fs/fs.js +426 -469
- package/plugins-dist/fs/grep.js +262 -253
- package/plugins-dist/fs/index.js +20 -34
- package/plugins-dist/fs/plugin.json +1 -2
- package/plugins-dist/fs/renderers.js +100 -112
- package/plugins-dist/fs/style.js +11 -15
- package/plugins-dist/fs/sys.js +31 -43
- package/plugins-dist/hooks/index.js +107 -127
- package/plugins-dist/keys/index.js +27 -31
- package/plugins-dist/mcp/index.js +271 -199
- package/plugins-dist/mcp/install.js +123 -137
- package/plugins-dist/mcp/mcp.js +638 -577
- package/plugins-dist/mcp/plugin.json +3 -1
- package/plugins-dist/mcp/project.js +98 -115
- package/plugins-dist/memory/index.js +83 -88
- package/plugins-dist/memory/memory.js +111 -128
- package/plugins-dist/memory/style.js +9 -14
- package/plugins-dist/mentions/attach.js +91 -99
- package/plugins-dist/mentions/candidates.js +49 -0
- package/plugins-dist/mentions/index.js +71 -81
- package/plugins-dist/mentions/plugin.json +2 -1
- package/plugins-dist/mentions/style.js +9 -14
- package/plugins-dist/models/config.js +29 -43
- package/plugins-dist/models/configure.js +421 -474
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -189
- package/plugins-dist/models/provider.js +263 -307
- package/plugins-dist/models/saved.js +60 -72
- package/plugins-dist/modes/index.js +138 -165
- package/plugins-dist/plugins/index.js +34 -34
- package/plugins-dist/print/index.js +192 -175
- package/plugins-dist/prompts/index.js +86 -89
- package/plugins-dist/prompts/notes.js +31 -37
- package/plugins-dist/prompts/prompts.js +155 -193
- package/plugins-dist/prompts/results.js +40 -53
- package/plugins-dist/prompts/sys.js +39 -50
- package/plugins-dist/renderers/index.js +32 -32
- package/plugins-dist/repeats/index.js +131 -174
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +230 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +136 -154
- package/plugins-dist/screenshot/index.js +37 -46
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +98 -126
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +117 -135
- package/plugins-dist/shell/plugin.json +1 -1
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +307 -362
- package/plugins-dist/shell/sys.js +64 -79
- package/plugins-dist/skills/index.js +193 -211
- package/plugins-dist/skills/install.js +122 -149
- package/plugins-dist/skills/project.js +65 -73
- package/plugins-dist/skills/skills.js +135 -171
- package/plugins-dist/steer/index.js +108 -125
- package/plugins-dist/suggest/index.js +235 -259
- package/plugins-dist/task/index.js +130 -117
- package/plugins-dist/task/plugin.json +5 -2
- package/plugins-dist/task/style.js +9 -14
- package/plugins-dist/task/subagent.js +156 -279
- package/plugins-dist/todo/index.js +79 -63
- package/plugins-dist/tools/index.js +36 -42
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +639 -678
- package/plugins-dist/tui/history.js +34 -37
- package/plugins-dist/tui/index.js +16 -18
- package/plugins-dist/tui/markdown.js +203 -247
- package/plugins-dist/tui/mascot.js +266 -355
- package/plugins-dist/tui/mentions.js +67 -144
- package/plugins-dist/tui/plugin.json +1 -2
- package/plugins-dist/tui/render.js +35 -45
- package/plugins-dist/tui/screen.js +197 -180
- package/plugins-dist/tui/transcript.js +436 -468
- package/plugins-dist/tui/tui.js +1554 -1656
- package/plugins-dist/tui/vendor.js +1088 -1388
- package/plugins-dist/undo/checkpoint.js +97 -118
- package/plugins-dist/undo/index.js +281 -192
- package/plugins-dist/undo/plugin.json +3 -0
- package/plugins-dist/undo/snapshot.js +134 -99
- package/plugins-dist/undo/style.js +9 -14
- package/plugins-dist/update/index.js +26 -28
- package/plugins-dist/web/env.js +55 -68
- package/plugins-dist/web/index.js +80 -110
- package/plugins-dist/web/plugin.json +1 -2
- package/plugins-dist/web/renderers.js +4 -5
- package/plugins-dist/web/web.js +514 -593
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +9 -2
- package/src/api.ts +1 -1
- package/src/host.ts +39 -4
- package/src/remote.ts +6 -1
- package/src/session.ts +496 -36
|
@@ -1,178 +1,151 @@
|
|
|
1
|
-
// /skills add|update|remove:从 git 仓库、npm 包或本地目录安装 skill。
|
|
2
|
-
//
|
|
3
|
-
// 不加 --project 装到 $JADE_HOME/skills/<名字>,加了装到 <工作目录>/.jade/skills/<名字>。
|
|
4
|
-
// 来源的写法和下载经核心的 sources@1 服务(和 jade plugins add 同一份):先下到 skills 目录里的 .staging-*
|
|
5
|
-
// (以 . 开头,查找 skill 时跳过),找到 SKILL.md 后再换进正式目录。
|
|
6
|
-
// 安装记录在 skills 目录的 .installed.json(按名字),update 按它重新下载;记录里有安装时的内容哈希,
|
|
7
|
-
// 装好后手动改过的默认不覆盖,要加 --force。skill 只是文字和附带的文件:安装不执行任何东西,也不装依赖。
|
|
8
1
|
import { randomBytes } from "node:crypto";
|
|
9
2
|
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
10
3
|
import path from "node:path";
|
|
11
4
|
import { NAME, parseSkill } from "./skills.js";
|
|
12
|
-
|
|
13
|
-
export const skillsRoot = (home, cwd, project) => (project ? path.join(cwd, ".jade", "skills") : path.join(home, "skills"));
|
|
5
|
+
export const skillsRoot = (home, cwd, project) => project ? path.join(cwd, ".jade", "skills") : path.join(home, "skills");
|
|
14
6
|
const RECORDS = ".installed.json";
|
|
15
7
|
export async function readRecords(root) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
throw new Error(`${path.join(root, RECORDS)}: ${e instanceof Error ? e.message : String(e)}`);
|
|
28
|
-
}
|
|
8
|
+
let text;
|
|
9
|
+
try {
|
|
10
|
+
text = await readFile(path.join(root, RECORDS), "utf8");
|
|
11
|
+
} catch {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(text);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
throw new Error(`${path.join(root, RECORDS)}: ${e instanceof Error ? e.message : String(e)}`);
|
|
18
|
+
}
|
|
29
19
|
}
|
|
30
20
|
async function writeRecords(root, records) {
|
|
31
|
-
|
|
21
|
+
await writeFile(path.join(root, RECORDS), JSON.stringify(records, null, 2) + `
|
|
22
|
+
`);
|
|
32
23
|
}
|
|
33
24
|
const exists = (p) => stat(p).then(() => true, () => false);
|
|
34
|
-
/** 把 --path 限制在来源目录里,不能跑到外面去 */
|
|
35
25
|
function inSubdir(root, subdir) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
const full = path.resolve(root, subdir);
|
|
27
|
+
const rel = path.relative(root, full);
|
|
28
|
+
if (rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel))
|
|
29
|
+
throw new Error(`--path ${subdir} points outside the source`);
|
|
30
|
+
return full;
|
|
41
31
|
}
|
|
42
|
-
/** 服务里抛出的错误带着 "plugin jade (sources@1.fetch): " 的前缀;给用户看的只要原来那句 */
|
|
43
32
|
async function plain(call) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
33
|
+
try {
|
|
34
|
+
return await call;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw e instanceof Error && e.name === "PluginError" && e.cause instanceof Error ? e.cause : e;
|
|
37
|
+
}
|
|
50
38
|
}
|
|
51
|
-
/** 安装一个 skill,返回它的名字和目录 */
|
|
52
39
|
export async function addSkill(spec, opts) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
const source = await plain(opts.sources.parse(spec, opts.cwd));
|
|
41
|
+
const record = await install(source, opts);
|
|
42
|
+
return { name: record.name, dir: path.join(path.resolve(opts.root), record.name) };
|
|
56
43
|
}
|
|
57
|
-
/** 按安装记录重新下载;没给名字时更新这个目录里所有装过的 skill。返回每个 skill 一行结果 */
|
|
58
44
|
export async function updateSkills(names, opts) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
const dir = path.join(root, name);
|
|
70
|
-
if (!opts.force && (await exists(dir)) && (await opts.sources.hash(dir)) !== rec.hash) {
|
|
71
|
-
lines.push(`${name}: changed since it was installed; add --force to overwrite the changes`);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const source = { kind: rec.kind, location: rec.location, spec: rec.source, ...(rec.ref ? { ref: rec.ref } : {}) };
|
|
75
|
-
const next = await install(source, { ...opts, force: true, ...(rec.subdir ? { subdir: rec.subdir } : {}) }, rec);
|
|
76
|
-
lines.push(next.hash === rec.hash ? `current ${name}` : `updated ${name}`);
|
|
77
|
-
}
|
|
78
|
-
catch (e) {
|
|
79
|
-
lines.push(`${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
80
|
-
}
|
|
45
|
+
const root = path.resolve(opts.root);
|
|
46
|
+
const records = await readRecords(root);
|
|
47
|
+
const lines = [];
|
|
48
|
+
for (const name of names.length ? names : Object.keys(records).sort()) {
|
|
49
|
+
const rec = records[name];
|
|
50
|
+
if (!rec) {
|
|
51
|
+
lines.push(`${name}: not installed with "/skills add"${await exists(path.join(root, name)) ? "; update it by hand" : ""}`);
|
|
52
|
+
continue;
|
|
81
53
|
}
|
|
82
|
-
|
|
54
|
+
try {
|
|
55
|
+
const dir = path.join(root, name);
|
|
56
|
+
if (!opts.force && await exists(dir) && await opts.sources.hash(dir) !== rec.hash) {
|
|
57
|
+
lines.push(`${name}: changed since it was installed; add --force to overwrite the changes`);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const source = { kind: rec.kind, location: rec.location, spec: rec.source, ...rec.ref ? { ref: rec.ref } : {} };
|
|
61
|
+
const next = await install(source, { ...opts, force: true, ...rec.subdir ? { subdir: rec.subdir } : {} }, rec);
|
|
62
|
+
lines.push(next.hash === rec.hash ? `current ${name}` : `updated ${name}`);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
lines.push(`${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return lines;
|
|
83
68
|
}
|
|
84
|
-
/** 删掉一个 skill 目录和它的安装记录;手动放进去的也能删 */
|
|
85
69
|
export async function removeSkill(name, root) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
if (!NAME.test(name))
|
|
71
|
+
throw new Error(`invalid skill name ${JSON.stringify(name)}`);
|
|
72
|
+
root = path.resolve(root);
|
|
73
|
+
const dir = path.join(root, name);
|
|
74
|
+
if (!await exists(path.join(dir, "SKILL.md")))
|
|
75
|
+
throw new Error(`there is no skill ${name} in ${root}`);
|
|
76
|
+
await rm(dir, { recursive: true, force: true });
|
|
77
|
+
const records = await readRecords(root);
|
|
78
|
+
if (records[name]) {
|
|
79
|
+
delete records[name];
|
|
80
|
+
await writeRecords(root, records);
|
|
81
|
+
}
|
|
82
|
+
return dir;
|
|
99
83
|
}
|
|
100
|
-
/** 下载、找到 SKILL.md、换进正式目录、写安装记录。更新时 prev 给出原来的记录(名字不变) */
|
|
101
84
|
async function install(source, opts, prev) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
throw new Error(`${source.location} contains the skills directory; give the skill's own directory, or use --path`);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
await mkdir(root, { recursive: true });
|
|
112
|
-
const records = await readRecords(root);
|
|
113
|
-
const staging = path.join(root, `.staging-${randomBytes(4).toString("hex")}`);
|
|
114
|
-
try {
|
|
115
|
-
const { root: fetched, commit } = await plain(opts.sources.fetch(source, staging, opts.log));
|
|
116
|
-
const dir = opts.subdir ? inSubdir(fetched, opts.subdir) : fetched;
|
|
117
|
-
if (!(await exists(path.join(dir, "SKILL.md"))))
|
|
118
|
-
throw new Error(await noSkillMessage(source.spec, dir, fetched));
|
|
119
|
-
const name = prev?.name ?? skillName(parseSkill(await readFile(path.join(dir, "SKILL.md"), "utf8")).meta.name, source, opts.subdir);
|
|
120
|
-
const target = path.join(root, name);
|
|
121
|
-
if (!opts.force && (await exists(target))) {
|
|
122
|
-
throw new Error(`skill ${name} is already installed in ${target}; run "/skills update ${name}", or add --force to replace it`);
|
|
123
|
-
}
|
|
124
|
-
const hash = await opts.sources.hash(dir);
|
|
125
|
-
await rm(target, { recursive: true, force: true });
|
|
126
|
-
await rename(dir, target);
|
|
127
|
-
const now = new Date().toISOString();
|
|
128
|
-
const record = {
|
|
129
|
-
name,
|
|
130
|
-
source: source.spec,
|
|
131
|
-
location: source.location,
|
|
132
|
-
kind: source.kind,
|
|
133
|
-
...(source.ref ? { ref: source.ref } : {}),
|
|
134
|
-
...(opts.subdir ? { subdir: opts.subdir } : {}),
|
|
135
|
-
...(commit ? { commit } : {}),
|
|
136
|
-
hash,
|
|
137
|
-
installedAt: prev?.installedAt ?? now,
|
|
138
|
-
...(prev ? { updatedAt: now } : {}),
|
|
139
|
-
};
|
|
140
|
-
records[name] = record;
|
|
141
|
-
await writeRecords(root, records);
|
|
142
|
-
return record;
|
|
85
|
+
const root = path.resolve(opts.root);
|
|
86
|
+
if (source.kind === "local") {
|
|
87
|
+
const from = opts.subdir ? inSubdir(source.location, opts.subdir) : source.location;
|
|
88
|
+
const rel = path.relative(from, root);
|
|
89
|
+
if (rel === "" || rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel)) {
|
|
90
|
+
throw new Error(`${source.location} contains the skills directory; give the skill's own directory, or use --path`);
|
|
143
91
|
}
|
|
144
|
-
|
|
145
|
-
|
|
92
|
+
}
|
|
93
|
+
await mkdir(root, { recursive: true });
|
|
94
|
+
const records = await readRecords(root);
|
|
95
|
+
const staging = path.join(root, `.staging-${randomBytes(4).toString("hex")}`);
|
|
96
|
+
try {
|
|
97
|
+
const { root: fetched, commit } = await plain(opts.sources.fetch(source, staging, opts.log));
|
|
98
|
+
const dir = opts.subdir ? inSubdir(fetched, opts.subdir) : fetched;
|
|
99
|
+
if (!await exists(path.join(dir, "SKILL.md")))
|
|
100
|
+
throw new Error(await noSkillMessage(source.spec, dir, fetched));
|
|
101
|
+
const name = prev?.name ?? skillName(parseSkill(await readFile(path.join(dir, "SKILL.md"), "utf8")).meta.name, source, opts.subdir);
|
|
102
|
+
const target = path.join(root, name);
|
|
103
|
+
if (!opts.force && await exists(target)) {
|
|
104
|
+
throw new Error(`skill ${name} is already installed in ${target}; run "/skills update ${name}", or add --force to replace it`);
|
|
146
105
|
}
|
|
106
|
+
const hash = await opts.sources.hash(dir);
|
|
107
|
+
await rm(target, { recursive: true, force: true });
|
|
108
|
+
await rename(dir, target);
|
|
109
|
+
const now = new Date().toISOString();
|
|
110
|
+
const record = {
|
|
111
|
+
name,
|
|
112
|
+
source: source.spec,
|
|
113
|
+
location: source.location,
|
|
114
|
+
kind: source.kind,
|
|
115
|
+
...source.ref ? { ref: source.ref } : {},
|
|
116
|
+
...opts.subdir ? { subdir: opts.subdir } : {},
|
|
117
|
+
...commit ? { commit } : {},
|
|
118
|
+
hash,
|
|
119
|
+
installedAt: prev?.installedAt ?? now,
|
|
120
|
+
...prev ? { updatedAt: now } : {}
|
|
121
|
+
};
|
|
122
|
+
records[name] = record;
|
|
123
|
+
await writeRecords(root, records);
|
|
124
|
+
return record;
|
|
125
|
+
} finally {
|
|
126
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
127
|
+
}
|
|
147
128
|
}
|
|
148
|
-
/** SKILL.md 里的 name;没有时用 --path 的最后一段,再没有就用仓库名、包名或目录名 */
|
|
149
129
|
function skillName(declared, source, subdir) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
throw new Error(`could not tell the skill's name; give it a "name:" in SKILL.md`);
|
|
157
|
-
return name;
|
|
130
|
+
const fromSource = source.kind === "npm" ? source.location.replace(/^@[^/]+\//, "").replace(/@.*$/, "").replace(/\.(tgz|tar\.gz)$/i, "") : source.location.replace(/[\\/]+$/, "").replace(/\.git$/, "");
|
|
131
|
+
const candidates = [declared, subdir && path.basename(subdir.replace(/[\\/]+$/, "")), path.basename(fromSource)];
|
|
132
|
+
const name = candidates.find((c) => c && NAME.test(c));
|
|
133
|
+
if (!name)
|
|
134
|
+
throw new Error(`could not tell the skill's name; give it a "name:" in SKILL.md`);
|
|
135
|
+
return name;
|
|
158
136
|
}
|
|
159
|
-
/** 来源里没有 SKILL.md 时:列出它里面的 skill,提示用 --path 选一个 */
|
|
160
137
|
async function noSkillMessage(spec, dir, fetched) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (found.length === 0)
|
|
175
|
-
return `${head}; it is not a skill`;
|
|
176
|
-
const shown = found.slice(0, 20).map((d) => ` ${d}`).join("\n") + (found.length > 20 ? `\n … ${found.length - 20} more` : "");
|
|
177
|
-
return `${head}. It contains these skills; pick one with --path <dir>:\n${shown}`;
|
|
138
|
+
let found = [];
|
|
139
|
+
try {
|
|
140
|
+
found = (await readdir(fetched, { recursive: true, withFileTypes: true })).filter((e) => e.isFile() && e.name === "SKILL.md").map((e) => path.relative(fetched, e.parentPath).split(path.sep).join("/")).filter((d) => d && !d.split("/").some((seg) => seg === "node_modules" || seg.startsWith("."))).sort();
|
|
141
|
+
} catch {}
|
|
142
|
+
const where = path.relative(fetched, dir).split(path.sep).join("/");
|
|
143
|
+
const head = `${spec}${where ? ` (--path ${where})` : ""} has no SKILL.md`;
|
|
144
|
+
if (found.length === 0)
|
|
145
|
+
return `${head}; it is not a skill`;
|
|
146
|
+
const shown = found.slice(0, 20).map((d) => ` ${d}`).join(`
|
|
147
|
+
`) + (found.length > 20 ? `
|
|
148
|
+
… ${found.length - 20} more` : "");
|
|
149
|
+
return `${head}. It contains these skills; pick one with --path <dir>:
|
|
150
|
+
${shown}`;
|
|
178
151
|
}
|
|
@@ -1,89 +1,81 @@
|
|
|
1
|
-
// 仓库目录、显示用的小工具、斜杠命令参数的切分、token 估算。插件之间不共享代码(只能共享类型),jade/mcp、jade/checks 各有一份。
|
|
2
1
|
import { existsSync, realpathSync } from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
export function realPath(p) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
4
|
+
try {
|
|
5
|
+
return realpathSync.native(p);
|
|
6
|
+
} catch {
|
|
7
|
+
return path.resolve(p);
|
|
8
|
+
}
|
|
11
9
|
}
|
|
12
|
-
/** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
|
|
13
10
|
export function repoRoot(cwd) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
let d = path.resolve(cwd);
|
|
12
|
+
for (;; ) {
|
|
13
|
+
if (existsSync(path.join(d, ".git")))
|
|
14
|
+
return d;
|
|
15
|
+
const parent = path.dirname(d);
|
|
16
|
+
if (parent === d)
|
|
17
|
+
return path.resolve(cwd);
|
|
18
|
+
d = parent;
|
|
19
|
+
}
|
|
23
20
|
}
|
|
24
|
-
/** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
|
|
25
21
|
export function projectDirs(root, cwd) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
22
|
+
const rel = path.relative(root, cwd);
|
|
23
|
+
const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
|
|
24
|
+
if (!inside)
|
|
25
|
+
return [cwd];
|
|
26
|
+
const dirs = [root];
|
|
27
|
+
if (rel)
|
|
28
|
+
for (const seg of rel.split(path.sep))
|
|
29
|
+
dirs.push(path.join(dirs.at(-1), seg));
|
|
30
|
+
return dirs;
|
|
35
31
|
}
|
|
36
|
-
/** 工作目录里的显示成相对路径,外面的显示绝对路径 */
|
|
37
32
|
export function display(cwd, full) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const rel = path.relative(cwd, full);
|
|
34
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
35
|
+
return shown.split(path.sep).join("/");
|
|
41
36
|
}
|
|
42
|
-
export const clip = (s, n) =>
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
export const
|
|
47
|
-
export const
|
|
48
|
-
export const
|
|
49
|
-
|
|
37
|
+
export const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
|
|
38
|
+
const styled = (style) => (text) => ({ text, style });
|
|
39
|
+
export const dim = styled("dim");
|
|
40
|
+
export const bold = styled("bold");
|
|
41
|
+
export const ok = styled("ok");
|
|
42
|
+
export const warn = styled("warn");
|
|
43
|
+
export const error = styled("error");
|
|
44
|
+
export const lines = (rows) => rows.flatMap((r, i) => i ? [`
|
|
45
|
+
`, r] : [r]);
|
|
46
|
+
export const plain = (t) => typeof t === "string" ? t : Array.isArray(t) ? t.map(plain).join("") : t.text;
|
|
50
47
|
export function splitArgs(text) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
else if (/\s/.test(ch)) {
|
|
67
|
-
if (started)
|
|
68
|
-
out.push(cur);
|
|
69
|
-
cur = "";
|
|
70
|
-
started = false;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
cur += ch;
|
|
74
|
-
started = true;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (quote)
|
|
78
|
-
throw new Error(`unclosed ${quote}`);
|
|
79
|
-
if (started)
|
|
48
|
+
const out = [];
|
|
49
|
+
let cur = "";
|
|
50
|
+
let started = false;
|
|
51
|
+
let quote;
|
|
52
|
+
for (const ch of text) {
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (ch === quote)
|
|
55
|
+
quote = undefined;
|
|
56
|
+
else
|
|
57
|
+
cur += ch;
|
|
58
|
+
} else if (ch === '"' || ch === "'") {
|
|
59
|
+
quote = ch;
|
|
60
|
+
started = true;
|
|
61
|
+
} else if (/\s/.test(ch)) {
|
|
62
|
+
if (started)
|
|
80
63
|
out.push(cur);
|
|
81
|
-
|
|
64
|
+
cur = "";
|
|
65
|
+
started = false;
|
|
66
|
+
} else {
|
|
67
|
+
cur += ch;
|
|
68
|
+
started = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (quote)
|
|
72
|
+
throw new Error(`unclosed ${quote}`);
|
|
73
|
+
if (started)
|
|
74
|
+
out.push(cur);
|
|
75
|
+
return out;
|
|
82
76
|
}
|
|
83
|
-
/** 中日韩文字和全角符号:大约一个字一个 token(和 jade/compact 的估算一致) */
|
|
84
77
|
const WIDE = /[ -鿿가-豈--]/g;
|
|
85
|
-
/** 粗略估算一段文字发给模型时占多少 token:英文和代码约 4 个字符 1 个,中日韩文字每字约 1 个 */
|
|
86
78
|
export function estimateTokens(text) {
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
const wide = text.match(WIDE)?.length ?? 0;
|
|
80
|
+
return Math.ceil((text.length - wide) / 4 + wide);
|
|
89
81
|
}
|