@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,192 +1,156 @@
|
|
|
1
|
-
// Skills:打包好的做事方法。一个目录就是一个 skill,入口是 SKILL.md(和 Claude Code、Agent Skills 的格式相同):
|
|
2
|
-
// ---
|
|
3
|
-
// name: pdf
|
|
4
|
-
// description: 读取、合并、拆分 PDF。处理 PDF 文件时使用
|
|
5
|
-
// ---
|
|
6
|
-
// 正文:具体步骤,可以引用同目录里的脚本、模板、参考资料
|
|
7
|
-
//
|
|
8
|
-
// 系统提示词里只列出每个 skill 的名字和描述;模型判断任务用得上时调用 skill 工具,才读入正文(渐进加载,省上下文)。
|
|
9
|
-
// 用户也可以用 /<skill 名> 直接要求使用某个 skill。
|
|
10
|
-
//
|
|
11
|
-
// 查找位置(同名时后面的覆盖前面的):
|
|
12
|
-
// ~/.claude/skills、$JADE_HOME/skills(用户层);
|
|
13
|
-
// 仓库根目录到工作目录每一级的 .claude/skills、.jade/skills(项目层)。
|
|
14
|
-
// 从旧 jade 的 src/skills.ts 移植;旧 jade 的"插件自带 skills 目录"(PluginBundle)没有移植:新的插件宿主没有内容包的概念。
|
|
15
1
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
16
2
|
import os from "node:os";
|
|
17
3
|
import path from "node:path";
|
|
18
4
|
import { projectDirs } from "./project.js";
|
|
19
5
|
export const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
20
|
-
/** 系统提示词里每个描述的上限 */
|
|
21
6
|
const MAX_DESCRIPTION = 400;
|
|
22
|
-
/** skill 工具列出的目录内文件数上限 */
|
|
23
7
|
const MAX_FILES = 60;
|
|
24
8
|
export async function loadSkills(opts) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
9
|
+
const dirs = [
|
|
10
|
+
{ dir: path.join(opts.userHome ?? os.homedir(), ".claude", "skills"), layer: "user" },
|
|
11
|
+
{ dir: path.join(opts.home, "skills"), layer: "user" }
|
|
12
|
+
];
|
|
13
|
+
for (const d of projectDirs(opts.root, opts.cwd)) {
|
|
14
|
+
dirs.push({ dir: path.join(d, ".claude", "skills"), layer: "project" }, { dir: path.join(d, ".jade", "skills"), layer: "project" });
|
|
15
|
+
}
|
|
16
|
+
const out = new Map;
|
|
17
|
+
const warnings = [];
|
|
18
|
+
const seen = new Set;
|
|
19
|
+
for (const { dir, layer } of dirs) {
|
|
20
|
+
if (seen.has(path.resolve(dir)))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(path.resolve(dir));
|
|
23
|
+
let names;
|
|
24
|
+
try {
|
|
25
|
+
names = (await readdir(dir)).filter((n) => !n.startsWith(".")).sort();
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
31
28
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
const firstLine = body.split("\n").find((l) => l.trim())?.replace(/^#+\s*/, "").trim() ?? "";
|
|
65
|
-
const description = (meta.description || firstLine).trim();
|
|
66
|
-
if (!description) {
|
|
67
|
-
warnings.push(`skill ${skillDir} is skipped: SKILL.md has no description`);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
const prev = out.get(name.toLowerCase());
|
|
71
|
-
out.set(name.toLowerCase(), {
|
|
72
|
-
name,
|
|
73
|
-
description: description.length > MAX_DESCRIPTION ? `${description.slice(0, MAX_DESCRIPTION)}…` : description,
|
|
74
|
-
dir: skillDir,
|
|
75
|
-
layer,
|
|
76
|
-
overrides: prev?.dir,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
29
|
+
for (const n of names) {
|
|
30
|
+
const skillDir = path.join(dir, n);
|
|
31
|
+
let text;
|
|
32
|
+
try {
|
|
33
|
+
if (!(await stat(skillDir)).isDirectory())
|
|
34
|
+
continue;
|
|
35
|
+
text = await readFile(path.join(skillDir, "SKILL.md"), "utf8");
|
|
36
|
+
} catch {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const { meta, body } = parseSkill(text);
|
|
40
|
+
const name = meta.name && NAME.test(meta.name) ? meta.name : n;
|
|
41
|
+
if (!NAME.test(name)) {
|
|
42
|
+
warnings.push(`skill ${skillDir} is skipped: the name may only contain letters, digits, - and _`);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const firstLine = body.split(`
|
|
46
|
+
`).find((l) => l.trim())?.replace(/^#+\s*/, "").trim() ?? "";
|
|
47
|
+
const description = (meta.description || firstLine).trim();
|
|
48
|
+
if (!description) {
|
|
49
|
+
warnings.push(`skill ${skillDir} is skipped: SKILL.md has no description`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const prev = out.get(name.toLowerCase());
|
|
53
|
+
out.set(name.toLowerCase(), {
|
|
54
|
+
name,
|
|
55
|
+
description: description.length > MAX_DESCRIPTION ? `${description.slice(0, MAX_DESCRIPTION)}…` : description,
|
|
56
|
+
dir: skillDir,
|
|
57
|
+
layer,
|
|
58
|
+
overrides: prev?.dir
|
|
59
|
+
});
|
|
79
60
|
}
|
|
80
|
-
|
|
61
|
+
}
|
|
62
|
+
return { skills: [...out.values()].sort((a, b) => a.name.localeCompare(b.name)), warnings };
|
|
81
63
|
}
|
|
82
|
-
/** front matter 里的简单键值(支持引号和 YAML 的 > | 多行写法),以及正文 */
|
|
83
64
|
export function parseSkill(text) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
body = body.slice(fm[0].length);
|
|
65
|
+
let body = text.replace(/^/, "");
|
|
66
|
+
const meta = {};
|
|
67
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(body);
|
|
68
|
+
if (fm) {
|
|
69
|
+
const lines = fm[1].split(/\r?\n/);
|
|
70
|
+
for (let i = 0;i < lines.length; i++) {
|
|
71
|
+
const m = /^([A-Za-z][\w-]*)\s*:\s*(.*?)\s*$/.exec(lines[i]);
|
|
72
|
+
if (!m)
|
|
73
|
+
continue;
|
|
74
|
+
let value = m[2];
|
|
75
|
+
if (/^[>|][+-]?$/.test(value)) {
|
|
76
|
+
const parts = [];
|
|
77
|
+
while (i + 1 < lines.length && (/^\s+\S/.test(lines[i + 1]) || lines[i + 1].trim() === ""))
|
|
78
|
+
parts.push(lines[++i].trim());
|
|
79
|
+
value = parts.join(value.startsWith(">") ? " " : `
|
|
80
|
+
`).trim();
|
|
81
|
+
}
|
|
82
|
+
meta[m[1].toLowerCase()] = value.replace(/^(["'])(.*)\1$/, "$2");
|
|
104
83
|
}
|
|
105
|
-
|
|
84
|
+
body = body.slice(fm[0].length);
|
|
85
|
+
}
|
|
86
|
+
return { meta, body: body.trim() };
|
|
106
87
|
}
|
|
107
|
-
/** 系统提示词的 skill 列表里这个 skill 的一行(/skills 按它估算占用) */
|
|
108
88
|
export const skillLine = (s) => `- ${s.name}: ${s.description.replace(/\s+/g, " ")}`;
|
|
109
|
-
/** 系统提示词里的 skill 列表;没有 skill 时为 undefined */
|
|
110
89
|
export function skillsPrompt(skills) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
].join("\n");
|
|
90
|
+
if (skills.length === 0)
|
|
91
|
+
return;
|
|
92
|
+
return [
|
|
93
|
+
"# Skills",
|
|
94
|
+
"Skills are packaged instructions for specific kinds of tasks, installed by the user or shipped with the repository. " + "When a task matches a skill's description, call the skill tool with its name before starting, then follow the instructions it returns. " + "Files a skill refers to are relative to its directory, which the skill tool tells you.",
|
|
95
|
+
"",
|
|
96
|
+
...skills.map(skillLine)
|
|
97
|
+
].join(`
|
|
98
|
+
`);
|
|
121
99
|
}
|
|
122
|
-
/**
|
|
123
|
-
* skill 工具:读入某个 skill 的正文,以及它目录里的文件。
|
|
124
|
-
* 会话里的工具列表在会话创建时就定了,所以不管有没有 skill 都注册它,名字也不写成 enum:
|
|
125
|
-
* 会话中途装的 skill 用 current() 取最新的列表,找不到时先 refresh() 重新查找一次。
|
|
126
|
-
* 说明里告诉模型怎么装 skill(装到 install 给的目录),否则它会照别的工具的习惯放进 .claude/skills
|
|
127
|
-
*/
|
|
128
100
|
export function skillTool(current, refresh, install) {
|
|
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
|
-
};
|
|
101
|
+
const lookup = (name) => current().find((s) => s.name.toLowerCase() === name.toLowerCase());
|
|
102
|
+
return {
|
|
103
|
+
name: "skill",
|
|
104
|
+
description: `Load the instructions of a skill listed in the system prompt under "# Skills". Call it when a task matches the skill's description, then follow the instructions. ` + "To install a new skill, run `jade skills add <source>` in the shell (<source>: a git repository such as user/repo or a URL, an npm package, or a local directory; " + "add `--path <dir>` for one skill inside a repository with several). It installs into " + `${install.user}; add \`--project\` to install into ${install.project} for this project only. ` + "Do not copy skills into .claude/skills. A newly installed skill can be used right away.",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: { name: { type: "string", description: "the skill's name" } },
|
|
108
|
+
required: ["name"],
|
|
109
|
+
additionalProperties: false
|
|
110
|
+
},
|
|
111
|
+
effect: "read",
|
|
112
|
+
concurrency: "safe",
|
|
113
|
+
idempotent: true,
|
|
114
|
+
async execute(input) {
|
|
115
|
+
const name = String(input.name ?? "");
|
|
116
|
+
let skill = lookup(name);
|
|
117
|
+
if (!skill) {
|
|
118
|
+
await refresh();
|
|
119
|
+
skill = lookup(name);
|
|
120
|
+
}
|
|
121
|
+
if (!skill) {
|
|
122
|
+
const names = current().map((s) => s.name);
|
|
123
|
+
return { content: `There is no skill named ${JSON.stringify(name)}. ${names.length ? `Available: ${names.join(", ")}.` : "No skills are installed."}`, isError: true };
|
|
124
|
+
}
|
|
125
|
+
let text;
|
|
126
|
+
try {
|
|
127
|
+
text = await readFile(path.join(skill.dir, "SKILL.md"), "utf8");
|
|
128
|
+
} catch (err) {
|
|
129
|
+
return { content: `Could not read the skill: ${err instanceof Error ? err.message : String(err)}`, isError: true };
|
|
130
|
+
}
|
|
131
|
+
const files = (await listFiles(skill.dir)).filter((f) => f !== "SKILL.md");
|
|
132
|
+
const shown = files.slice(0, MAX_FILES);
|
|
133
|
+
return {
|
|
134
|
+
content: [
|
|
135
|
+
`Skill "${skill.name}" (${skill.layer === "project" ? "shipped with the repository" : "installed by the user"}).`,
|
|
136
|
+
`Its directory is ${skill.dir}; paths in the instructions are relative to it.`,
|
|
137
|
+
files.length ? `Files in the skill:
|
|
138
|
+
${shown.map((f) => ` ${f}`).join(`
|
|
139
|
+
`)}${files.length > shown.length ? `
|
|
140
|
+
… ${files.length - shown.length} more` : ""}` : "",
|
|
141
|
+
"",
|
|
142
|
+
parseSkill(text).body
|
|
143
|
+
].filter((l, i) => l !== "" || i === 3).join(`
|
|
144
|
+
`)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
179
148
|
}
|
|
180
149
|
async function listFiles(dir) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
.sort();
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
150
|
+
try {
|
|
151
|
+
const entries = await readdir(dir, { recursive: true, withFileTypes: true });
|
|
152
|
+
return entries.filter((e) => e.isFile()).map((e) => path.relative(dir, path.join(e.parentPath, e.name)).split(path.sep).join("/")).filter((f) => !f.split("/").some((seg) => seg.startsWith(".") || seg === "node_modules" || seg === "__pycache__")).sort();
|
|
153
|
+
} catch {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
192
156
|
}
|
|
@@ -1,135 +1,118 @@
|
|
|
1
|
-
// jade/steer:在一轮的中途对模型说话。内核只在空闲时接受用户消息(一轮没完时不能再发一条),
|
|
2
|
-
// 所以不走输入:前端经 steer@1 把话交过来,下一次请求模型时在 context.project 里附在最后一条消息
|
|
3
|
-
// (这时是刚执行完的工具的结果)后面,并写进日志(derived),之后的投影、恢复的会话里它都在同一个位置。
|
|
4
|
-
// 和 prompts@1 的 note 是同一个办法,区别是这里是用户自己说的话,所以项目层插件不能用。
|
|
5
|
-
//
|
|
6
|
-
// 这一轮没有再请求模型就结束了的(模型正在写最后一条回复时说的),话还留在这里:前端在一轮结束后用 take 取回,
|
|
7
|
-
// 当作普通消息发出去。
|
|
8
1
|
import { definePlugin } from "@uncarved/jade-api";
|
|
9
2
|
const ID = "jade/steer";
|
|
10
|
-
/** derived 里:消息的下标 → 附在它后面的话 */
|
|
11
3
|
const KEY = `${ID}/said`;
|
|
12
|
-
/** 附在用户的话前面,告诉模型这是中途说的 */
|
|
13
4
|
export const MARKER = "[The user sent the following while you were working. Take it into account from here on.]";
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const watchers = new Set();
|
|
5
|
+
const sessions = new Map;
|
|
6
|
+
const watchers = new Set;
|
|
17
7
|
function changed() {
|
|
18
|
-
|
|
8
|
+
for (const fn of [...watchers]) {
|
|
9
|
+
try {
|
|
10
|
+
fn();
|
|
11
|
+
} catch {}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const bold = (text) => ({ text, style: "bold" });
|
|
15
|
+
const dim = (text) => ({ text, style: "dim" });
|
|
16
|
+
export default definePlugin({
|
|
17
|
+
process(ctx) {
|
|
18
|
+
ctx.provide("steer@1", (caller) => {
|
|
19
|
+
const user = (method) => {
|
|
20
|
+
if (caller.layer === "project")
|
|
21
|
+
throw new Error(`steer.${method}: project plugins cannot speak for the user`);
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
push(session, text) {
|
|
25
|
+
user("push");
|
|
26
|
+
if (typeof text !== "string" || !text.trim())
|
|
27
|
+
throw new Error("steer.push: text must be a non-empty string");
|
|
28
|
+
const s = sessions.get(session);
|
|
29
|
+
if (!s?.running())
|
|
30
|
+
return false;
|
|
31
|
+
s.pending.push(text);
|
|
32
|
+
changed();
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
pending: (session) => [...sessions.get(session)?.pending ?? []],
|
|
36
|
+
take(session) {
|
|
37
|
+
user("take");
|
|
38
|
+
const taken = sessions.get(session)?.pending.splice(0) ?? [];
|
|
39
|
+
if (taken.length > 0)
|
|
40
|
+
changed();
|
|
41
|
+
return taken;
|
|
42
|
+
},
|
|
43
|
+
subscribe(fn) {
|
|
44
|
+
if (typeof fn !== "function")
|
|
45
|
+
throw new Error("steer.subscribe: fn must be a function");
|
|
46
|
+
watchers.add(fn);
|
|
47
|
+
const off = () => void watchers.delete(fn);
|
|
48
|
+
caller.onDispose(off);
|
|
49
|
+
return off;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
ctx.service("renderers@1")?.event({
|
|
54
|
+
event: "said",
|
|
55
|
+
render(data) {
|
|
56
|
+
const text = data?.text;
|
|
57
|
+
if (typeof text !== "string")
|
|
58
|
+
return;
|
|
59
|
+
return { line: [`
|
|
60
|
+
`, bold(`› ${text.replace(/\n/g, `
|
|
61
|
+
`)}`), " ", dim("(sent while working)")] };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
async session(ctx) {
|
|
66
|
+
const id = ctx.session.id;
|
|
67
|
+
const entry = {
|
|
68
|
+
pending: [],
|
|
69
|
+
running() {
|
|
19
70
|
try {
|
|
20
|
-
|
|
71
|
+
const phase = ctx.session.state().phase;
|
|
72
|
+
return phase !== "new" && phase !== "idle" && phase !== "ended";
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
21
75
|
}
|
|
22
|
-
|
|
23
|
-
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
sessions.set(id, entry);
|
|
79
|
+
await ctx.effect(() => () => {
|
|
80
|
+
if (sessions.get(id) === entry)
|
|
81
|
+
sessions.delete(id);
|
|
82
|
+
if (entry.pending.length > 0)
|
|
83
|
+
changed();
|
|
84
|
+
});
|
|
85
|
+
ctx.kernel.hook({
|
|
86
|
+
kind: "transform",
|
|
87
|
+
point: "context.project",
|
|
88
|
+
order: -39,
|
|
89
|
+
fn: async (messages, hook) => {
|
|
90
|
+
let said = hook.derived[KEY] ?? {};
|
|
91
|
+
if (entry.pending.length > 0 && messages.at(-1)?.role === "user") {
|
|
92
|
+
const texts = entry.pending.splice(0);
|
|
93
|
+
const at = String(messages.length - 1);
|
|
94
|
+
said = { ...said, [at]: [...said[at] ?? [], ...texts] };
|
|
95
|
+
try {
|
|
96
|
+
await hook.record(KEY, said);
|
|
97
|
+
for (const text of texts)
|
|
98
|
+
await hook.emit("said", { text });
|
|
99
|
+
} catch (e) {
|
|
100
|
+
entry.pending.unshift(...texts);
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
changed();
|
|
24
104
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
throw new Error(`steer.${method}: project plugins cannot speak for the user`);
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
push(session, text) {
|
|
38
|
-
user("push");
|
|
39
|
-
if (typeof text !== "string" || !text.trim())
|
|
40
|
-
throw new Error("steer.push: text must be a non-empty string");
|
|
41
|
-
const s = sessions.get(session);
|
|
42
|
-
if (!s?.running())
|
|
43
|
-
return false;
|
|
44
|
-
s.pending.push(text);
|
|
45
|
-
changed();
|
|
46
|
-
return true;
|
|
47
|
-
},
|
|
48
|
-
pending: (session) => [...(sessions.get(session)?.pending ?? [])],
|
|
49
|
-
take(session) {
|
|
50
|
-
user("take");
|
|
51
|
-
const taken = sessions.get(session)?.pending.splice(0) ?? [];
|
|
52
|
-
if (taken.length > 0)
|
|
53
|
-
changed();
|
|
54
|
-
return taken;
|
|
55
|
-
},
|
|
56
|
-
subscribe(fn) {
|
|
57
|
-
if (typeof fn !== "function")
|
|
58
|
-
throw new Error("steer.subscribe: fn must be a function");
|
|
59
|
-
watchers.add(fn);
|
|
60
|
-
const off = () => void watchers.delete(fn);
|
|
61
|
-
caller.onDispose(off);
|
|
62
|
-
return off;
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
// 交给模型的那一刻在对话里显示出来,和用户发的消息一个样子;恢复的会话重新显示时也在原来的位置
|
|
67
|
-
ctx.service("renderers@1")?.event({
|
|
68
|
-
event: "said",
|
|
69
|
-
render(data) {
|
|
70
|
-
const text = data?.text;
|
|
71
|
-
if (typeof text !== "string")
|
|
72
|
-
return undefined;
|
|
73
|
-
return { line: `\n${bold(`› ${text.replace(/\n/g, "\n ")}`)} ${dim("(sent while working)")}` };
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
},
|
|
77
|
-
async session(ctx) {
|
|
78
|
-
const id = ctx.session.id;
|
|
79
|
-
const entry = {
|
|
80
|
-
pending: [],
|
|
81
|
-
running() {
|
|
82
|
-
try {
|
|
83
|
-
const phase = ctx.session.state().phase;
|
|
84
|
-
return phase !== "new" && phase !== "idle" && phase !== "ended";
|
|
85
|
-
}
|
|
86
|
-
catch {
|
|
87
|
-
// 会话还没建好,或者已经关了
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
sessions.set(id, entry);
|
|
93
|
-
await ctx.effect(() => () => {
|
|
94
|
-
if (sessions.get(id) === entry)
|
|
95
|
-
sessions.delete(id);
|
|
96
|
-
if (entry.pending.length > 0)
|
|
97
|
-
changed();
|
|
98
|
-
});
|
|
99
|
-
ctx.kernel.hook({
|
|
100
|
-
kind: "transform",
|
|
101
|
-
point: "context.project",
|
|
102
|
-
// 排在压缩之类改动消息列表的 hook 前面:下标按日志里的消息算
|
|
103
|
-
order: -39,
|
|
104
|
-
fn: async (messages, hook) => {
|
|
105
|
-
let said = hook.derived[KEY] ?? {};
|
|
106
|
-
if (entry.pending.length > 0 && messages.at(-1)?.role === "user") {
|
|
107
|
-
const texts = entry.pending.splice(0);
|
|
108
|
-
const at = String(messages.length - 1);
|
|
109
|
-
said = { ...said, [at]: [...(said[at] ?? []), ...texts] };
|
|
110
|
-
try {
|
|
111
|
-
// 先落盘再用(I-5);事件给前端显示
|
|
112
|
-
await hook.record(KEY, said);
|
|
113
|
-
for (const text of texts)
|
|
114
|
-
await hook.emit("said", { text });
|
|
115
|
-
}
|
|
116
|
-
catch (e) {
|
|
117
|
-
entry.pending.unshift(...texts);
|
|
118
|
-
throw e;
|
|
119
|
-
}
|
|
120
|
-
changed();
|
|
121
|
-
}
|
|
122
|
-
return messages.map((m, i) => {
|
|
123
|
-
const texts = said[i];
|
|
124
|
-
if (!texts?.length || m.role !== "user")
|
|
125
|
-
return m;
|
|
126
|
-
const blocks = [
|
|
127
|
-
{ kind: "text", text: MARKER, origin: { by: "plugin", id: ID }, trust: "trusted" },
|
|
128
|
-
...texts.map((text) => ({ kind: "text", text, origin: { by: "user" }, trust: "trusted" })),
|
|
129
|
-
];
|
|
130
|
-
return { ...m, content: [...m.content, ...blocks] };
|
|
131
|
-
});
|
|
132
|
-
},
|
|
105
|
+
return messages.map((m, i) => {
|
|
106
|
+
const texts = said[i];
|
|
107
|
+
if (!texts?.length || m.role !== "user")
|
|
108
|
+
return m;
|
|
109
|
+
const blocks = [
|
|
110
|
+
{ kind: "text", text: MARKER, origin: { by: "plugin", id: ID }, trust: "trusted" },
|
|
111
|
+
...texts.map((text) => ({ kind: "text", text, origin: { by: "user" }, trust: "trusted" }))
|
|
112
|
+
];
|
|
113
|
+
return { ...m, content: [...m.content, ...blocks] };
|
|
133
114
|
});
|
|
134
|
-
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
135
118
|
});
|