@uncarved/jade 0.3.0 → 0.4.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/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 +482 -27
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +49 -24
- package/plugins/approval/policy.ts +48 -25
- 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 +55 -12
- 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 +10 -9
- package/plugins/models/index.ts +31 -4
- package/plugins/models/provider.ts +12 -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 +39 -9
- package/plugins/schedule/index.ts +2 -0
- package/plugins/screenshot/browser.ts +231 -0
- package/plugins/screenshot/index.ts +3 -2
- package/plugins/screenshot/tool.ts +27 -51
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +75 -22
- package/plugins/shell/plugin.json +1 -2
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +93 -34
- 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 +81 -81
- package/plugins/task/plugin.json +5 -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 +57 -0
- package/plugins/tools/plugin.json +7 -0
- package/plugins/tui/frontend.ts +161 -87
- package/plugins/tui/index.ts +2 -3
- package/plugins/tui/mascot.ts +8 -7
- 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 +356 -104
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +5 -3
- package/plugins/undo/index.ts +43 -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 -414
- package/plugins-dist/approval/policy.js +395 -497
- 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 -244
- 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 +392 -473
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -188
- package/plugins-dist/models/provider.js +243 -295
- package/plugins-dist/models/saved.js +59 -71
- 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 +81 -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 +134 -151
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +229 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +169 -0
- package/plugins-dist/screenshot/index.js +37 -45
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +101 -151
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +117 -74
- package/plugins-dist/shell/plugin.json +1 -2
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +317 -320
- 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 -148
- package/plugins-dist/task/plugin.json +5 -4
- 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 +43 -0
- package/plugins-dist/tools/plugin.json +9 -0
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +641 -655
- 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 -353
- 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 -1645
- package/plugins-dist/tui/vendor.js +1388 -1088
- package/plugins-dist/undo/checkpoint.js +95 -118
- package/plugins-dist/undo/index.js +185 -192
- package/plugins-dist/undo/snapshot.js +83 -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 +489 -34
|
@@ -1,92 +1,77 @@
|
|
|
1
|
-
// 跨运行时的进程和可执行文件查找:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
|
|
2
1
|
import { spawn as nodeSpawn, spawnSync as nodeSpawnSync } from "node:child_process";
|
|
3
2
|
import { accessSync, constants, statSync } from "node:fs";
|
|
4
3
|
import path from "node:path";
|
|
5
|
-
const EMPTY = { async
|
|
6
|
-
/**
|
|
7
|
-
* 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
|
|
8
|
-
* 调用方用 try/catch 判断"没装",和 Bun.spawn 同步抛错的用法一致
|
|
9
|
-
*/
|
|
4
|
+
const EMPTY = { async* [Symbol.asyncIterator]() {} };
|
|
10
5
|
export function spawn(cmd, opts = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
kill: () => void child.kill(),
|
|
32
|
-
});
|
|
33
|
-
});
|
|
6
|
+
const child = nodeSpawn(cmd[0], cmd.slice(1), {
|
|
7
|
+
cwd: opts.cwd,
|
|
8
|
+
stdio: ["ignore", opts.stdout ?? "pipe", opts.stderr ?? "pipe"],
|
|
9
|
+
detached: opts.detached ?? false,
|
|
10
|
+
env: opts.env,
|
|
11
|
+
windowsHide: true
|
|
12
|
+
});
|
|
13
|
+
const exited = new Promise((resolve) => child.once("exit", (code) => resolve(code)));
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
child.once("error", reject);
|
|
16
|
+
child.once("spawn", () => {
|
|
17
|
+
child.off("error", reject);
|
|
18
|
+
child.on("error", () => {});
|
|
19
|
+
resolve({
|
|
20
|
+
pid: child.pid,
|
|
21
|
+
stdout: child.stdout ?? EMPTY,
|
|
22
|
+
stderr: child.stderr ?? EMPTY,
|
|
23
|
+
exited,
|
|
24
|
+
kill: () => void child.kill()
|
|
25
|
+
});
|
|
34
26
|
});
|
|
27
|
+
});
|
|
35
28
|
}
|
|
36
|
-
/** 同步运行,忽略输出和错误;用于退出前的清理 */
|
|
37
29
|
export function runSync(cmd, opts = {}) {
|
|
38
|
-
|
|
30
|
+
nodeSpawnSync(cmd[0], cmd.slice(1), { stdio: "ignore", windowsHide: true, env: opts.env });
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const MISS_TTL_MS = 30_000;
|
|
43
|
-
/**
|
|
44
|
-
* 在 PATH 里找可执行文件,找不到返回 undefined。Windows 上按 PATHEXT 补扩展名;带路径分隔符时只检查那个文件。
|
|
45
|
-
* 结果会记住:编辑后检查每批修改都要找 ruff、go,每次同步扫一遍 PATH 要几毫秒,期间事件循环停住
|
|
46
|
-
*/
|
|
32
|
+
const found = new Map;
|
|
33
|
+
const MISS_TTL_MS = 30000;
|
|
47
34
|
export function which(bin) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
if (bin.includes("/") || process.platform === "win32" && bin.includes("\\"))
|
|
36
|
+
return lookup(bin);
|
|
37
|
+
const key = `${bin}\x00${process.env.PATH ?? process.env.Path ?? ""}\x00${process.env.PATHEXT ?? ""}`;
|
|
38
|
+
const hit = found.get(key);
|
|
39
|
+
if (hit && (hit.file !== undefined || Date.now() - hit.at < MISS_TTL_MS))
|
|
40
|
+
return hit.file;
|
|
41
|
+
const file = lookup(bin);
|
|
42
|
+
found.set(key, { file, at: Date.now() });
|
|
43
|
+
return file;
|
|
57
44
|
}
|
|
58
45
|
function lookup(bin) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (ok(base + ext))
|
|
79
|
-
return base + ext;
|
|
80
|
-
}
|
|
81
|
-
return undefined;
|
|
82
|
-
};
|
|
83
|
-
if (bin.includes("/") || (win && bin.includes("\\")))
|
|
84
|
-
return tryAll(path.resolve(bin));
|
|
85
|
-
const dirs = (process.env.PATH ?? process.env.Path ?? "").split(path.delimiter).filter(Boolean);
|
|
86
|
-
for (const dir of dirs) {
|
|
87
|
-
const found = tryAll(path.join(dir.replace(/^"(.*)"$/, "$1"), bin));
|
|
88
|
-
if (found)
|
|
89
|
-
return found;
|
|
46
|
+
const win = process.platform === "win32";
|
|
47
|
+
const exts = win ? ["", ...(process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)] : [""];
|
|
48
|
+
const ok = (file) => {
|
|
49
|
+
try {
|
|
50
|
+
if (!statSync(file).isFile())
|
|
51
|
+
return false;
|
|
52
|
+
if (!win)
|
|
53
|
+
accessSync(file, constants.X_OK);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const tryAll = (base) => {
|
|
60
|
+
for (const ext of exts) {
|
|
61
|
+
if (win && ext === "" && !path.extname(base))
|
|
62
|
+
continue;
|
|
63
|
+
if (ok(base + ext))
|
|
64
|
+
return base + ext;
|
|
90
65
|
}
|
|
91
|
-
return
|
|
66
|
+
return;
|
|
67
|
+
};
|
|
68
|
+
if (bin.includes("/") || win && bin.includes("\\"))
|
|
69
|
+
return tryAll(path.resolve(bin));
|
|
70
|
+
const dirs = (process.env.PATH ?? process.env.Path ?? "").split(path.delimiter).filter(Boolean);
|
|
71
|
+
for (const dir of dirs) {
|
|
72
|
+
const found = tryAll(path.join(dir.replace(/^"(.*)"$/, "$1"), bin));
|
|
73
|
+
if (found)
|
|
74
|
+
return found;
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
92
77
|
}
|
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
// jade/skills:skill 工具、系统提示词里的 skill 列表、/skills(列出,以及 add / update / remove,见 install.ts;
|
|
2
|
-
// 终端里是 jade skills …),以及每个 skill 一条 /<skill 名> 命令。
|
|
3
|
-
//
|
|
4
|
-
// 每次调用模型之前重新查找 skill:会话中途装的马上能用,不用 /clear 或重启。随仓库分发的 skill(项目层)不用确认:
|
|
5
|
-
// 它只是给模型看的文字,不执行代码;和旧 jade 一样,列表里有项目层的 skill 时整段标为不可信。
|
|
6
1
|
import path from "node:path";
|
|
7
2
|
import { definePlugin } from "@uncarved/jade-api";
|
|
8
3
|
import { addSkill, removeSkill, skillsRoot, updateSkills } from "./install.js";
|
|
9
|
-
import { bold, clip, dim, display, estimateTokens,
|
|
4
|
+
import { bold, clip, dim, display, error, estimateTokens, lines as joinLines, plain, realPath, repoRoot, splitArgs } from "./project.js";
|
|
10
5
|
import { loadSkills, skillLine, skillsPrompt, skillTool } from "./skills.js";
|
|
11
6
|
const ID = "jade/skills";
|
|
12
|
-
/** /<skill> 发给模型的消息:让它先加载这个 skill */
|
|
13
7
|
export function skillMessage(name, args) {
|
|
14
|
-
|
|
8
|
+
return `Use the "${name}" skill${args.trim() ? ` for this: ${args.trim()}` : "."}`;
|
|
15
9
|
}
|
|
16
|
-
const errorText = (e) =>
|
|
17
|
-
/** cmd 是 "/skills" 或 "jade skills" */
|
|
10
|
+
const errorText = (e) => e instanceof Error ? e.message : String(e);
|
|
18
11
|
export const manageUsage = (cmd) => `usage: ${cmd} [list]
|
|
19
12
|
${cmd} add <source> [--project] [--path <dir>] [--force]
|
|
20
13
|
${cmd} update [name…] [--project] [--force]
|
|
@@ -25,215 +18,204 @@ export const manageUsage = (cmd) => `usage: ${cmd} [list]
|
|
|
25
18
|
--project use <cwd>/.jade/skills instead of $JADE_HOME/skills
|
|
26
19
|
--path the skill's directory inside the source (for repositories with several skills)
|
|
27
20
|
--force replace a skill with the same name, or overwrite local changes on update`;
|
|
28
|
-
/** list / add / update / remove,参数已经切好;返回给用户看的结果,用法错误或失败时抛错。cmd 用在提示里 */
|
|
29
21
|
export async function manageSkills(argv, env) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
const total = toolTokens + estimateTokens(skillsPrompt(skills));
|
|
45
|
-
return [
|
|
46
|
-
...skills.map((sk) => `${bold(sk.name)} ${dim(`${sk.layer} · ${display(env.cwd, sk.dir)} · ≈${estimateTokens(skillLine(sk))} tokens`)}\n ${clip(sk.description.replace(/\s+/g, " "), 300)}`),
|
|
47
|
-
dim(`≈${total} tokens in every request (the skill list and the skill tool); a skill's instructions are read only when it is used`),
|
|
48
|
-
].join("\n");
|
|
22
|
+
const usage = manageUsage(env.cmd);
|
|
23
|
+
const [sub, ...tail] = argv;
|
|
24
|
+
if (sub === "-h" || sub === "--help" || tail.includes("-h") || tail.includes("--help"))
|
|
25
|
+
return usage;
|
|
26
|
+
if (sub === undefined || sub === "list") {
|
|
27
|
+
if (tail.length)
|
|
28
|
+
throw new Error(usage);
|
|
29
|
+
const skills = env.skills ?? (await find(env.home, env.cwd)).skills;
|
|
30
|
+
const tool = skillTool(() => skills, async () => {}, { user: skillsRoot(env.home, env.cwd, false), project: skillsRoot(env.home, env.cwd, true) });
|
|
31
|
+
const toolTokens = estimateTokens(JSON.stringify({ name: tool.name, description: tool.description, input_schema: tool.inputSchema }));
|
|
32
|
+
if (skills.length === 0) {
|
|
33
|
+
return dim(`(no skills) install one with ${env.cmd} add <source>, or put it in ${display(env.cwd, path.join(env.home, "skills"))}/<name>/SKILL.md or .jade/skills/<name>/SKILL.md
|
|
34
|
+
the skill tool itself takes ≈${toolTokens} tokens in every request`);
|
|
49
35
|
}
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
36
|
+
const total = toolTokens + estimateTokens(skillsPrompt(skills));
|
|
37
|
+
return joinLines([
|
|
38
|
+
...skills.map((sk) => [bold(sk.name), " ", dim(`${sk.layer} · ${display(env.cwd, sk.dir)} · ≈${estimateTokens(skillLine(sk))} tokens`), `
|
|
39
|
+
${clip(sk.description.replace(/\s+/g, " "), 300)}`]),
|
|
40
|
+
dim(`≈${total} tokens in every request (the skill list and the skill tool); a skill's instructions are read only when it is used`)
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
const positionals = [];
|
|
44
|
+
let project = false;
|
|
45
|
+
let force = false;
|
|
46
|
+
let subdir;
|
|
47
|
+
for (let i = 0;i < tail.length; i++) {
|
|
48
|
+
const a = tail[i];
|
|
49
|
+
if (a === "--project")
|
|
50
|
+
project = true;
|
|
51
|
+
else if (a === "--force" || a === "-f")
|
|
52
|
+
force = true;
|
|
53
|
+
else if (a === "--path") {
|
|
54
|
+
subdir = tail[++i];
|
|
55
|
+
if (subdir === undefined)
|
|
56
|
+
throw new Error(`--path needs a value
|
|
57
|
+
${usage}`);
|
|
58
|
+
} else if (a.startsWith("--path="))
|
|
59
|
+
subdir = a.slice("--path=".length);
|
|
60
|
+
else if (a.startsWith("-"))
|
|
61
|
+
throw new Error(`unknown option ${a}
|
|
62
|
+
${usage}`);
|
|
63
|
+
else
|
|
64
|
+
positionals.push(a);
|
|
65
|
+
}
|
|
66
|
+
const root = skillsRoot(env.home, env.cwd, project);
|
|
67
|
+
const later = "a running jade can use it from its next step";
|
|
68
|
+
switch (sub) {
|
|
69
|
+
case "add":
|
|
70
|
+
case "install": {
|
|
71
|
+
if (positionals.length !== 1)
|
|
72
|
+
throw new Error(usage);
|
|
73
|
+
const { name, dir } = await addSkill(positionals[0], { sources: env.sources, root, cwd: env.cwd, force, ...subdir ? { subdir } : {}, ...env.log ? { log: env.log } : {} });
|
|
74
|
+
return `installed skill ${name} into ${display(env.cwd, dir)}; ${later}`;
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
lines.push("a running jade uses the updated skills from its next step");
|
|
90
|
-
return lines.join("\n");
|
|
91
|
-
}
|
|
92
|
-
case "remove":
|
|
93
|
-
case "rm": {
|
|
94
|
-
if (positionals.length !== 1 || subdir || force)
|
|
95
|
-
throw new Error(usage);
|
|
96
|
-
const dir = await removeSkill(positionals[0], root);
|
|
97
|
-
return `removed skill ${positionals[0]} (${display(env.cwd, dir)})`;
|
|
98
|
-
}
|
|
99
|
-
default:
|
|
100
|
-
throw new Error(usage);
|
|
76
|
+
case "update": {
|
|
77
|
+
if (subdir)
|
|
78
|
+
throw new Error(usage);
|
|
79
|
+
const lines = await updateSkills(positionals, { sources: env.sources, root, cwd: env.cwd, force, ...env.log ? { log: env.log } : {} });
|
|
80
|
+
if (lines.length === 0)
|
|
81
|
+
return `no skills in ${display(env.cwd, root)} were installed with "${env.cmd} add"`;
|
|
82
|
+
if (lines.some((l) => l.startsWith("updated ")))
|
|
83
|
+
lines.push("a running jade uses the updated skills from its next step");
|
|
84
|
+
return lines.join(`
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
case "remove":
|
|
88
|
+
case "rm": {
|
|
89
|
+
if (positionals.length !== 1 || subdir || force)
|
|
90
|
+
throw new Error(usage);
|
|
91
|
+
const dir = await removeSkill(positionals[0], root);
|
|
92
|
+
return `removed skill ${positionals[0]} (${display(env.cwd, dir)})`;
|
|
101
93
|
}
|
|
94
|
+
default:
|
|
95
|
+
throw new Error(usage);
|
|
96
|
+
}
|
|
102
97
|
}
|
|
103
98
|
async function find(home, cwd) {
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
const here = realPath(cwd);
|
|
100
|
+
return loadSkills({ home, root: realPath(repoRoot(here)), cwd: here });
|
|
106
101
|
}
|
|
107
|
-
/** 最近一个会话找到的 skill,/skills 显示它 */
|
|
108
102
|
let latest;
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
/** 已经告诉过用户的警告:每个会话都会重新查找,同样的警告不重复说 */
|
|
112
|
-
const warned = new Set();
|
|
103
|
+
const skillCommands = new Map;
|
|
104
|
+
const warned = new Set;
|
|
113
105
|
export default definePlugin({
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
106
|
+
process(ctx) {
|
|
107
|
+
const sources = ctx.require("sources@1");
|
|
108
|
+
latest = undefined;
|
|
109
|
+
skillCommands.clear();
|
|
110
|
+
ctx.service("commands@1")?.register({
|
|
111
|
+
name: "skills",
|
|
112
|
+
args: "[add <source> | update [name…] | remove <name>] [--project]",
|
|
113
|
+
description: "skills the agent can use; install them from git, npm or a directory",
|
|
114
|
+
instant: true,
|
|
115
|
+
async run(args, cctx) {
|
|
116
|
+
let argv;
|
|
117
|
+
try {
|
|
118
|
+
argv = splitArgs(args);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
return error(errorText(e));
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
return await manageSkills(argv, { home: ctx.home, cwd: ctx.cwd, cmd: "/skills", sources, log: (t) => cctx.print(dim(t)), ...latest ? { skills: latest } : {} });
|
|
124
|
+
} catch (e) {
|
|
125
|
+
return error(errorText(e));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
ctx.service("cli@1")?.register({
|
|
130
|
+
name: "skills",
|
|
131
|
+
run: async (argv, cli) => plain(await manageSkills(argv, { home: ctx.home, cwd: ctx.cwd, cmd: "jade skills", sources, log: cli.log }))
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
async session(ctx) {
|
|
135
|
+
const ui = ctx.service("ui@1");
|
|
136
|
+
const approval = ctx.service("approval@1");
|
|
137
|
+
const prompts = ctx.service("prompts@1");
|
|
138
|
+
const commands = ctx.service("commands@1");
|
|
139
|
+
let current = [];
|
|
140
|
+
let shown = "";
|
|
141
|
+
let removeSection;
|
|
142
|
+
const readable = new Map;
|
|
143
|
+
const mine = new Set;
|
|
144
|
+
const child = ctx.session.parent !== undefined;
|
|
145
|
+
const applyPrompt = (skills) => {
|
|
146
|
+
const key = JSON.stringify(skills.map((s) => [s.name, s.description, s.dir, s.layer]));
|
|
147
|
+
if (key === shown)
|
|
148
|
+
return false;
|
|
149
|
+
shown = key;
|
|
150
|
+
removeSection?.();
|
|
151
|
+
removeSection = skills.length ? prompts?.add({ text: skillsPrompt(skills), untrusted: !skills.every((s) => s.layer === "user") }) : undefined;
|
|
152
|
+
const dirs = new Set(skills.map((s) => s.dir));
|
|
153
|
+
for (const [dir, revoke] of readable)
|
|
154
|
+
if (!dirs.has(dir))
|
|
155
|
+
revoke(), readable.delete(dir);
|
|
156
|
+
for (const dir of dirs)
|
|
157
|
+
if (!readable.has(dir) && approval)
|
|
158
|
+
readable.set(dir, approval.allowRead(dir));
|
|
159
|
+
return true;
|
|
160
|
+
};
|
|
161
|
+
const apply = (skills, warnings) => {
|
|
162
|
+
for (const w of warnings) {
|
|
163
|
+
if (warned.has(w))
|
|
164
|
+
continue;
|
|
165
|
+
warned.add(w);
|
|
166
|
+
ui?.notify(`${ID}: ${w}`, "warning");
|
|
167
|
+
}
|
|
168
|
+
current = skills;
|
|
169
|
+
if (child)
|
|
170
|
+
return applyPrompt(skills);
|
|
171
|
+
latest = skills;
|
|
172
|
+
if (!applyPrompt(skills))
|
|
173
|
+
return;
|
|
174
|
+
if (!commands)
|
|
175
|
+
return;
|
|
176
|
+
const names = new Set(skills.map((s) => s.name.toLowerCase()));
|
|
177
|
+
for (const [key, revoke] of skillCommands) {
|
|
178
|
+
if (names.has(key))
|
|
179
|
+
continue;
|
|
180
|
+
revoke();
|
|
181
|
+
skillCommands.delete(key);
|
|
182
|
+
mine.delete(key);
|
|
183
|
+
}
|
|
184
|
+
for (const sk of skills) {
|
|
185
|
+
const key = sk.name.toLowerCase();
|
|
186
|
+
if (mine.has(key))
|
|
187
|
+
continue;
|
|
188
|
+
const taken = commands.get(sk.name);
|
|
189
|
+
if (taken && taken.plugin !== ID)
|
|
190
|
+
continue;
|
|
191
|
+
if (taken)
|
|
192
|
+
skillCommands.get(key)?.();
|
|
193
|
+
try {
|
|
194
|
+
const revoke = commands.register({
|
|
195
|
+
name: sk.name,
|
|
196
|
+
args: "[task]",
|
|
197
|
+
description: `${clip(sk.description.replace(/\s+/g, " "), 80)} (skill)`,
|
|
198
|
+
run: (args) => ({ prompt: skillMessage(sk.name, args) })
|
|
199
|
+
});
|
|
200
|
+
skillCommands.set(key, revoke);
|
|
201
|
+
mine.add(key);
|
|
202
|
+
} catch {}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const refresh = async () => {
|
|
206
|
+
const { skills, warnings } = await find(ctx.home, ctx.cwd);
|
|
207
|
+
apply(skills, warnings);
|
|
208
|
+
};
|
|
209
|
+
await refresh();
|
|
210
|
+
ctx.kernel.tool(skillTool(() => current, refresh, { user: skillsRoot(ctx.home, ctx.cwd, false), project: skillsRoot(ctx.home, ctx.cwd, true) }));
|
|
211
|
+
ctx.kernel.hook({
|
|
212
|
+
kind: "transform",
|
|
213
|
+
point: "context.project",
|
|
214
|
+
optional: true,
|
|
215
|
+
fn: async (messages) => {
|
|
223
216
|
await refresh();
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
ctx.kernel.hook({
|
|
229
|
-
kind: "transform",
|
|
230
|
-
point: "context.project",
|
|
231
|
-
// 查找出错时沿用上一次的列表,不让这一轮失败
|
|
232
|
-
optional: true,
|
|
233
|
-
fn: async (messages) => {
|
|
234
|
-
await refresh();
|
|
235
|
-
return messages;
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
},
|
|
217
|
+
return messages;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
239
221
|
});
|