@uncarved/jade 0.2.1 → 0.3.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 +64 -2
- package/assets/logo.svg +1 -0
- package/bin/jade.js +4 -0
- package/dist/api.d.ts +5 -250
- package/dist/api.js +5 -7
- package/dist/api.js.map +1 -1
- package/dist/fetch.d.ts +8 -0
- package/dist/fetch.js +19 -17
- package/dist/fetch.js.map +1 -1
- package/dist/host.d.ts +12 -1
- package/dist/host.js +49 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +26 -4
- package/dist/main.js.map +1 -1
- package/dist/remote.js +4 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/dist/session.js +133 -13
- package/dist/session.js.map +1 -1
- package/dist/source.d.ts +2 -10
- package/dist/source.js.map +1 -1
- package/dist/update.d.ts +8 -20
- package/dist/update.js +12 -1
- package/dist/update.js.map +1 -1
- package/package.json +4 -2
- package/plugins/approval/index.ts +233 -85
- package/plugins/approval/plugin.json +1 -1
- package/plugins/approval/policy.ts +2 -1
- package/plugins/approval/review.ts +1 -1
- package/plugins/ask/index.ts +2 -2
- package/plugins/budget/index.ts +1 -1
- package/plugins/checks/checks.ts +3 -2
- package/plugins/checks/index.ts +2 -5
- package/plugins/commands/index.ts +2 -44
- package/plugins/compact/compact.ts +8 -3
- package/plugins/compact/index.ts +13 -16
- package/plugins/continue/index.ts +1 -1
- package/plugins/cost/index.ts +143 -0
- package/plugins/cost/plugin.json +13 -0
- package/plugins/custom-commands/index.ts +85 -0
- package/plugins/custom-commands/plugin.json +8 -0
- package/plugins/editor/index.ts +88 -0
- package/plugins/editor/plugin.json +17 -0
- package/plugins/fs/fs.ts +33 -6
- package/plugins/fs/grep.ts +6 -4
- package/plugins/fs/index.ts +2 -3
- package/plugins/fs/renderers.ts +1 -1
- package/plugins/hooks/index.ts +152 -0
- package/plugins/hooks/plugin.json +14 -0
- package/plugins/keys/index.ts +2 -18
- package/plugins/mcp/index.ts +40 -12
- package/plugins/mcp/install.ts +139 -0
- package/plugins/mcp/mcp.ts +2 -1
- package/plugins/mcp/plugin.json +1 -1
- package/plugins/mcp/project.ts +37 -1
- package/plugins/memory/index.ts +4 -9
- package/plugins/memory/plugin.json +1 -1
- package/plugins/mentions/index.ts +2 -2
- package/plugins/models/configure.ts +258 -150
- package/plugins/models/context.ts +2 -2
- package/plugins/models/index.ts +35 -42
- package/plugins/models/plugin.json +1 -1
- package/plugins/models/provider.ts +22 -4
- package/plugins/models/saved.ts +8 -4
- package/plugins/modes/index.ts +2 -17
- package/plugins/plugins/index.ts +2 -2
- package/plugins/print/index.ts +36 -6
- package/plugins/print/plugin.json +1 -0
- package/plugins/prompts/index.ts +22 -14
- package/plugins/{memory → prompts}/notes.ts +21 -9
- package/plugins/prompts/plugin.json +8 -2
- package/plugins/prompts/prompts.ts +5 -4
- package/plugins/renderers/index.ts +2 -43
- package/plugins/repeats/index.ts +1 -1
- package/plugins/schedule/index.ts +2 -2
- package/plugins/scratch/index.ts +2 -3
- package/plugins/screenshot/index.ts +26 -13
- package/plugins/screenshot/plugin.json +1 -1
- package/plugins/sessions/index.ts +2 -17
- package/plugins/shell/index.ts +56 -6
- package/plugins/shell/plugin.json +3 -1
- package/plugins/shell/renderers.ts +1 -1
- package/plugins/shell/service.ts +2 -13
- package/plugins/shell/shell.ts +31 -16
- package/plugins/skills/index.ts +172 -37
- package/plugins/skills/install.ts +212 -0
- package/plugins/skills/plugin.json +3 -2
- package/plugins/skills/project.ts +38 -1
- package/plugins/skills/skills.ts +28 -9
- package/plugins/steer/index.ts +142 -0
- package/plugins/steer/plugin.json +8 -0
- package/plugins/suggest/index.ts +16 -11
- package/plugins/suggest/plugin.json +1 -1
- package/plugins/task/index.ts +7 -16
- package/plugins/task/plugin.json +9 -2
- package/plugins/task/subagent.ts +23 -5
- package/plugins/todo/index.ts +2 -2
- package/plugins/tui/editor.ts +10 -2
- package/plugins/tui/frontend.ts +103 -21
- package/plugins/tui/index.ts +3 -8
- package/plugins/tui/markdown.ts +51 -6
- package/plugins/tui/mascot.ts +505 -0
- package/plugins/tui/plugin.json +2 -2
- package/plugins/tui/screen.ts +6 -0
- package/plugins/tui/transcript.ts +17 -2
- package/plugins/tui/tui.ts +321 -90
- package/plugins/undo/checkpoint.ts +2 -2
- package/plugins/undo/index.ts +84 -26
- package/plugins/undo/plugin.json +8 -2
- package/plugins/undo/snapshot.ts +129 -0
- package/plugins/update/index.ts +11 -15
- package/plugins/update/plugin.json +2 -1
- package/plugins/web/index.ts +2 -5
- package/plugins/web/renderers.ts +1 -1
- package/plugins-dist/approval/index.js +217 -51
- package/plugins-dist/approval/plugin.json +1 -1
- package/plugins-dist/ask/index.js +1 -1
- package/plugins-dist/budget/index.js +1 -1
- package/plugins-dist/checks/checks.js +2 -1
- package/plugins-dist/checks/index.js +1 -1
- package/plugins-dist/commands/index.js +1 -1
- package/plugins-dist/compact/compact.js +6 -1
- package/plugins-dist/compact/index.js +12 -8
- package/plugins-dist/continue/index.js +1 -1
- package/plugins-dist/cost/index.js +135 -0
- package/plugins-dist/cost/plugin.json +16 -0
- package/plugins-dist/custom-commands/index.js +86 -0
- package/plugins-dist/custom-commands/plugin.json +12 -0
- package/plugins-dist/editor/index.js +89 -0
- package/plugins-dist/editor/plugin.json +21 -0
- package/plugins-dist/fs/fs.js +34 -6
- package/plugins-dist/fs/grep.js +5 -3
- package/plugins-dist/fs/index.js +1 -1
- package/plugins-dist/hooks/index.js +145 -0
- package/plugins-dist/hooks/plugin.json +19 -0
- package/plugins-dist/keys/index.js +1 -1
- package/plugins-dist/mcp/index.js +41 -9
- package/plugins-dist/mcp/install.js +160 -0
- package/plugins-dist/mcp/mcp.js +2 -1
- package/plugins-dist/mcp/plugin.json +2 -1
- package/plugins-dist/mcp/project.js +42 -1
- package/plugins-dist/memory/index.js +3 -5
- package/plugins-dist/memory/plugin.json +1 -1
- package/plugins-dist/mentions/index.js +1 -1
- package/plugins-dist/models/configure.js +252 -151
- package/plugins-dist/models/context.js +2 -2
- package/plugins-dist/models/index.js +37 -14
- package/plugins-dist/models/plugin.json +1 -1
- package/plugins-dist/models/provider.js +4 -2
- package/plugins-dist/models/saved.js +9 -4
- package/plugins-dist/modes/index.js +1 -1
- package/plugins-dist/plugins/index.js +1 -1
- package/plugins-dist/print/index.js +37 -3
- package/plugins-dist/print/plugin.json +3 -0
- package/plugins-dist/prompts/index.js +22 -3
- package/plugins-dist/{memory → prompts}/notes.js +10 -7
- package/plugins-dist/prompts/plugin.json +8 -2
- package/plugins-dist/prompts/prompts.js +5 -4
- package/plugins-dist/renderers/index.js +1 -1
- package/plugins-dist/repeats/index.js +1 -1
- package/plugins-dist/schedule/index.js +1 -1
- package/plugins-dist/scratch/index.js +1 -1
- package/plugins-dist/screenshot/index.js +25 -11
- package/plugins-dist/screenshot/plugin.json +1 -1
- package/plugins-dist/sessions/index.js +1 -1
- package/plugins-dist/shell/index.js +55 -3
- package/plugins-dist/shell/plugin.json +3 -1
- package/plugins-dist/shell/shell.js +26 -8
- package/plugins-dist/skills/index.js +184 -35
- package/plugins-dist/skills/install.js +178 -0
- package/plugins-dist/skills/plugin.json +6 -2
- package/plugins-dist/skills/project.js +43 -1
- package/plugins-dist/skills/skills.js +27 -10
- package/plugins-dist/steer/index.js +135 -0
- package/plugins-dist/steer/plugin.json +12 -0
- package/plugins-dist/suggest/index.js +15 -9
- package/plugins-dist/suggest/plugin.json +1 -1
- package/plugins-dist/task/index.js +6 -4
- package/plugins-dist/task/plugin.json +10 -2
- package/plugins-dist/task/subagent.js +20 -5
- package/plugins-dist/todo/index.js +1 -1
- package/plugins-dist/tui/editor.js +7 -2
- package/plugins-dist/tui/frontend.js +107 -13
- package/plugins-dist/tui/index.js +2 -1
- package/plugins-dist/tui/markdown.js +48 -6
- package/plugins-dist/tui/mascot.js +439 -0
- package/plugins-dist/tui/plugin.json +3 -2
- package/plugins-dist/tui/screen.js +2 -0
- package/plugins-dist/tui/transcript.js +16 -1
- package/plugins-dist/tui/tui.js +302 -81
- package/plugins-dist/undo/checkpoint.js +1 -1
- package/plugins-dist/undo/index.js +91 -24
- package/plugins-dist/undo/plugin.json +10 -3
- package/plugins-dist/undo/snapshot.js +111 -0
- package/plugins-dist/update/index.js +9 -10
- package/plugins-dist/update/plugin.json +4 -1
- package/plugins-dist/web/index.js +1 -1
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +8 -0
- package/src/api.ts +7 -262
- package/src/fetch.ts +18 -16
- package/src/host.ts +49 -1
- package/src/index.ts +1 -1
- package/src/main.ts +23 -5
- package/src/remote.ts +2 -0
- package/src/session.ts +134 -15
- package/src/source.ts +2 -11
- package/src/update.ts +16 -10
- package/plugins/undo/notes.ts +0 -43
- package/plugins-dist/undo/notes.js +0 -36
|
@@ -0,0 +1,212 @@
|
|
|
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
|
+
|
|
9
|
+
import { randomBytes } from "node:crypto";
|
|
10
|
+
import { mkdir, readdir, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import type { PluginSourceSpec, Sources } from "@uncarved/jade-api";
|
|
13
|
+
import { NAME, parseSkill } from "./skills.ts";
|
|
14
|
+
|
|
15
|
+
export interface SkillRecord {
|
|
16
|
+
name: string;
|
|
17
|
+
/** 用户写的来源 */
|
|
18
|
+
source: string;
|
|
19
|
+
/** 解析后的来源(git 地址、npm 写法或绝对路径);更新时直接用它 */
|
|
20
|
+
location: string;
|
|
21
|
+
kind: PluginSourceSpec["kind"];
|
|
22
|
+
ref?: string;
|
|
23
|
+
subdir?: string;
|
|
24
|
+
commit?: string;
|
|
25
|
+
/** 安装时 skill 目录的内容哈希 */
|
|
26
|
+
hash: string;
|
|
27
|
+
installedAt: string;
|
|
28
|
+
updatedAt?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface InstallOptions {
|
|
32
|
+
/** 核心的 sources@1:识别来源、下载、算内容哈希 */
|
|
33
|
+
sources: Sources;
|
|
34
|
+
/** $JADE_HOME/skills 或 <工作目录>/.jade/skills */
|
|
35
|
+
root: string;
|
|
36
|
+
/** 解析相对路径用 */
|
|
37
|
+
cwd: string;
|
|
38
|
+
/** 只用来源里的这个子目录 */
|
|
39
|
+
subdir?: string;
|
|
40
|
+
/** 已有同名 skill,或装好后被手动改过时,照样替换 */
|
|
41
|
+
force?: boolean;
|
|
42
|
+
log?: (text: string) => void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 不加 --project 装到 $JADE_HOME/skills,加了装到 <工作目录>/.jade/skills */
|
|
46
|
+
export const skillsRoot = (home: string, cwd: string, project: boolean) => (project ? path.join(cwd, ".jade", "skills") : path.join(home, "skills"));
|
|
47
|
+
|
|
48
|
+
const RECORDS = ".installed.json";
|
|
49
|
+
|
|
50
|
+
export async function readRecords(root: string): Promise<Record<string, SkillRecord>> {
|
|
51
|
+
let text: string;
|
|
52
|
+
try {
|
|
53
|
+
text = await readFile(path.join(root, RECORDS), "utf8");
|
|
54
|
+
} catch {
|
|
55
|
+
return {};
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(text) as Record<string, SkillRecord>;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw new Error(`${path.join(root, RECORDS)}: ${e instanceof Error ? e.message : String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function writeRecords(root: string, records: Record<string, SkillRecord>): Promise<void> {
|
|
65
|
+
await writeFile(path.join(root, RECORDS), JSON.stringify(records, null, 2) + "\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const exists = (p: string) => stat(p).then(() => true, () => false);
|
|
69
|
+
|
|
70
|
+
/** 把 --path 限制在来源目录里,不能跑到外面去 */
|
|
71
|
+
function inSubdir(root: string, subdir: string): string {
|
|
72
|
+
const full = path.resolve(root, subdir);
|
|
73
|
+
const rel = path.relative(root, full);
|
|
74
|
+
if (rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) throw new Error(`--path ${subdir} points outside the source`);
|
|
75
|
+
return full;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 服务里抛出的错误带着 "plugin jade (sources@1.fetch): " 的前缀;给用户看的只要原来那句 */
|
|
79
|
+
async function plain<T>(call: Promise<T>): Promise<T> {
|
|
80
|
+
try {
|
|
81
|
+
return await call;
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw e instanceof Error && e.name === "PluginError" && e.cause instanceof Error ? e.cause : e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 安装一个 skill,返回它的名字和目录 */
|
|
88
|
+
export async function addSkill(spec: string, opts: InstallOptions): Promise<{ name: string; dir: string }> {
|
|
89
|
+
const source = await plain(opts.sources.parse(spec, opts.cwd));
|
|
90
|
+
const record = await install(source, opts);
|
|
91
|
+
return { name: record.name, dir: path.join(path.resolve(opts.root), record.name) };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 按安装记录重新下载;没给名字时更新这个目录里所有装过的 skill。返回每个 skill 一行结果 */
|
|
95
|
+
export async function updateSkills(names: readonly string[], opts: Omit<InstallOptions, "subdir">): Promise<string[]> {
|
|
96
|
+
const root = path.resolve(opts.root);
|
|
97
|
+
const records = await readRecords(root);
|
|
98
|
+
const lines: string[] = [];
|
|
99
|
+
for (const name of names.length ? names : Object.keys(records).sort()) {
|
|
100
|
+
const rec = records[name];
|
|
101
|
+
if (!rec) {
|
|
102
|
+
lines.push(`${name}: not installed with "/skills add"${(await exists(path.join(root, name))) ? "; update it by hand" : ""}`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const dir = path.join(root, name);
|
|
107
|
+
if (!opts.force && (await exists(dir)) && (await opts.sources.hash(dir)) !== rec.hash) {
|
|
108
|
+
lines.push(`${name}: changed since it was installed; add --force to overwrite the changes`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const source: PluginSourceSpec = { kind: rec.kind, location: rec.location, spec: rec.source, ...(rec.ref ? { ref: rec.ref } : {}) };
|
|
112
|
+
const next = await install(source, { ...opts, force: true, ...(rec.subdir ? { subdir: rec.subdir } : {}) }, rec);
|
|
113
|
+
lines.push(next.hash === rec.hash ? `current ${name}` : `updated ${name}`);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
lines.push(`${name}: ${e instanceof Error ? e.message : String(e)}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return lines;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** 删掉一个 skill 目录和它的安装记录;手动放进去的也能删 */
|
|
122
|
+
export async function removeSkill(name: string, root: string): Promise<string> {
|
|
123
|
+
if (!NAME.test(name)) throw new Error(`invalid skill name ${JSON.stringify(name)}`);
|
|
124
|
+
root = path.resolve(root);
|
|
125
|
+
const dir = path.join(root, name);
|
|
126
|
+
if (!(await exists(path.join(dir, "SKILL.md")))) throw new Error(`there is no skill ${name} in ${root}`);
|
|
127
|
+
await rm(dir, { recursive: true, force: true });
|
|
128
|
+
const records = await readRecords(root);
|
|
129
|
+
if (records[name]) {
|
|
130
|
+
delete records[name];
|
|
131
|
+
await writeRecords(root, records);
|
|
132
|
+
}
|
|
133
|
+
return dir;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 下载、找到 SKILL.md、换进正式目录、写安装记录。更新时 prev 给出原来的记录(名字不变) */
|
|
137
|
+
async function install(source: PluginSourceSpec, opts: InstallOptions, prev?: SkillRecord): Promise<SkillRecord> {
|
|
138
|
+
const root = path.resolve(opts.root);
|
|
139
|
+
// 本地来源包含 skills 目录时,staging 会被复制进去(甚至递归复制自己)
|
|
140
|
+
if (source.kind === "local") {
|
|
141
|
+
const from = opts.subdir ? inSubdir(source.location, opts.subdir) : source.location;
|
|
142
|
+
const rel = path.relative(from, root);
|
|
143
|
+
if (rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel))) {
|
|
144
|
+
throw new Error(`${source.location} contains the skills directory; give the skill's own directory, or use --path`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
await mkdir(root, { recursive: true });
|
|
148
|
+
const records = await readRecords(root);
|
|
149
|
+
const staging = path.join(root, `.staging-${randomBytes(4).toString("hex")}`);
|
|
150
|
+
try {
|
|
151
|
+
const { root: fetched, commit } = await plain(opts.sources.fetch(source, staging, opts.log));
|
|
152
|
+
const dir = opts.subdir ? inSubdir(fetched, opts.subdir) : fetched;
|
|
153
|
+
if (!(await exists(path.join(dir, "SKILL.md")))) throw new Error(await noSkillMessage(source.spec, dir, fetched));
|
|
154
|
+
const name = prev?.name ?? skillName(parseSkill(await readFile(path.join(dir, "SKILL.md"), "utf8")).meta.name, source, opts.subdir);
|
|
155
|
+
const target = path.join(root, name);
|
|
156
|
+
if (!opts.force && (await exists(target))) {
|
|
157
|
+
throw new Error(`skill ${name} is already installed in ${target}; run "/skills update ${name}", or add --force to replace it`);
|
|
158
|
+
}
|
|
159
|
+
const hash = await opts.sources.hash(dir);
|
|
160
|
+
await rm(target, { recursive: true, force: true });
|
|
161
|
+
await rename(dir, target);
|
|
162
|
+
const now = new Date().toISOString();
|
|
163
|
+
const record: SkillRecord = {
|
|
164
|
+
name,
|
|
165
|
+
source: source.spec,
|
|
166
|
+
location: source.location,
|
|
167
|
+
kind: source.kind,
|
|
168
|
+
...(source.ref ? { ref: source.ref } : {}),
|
|
169
|
+
...(opts.subdir ? { subdir: opts.subdir } : {}),
|
|
170
|
+
...(commit ? { commit } : {}),
|
|
171
|
+
hash,
|
|
172
|
+
installedAt: prev?.installedAt ?? now,
|
|
173
|
+
...(prev ? { updatedAt: now } : {}),
|
|
174
|
+
};
|
|
175
|
+
records[name] = record;
|
|
176
|
+
await writeRecords(root, records);
|
|
177
|
+
return record;
|
|
178
|
+
} finally {
|
|
179
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** SKILL.md 里的 name;没有时用 --path 的最后一段,再没有就用仓库名、包名或目录名 */
|
|
184
|
+
function skillName(declared: string | undefined, source: PluginSourceSpec, subdir?: string): string {
|
|
185
|
+
const fromSource =
|
|
186
|
+
source.kind === "npm"
|
|
187
|
+
? source.location.replace(/^@[^/]+\//, "").replace(/@.*$/, "").replace(/\.(tgz|tar\.gz)$/i, "")
|
|
188
|
+
: source.location.replace(/[\\/]+$/, "").replace(/\.git$/, "");
|
|
189
|
+
const candidates = [declared, subdir && path.basename(subdir.replace(/[\\/]+$/, "")), path.basename(fromSource)];
|
|
190
|
+
const name = candidates.find((c) => c && NAME.test(c));
|
|
191
|
+
if (!name) throw new Error(`could not tell the skill's name; give it a "name:" in SKILL.md`);
|
|
192
|
+
return name;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** 来源里没有 SKILL.md 时:列出它里面的 skill,提示用 --path 选一个 */
|
|
196
|
+
async function noSkillMessage(spec: string, dir: string, fetched: string): Promise<string> {
|
|
197
|
+
let found: string[] = [];
|
|
198
|
+
try {
|
|
199
|
+
found = (await readdir(fetched, { recursive: true, withFileTypes: true }))
|
|
200
|
+
.filter((e) => e.isFile() && e.name === "SKILL.md")
|
|
201
|
+
.map((e) => path.relative(fetched, e.parentPath).split(path.sep).join("/"))
|
|
202
|
+
.filter((d) => d && !d.split("/").some((seg) => seg === "node_modules" || seg.startsWith(".")))
|
|
203
|
+
.sort();
|
|
204
|
+
} catch {
|
|
205
|
+
// 没有可列的
|
|
206
|
+
}
|
|
207
|
+
const where = path.relative(fetched, dir).split(path.sep).join("/");
|
|
208
|
+
const head = `${spec}${where ? ` (--path ${where})` : ""} has no SKILL.md`;
|
|
209
|
+
if (found.length === 0) return `${head}; it is not a skill`;
|
|
210
|
+
const shown = found.slice(0, 20).map((d) => ` ${d}`).join("\n") + (found.length > 20 ? `\n … ${found.length - 20} more` : "");
|
|
211
|
+
return `${head}. It contains these skills; pick one with --path <dir>:\n${shown}`;
|
|
212
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "jade/skills",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"api": "^1",
|
|
5
5
|
"entry": "./index.ts",
|
|
6
|
-
"
|
|
6
|
+
"requires": ["sources@1"],
|
|
7
|
+
"optional": ["ui@1", "prompts@1", "commands@1", "approval@1", "cli@1"]
|
|
7
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 仓库目录、显示用的小工具、斜杠命令参数的切分、token 估算。插件之间不共享代码(只能共享类型),jade/mcp、jade/checks 各有一份。
|
|
2
2
|
|
|
3
3
|
import { existsSync, realpathSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
@@ -46,4 +46,41 @@ const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
|
46
46
|
const paint = (open: string, close: string) => (s: string) =>
|
|
47
47
|
colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
|
|
48
48
|
export const dim = paint("2", "22");
|
|
49
|
+
export const red = paint("31", "39");
|
|
49
50
|
export const bold = paint("1", "22");
|
|
51
|
+
|
|
52
|
+
/** 斜杠命令的参数按空白切开;"…" 或 '…' 里的空白不切(不处理反斜杠,Windows 路径照写) */
|
|
53
|
+
export function splitArgs(text: string): string[] {
|
|
54
|
+
const out: string[] = [];
|
|
55
|
+
let cur = "";
|
|
56
|
+
let started = false;
|
|
57
|
+
let quote: string | undefined;
|
|
58
|
+
for (const ch of text) {
|
|
59
|
+
if (quote) {
|
|
60
|
+
if (ch === quote) quote = undefined;
|
|
61
|
+
else cur += ch;
|
|
62
|
+
} else if (ch === '"' || ch === "'") {
|
|
63
|
+
quote = ch;
|
|
64
|
+
started = true;
|
|
65
|
+
} else if (/\s/.test(ch)) {
|
|
66
|
+
if (started) out.push(cur);
|
|
67
|
+
cur = "";
|
|
68
|
+
started = false;
|
|
69
|
+
} else {
|
|
70
|
+
cur += ch;
|
|
71
|
+
started = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (quote) throw new Error(`unclosed ${quote}`);
|
|
75
|
+
if (started) out.push(cur);
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 中日韩文字和全角符号:大约一个字一个 token(和 jade/compact 的估算一致) */
|
|
80
|
+
const WIDE = /[ -鿿가-豈--]/g;
|
|
81
|
+
|
|
82
|
+
/** 粗略估算一段文字发给模型时占多少 token:英文和代码约 4 个字符 1 个,中日韩文字每字约 1 个 */
|
|
83
|
+
export function estimateTokens(text: string): number {
|
|
84
|
+
const wide = text.match(WIDE)?.length ?? 0;
|
|
85
|
+
return Math.ceil((text.length - wide) / 4 + wide);
|
|
86
|
+
}
|
package/plugins/skills/skills.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface Skill {
|
|
|
29
29
|
overrides?: string;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
32
|
+
export const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
33
33
|
/** 系统提示词里每个描述的上限 */
|
|
34
34
|
const MAX_DESCRIPTION = 400;
|
|
35
35
|
/** skill 工具列出的目录内文件数上限 */
|
|
@@ -120,6 +120,9 @@ export function parseSkill(text: string): { meta: Record<string, string>; body:
|
|
|
120
120
|
return { meta, body: body.trim() };
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/** 系统提示词的 skill 列表里这个 skill 的一行(/skills 按它估算占用) */
|
|
124
|
+
export const skillLine = (s: Skill) => `- ${s.name}: ${s.description.replace(/\s+/g, " ")}`;
|
|
125
|
+
|
|
123
126
|
/** 系统提示词里的 skill 列表;没有 skill 时为 undefined */
|
|
124
127
|
export function skillsPrompt(skills: Skill[]): string | undefined {
|
|
125
128
|
if (skills.length === 0) return undefined;
|
|
@@ -129,20 +132,29 @@ export function skillsPrompt(skills: Skill[]): string | undefined {
|
|
|
129
132
|
"When a task matches a skill's description, call the skill tool with its name before starting, then follow the instructions it returns. " +
|
|
130
133
|
"Files a skill refers to are relative to its directory, which the skill tool tells you.",
|
|
131
134
|
"",
|
|
132
|
-
...skills.map(
|
|
135
|
+
...skills.map(skillLine),
|
|
133
136
|
].join("\n");
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
/**
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
/**
|
|
140
|
+
* skill 工具:读入某个 skill 的正文,以及它目录里的文件。
|
|
141
|
+
* 会话里的工具列表在会话创建时就定了,所以不管有没有 skill 都注册它,名字也不写成 enum:
|
|
142
|
+
* 会话中途装的 skill 用 current() 取最新的列表,找不到时先 refresh() 重新查找一次。
|
|
143
|
+
* 说明里告诉模型怎么装 skill(装到 install 给的目录),否则它会照别的工具的习惯放进 .claude/skills
|
|
144
|
+
*/
|
|
145
|
+
export function skillTool(current: () => Skill[], refresh: () => Promise<void>, install: { user: string; project: string }): Tool {
|
|
146
|
+
const lookup = (name: string) => current().find((s) => s.name.toLowerCase() === name.toLowerCase());
|
|
139
147
|
return {
|
|
140
148
|
name: "skill",
|
|
141
149
|
description:
|
|
142
|
-
|
|
150
|
+
'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. ' +
|
|
151
|
+
"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; " +
|
|
152
|
+
"add `--path <dir>` for one skill inside a repository with several). It installs into " +
|
|
153
|
+
`${install.user}; add \`--project\` to install into ${install.project} for this project only. ` +
|
|
154
|
+
"Do not copy skills into .claude/skills. A newly installed skill can be used right away.",
|
|
143
155
|
inputSchema: {
|
|
144
156
|
type: "object",
|
|
145
|
-
properties: { name: { type: "string",
|
|
157
|
+
properties: { name: { type: "string", description: "the skill's name" } },
|
|
146
158
|
required: ["name"],
|
|
147
159
|
additionalProperties: false,
|
|
148
160
|
},
|
|
@@ -151,8 +163,15 @@ export function skillTool(skills: Skill[]): Tool {
|
|
|
151
163
|
idempotent: true,
|
|
152
164
|
async execute(input) {
|
|
153
165
|
const name = String((input as { name?: unknown }).name ?? "");
|
|
154
|
-
|
|
155
|
-
if (!skill)
|
|
166
|
+
let skill = lookup(name);
|
|
167
|
+
if (!skill) {
|
|
168
|
+
await refresh();
|
|
169
|
+
skill = lookup(name);
|
|
170
|
+
}
|
|
171
|
+
if (!skill) {
|
|
172
|
+
const names = current().map((s) => s.name);
|
|
173
|
+
return { content: `There is no skill named ${JSON.stringify(name)}. ${names.length ? `Available: ${names.join(", ")}.` : "No skills are installed."}`, isError: true };
|
|
174
|
+
}
|
|
156
175
|
let text: string;
|
|
157
176
|
try {
|
|
158
177
|
text = await readFile(path.join(skill.dir, "SKILL.md"), "utf8");
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// jade/steer:在一轮的中途对模型说话。内核只在空闲时接受用户消息(一轮没完时不能再发一条),
|
|
2
|
+
// 所以不走输入:前端经 steer@1 把话交过来,下一次请求模型时在 context.project 里附在最后一条消息
|
|
3
|
+
// (这时是刚执行完的工具的结果)后面,并写进日志(derived),之后的投影、恢复的会话里它都在同一个位置。
|
|
4
|
+
// 和 prompts@1 的 note 是同一个办法,区别是这里是用户自己说的话,所以项目层插件不能用。
|
|
5
|
+
//
|
|
6
|
+
// 这一轮没有再请求模型就结束了的(模型正在写最后一条回复时说的),话还留在这里:前端在一轮结束后用 take 取回,
|
|
7
|
+
// 当作普通消息发出去。
|
|
8
|
+
|
|
9
|
+
import type { Block, Message } from "uncarved";
|
|
10
|
+
import { definePlugin } from "@uncarved/jade-api";
|
|
11
|
+
import type { Renderers, Steer } from "@uncarved/jade-api/services";
|
|
12
|
+
|
|
13
|
+
const ID = "jade/steer";
|
|
14
|
+
/** derived 里:消息的下标 → 附在它后面的话 */
|
|
15
|
+
const KEY = `${ID}/said`;
|
|
16
|
+
type Said = Record<string, string[]>;
|
|
17
|
+
|
|
18
|
+
/** 附在用户的话前面,告诉模型这是中途说的 */
|
|
19
|
+
export const MARKER = "[The user sent the following while you were working. Take it into account from here on.]";
|
|
20
|
+
|
|
21
|
+
interface Entry {
|
|
22
|
+
/** 还没交给模型的话 */
|
|
23
|
+
pending: string[];
|
|
24
|
+
/** 这个会话有没有一轮正在跑 */
|
|
25
|
+
running(): boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 打开着的会话。模块每个进程只加载一次,进程级和会话级共用 */
|
|
29
|
+
const sessions = new Map<string, Entry>();
|
|
30
|
+
const watchers = new Set<() => void>();
|
|
31
|
+
|
|
32
|
+
function changed(): void {
|
|
33
|
+
for (const fn of [...watchers]) {
|
|
34
|
+
try {
|
|
35
|
+
fn();
|
|
36
|
+
} catch {
|
|
37
|
+
// 订阅者的错不连累这里
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const bold = (s: string) => `\x1b[1m${s}\x1b[22m`;
|
|
43
|
+
const dim = (s: string) => `\x1b[2m${s}\x1b[22m`;
|
|
44
|
+
|
|
45
|
+
export default definePlugin({
|
|
46
|
+
process(ctx) {
|
|
47
|
+
ctx.provide("steer@1", (caller): Steer => {
|
|
48
|
+
const user = (method: string) => {
|
|
49
|
+
if (caller.layer === "project") throw new Error(`steer.${method}: project plugins cannot speak for the user`);
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
push(session, text) {
|
|
53
|
+
user("push");
|
|
54
|
+
if (typeof text !== "string" || !text.trim()) throw new Error("steer.push: text must be a non-empty string");
|
|
55
|
+
const s = sessions.get(session);
|
|
56
|
+
if (!s?.running()) return false;
|
|
57
|
+
s.pending.push(text);
|
|
58
|
+
changed();
|
|
59
|
+
return true;
|
|
60
|
+
},
|
|
61
|
+
pending: (session) => [...(sessions.get(session)?.pending ?? [])],
|
|
62
|
+
take(session) {
|
|
63
|
+
user("take");
|
|
64
|
+
const taken = sessions.get(session)?.pending.splice(0) ?? [];
|
|
65
|
+
if (taken.length > 0) changed();
|
|
66
|
+
return taken;
|
|
67
|
+
},
|
|
68
|
+
subscribe(fn) {
|
|
69
|
+
if (typeof fn !== "function") throw new Error("steer.subscribe: fn must be a function");
|
|
70
|
+
watchers.add(fn);
|
|
71
|
+
const off = () => void watchers.delete(fn);
|
|
72
|
+
caller.onDispose(off);
|
|
73
|
+
return off;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 交给模型的那一刻在对话里显示出来,和用户发的消息一个样子;恢复的会话重新显示时也在原来的位置
|
|
79
|
+
ctx.service<Renderers>("renderers@1")?.event({
|
|
80
|
+
event: "said",
|
|
81
|
+
render(data) {
|
|
82
|
+
const text = (data as { text?: unknown } | null)?.text;
|
|
83
|
+
if (typeof text !== "string") return undefined;
|
|
84
|
+
return { line: `\n${bold(`› ${text.replace(/\n/g, "\n ")}`)} ${dim("(sent while working)")}` };
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
async session(ctx) {
|
|
90
|
+
const id = ctx.session.id;
|
|
91
|
+
const entry: Entry = {
|
|
92
|
+
pending: [],
|
|
93
|
+
running() {
|
|
94
|
+
try {
|
|
95
|
+
const phase = ctx.session.state().phase;
|
|
96
|
+
return phase !== "new" && phase !== "idle" && phase !== "ended";
|
|
97
|
+
} catch {
|
|
98
|
+
// 会话还没建好,或者已经关了
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
sessions.set(id, entry);
|
|
104
|
+
await ctx.effect(() => () => {
|
|
105
|
+
if (sessions.get(id) === entry) sessions.delete(id);
|
|
106
|
+
if (entry.pending.length > 0) changed();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
ctx.kernel.hook({
|
|
110
|
+
kind: "transform",
|
|
111
|
+
point: "context.project",
|
|
112
|
+
// 排在压缩之类改动消息列表的 hook 前面:下标按日志里的消息算
|
|
113
|
+
order: -39,
|
|
114
|
+
fn: async (messages, hook) => {
|
|
115
|
+
let said = (hook.derived[KEY] as Said | undefined) ?? {};
|
|
116
|
+
if (entry.pending.length > 0 && messages.at(-1)?.role === "user") {
|
|
117
|
+
const texts = entry.pending.splice(0);
|
|
118
|
+
const at = String(messages.length - 1);
|
|
119
|
+
said = { ...said, [at]: [...(said[at] ?? []), ...texts] };
|
|
120
|
+
try {
|
|
121
|
+
// 先落盘再用(I-5);事件给前端显示
|
|
122
|
+
await hook.record(KEY, said);
|
|
123
|
+
for (const text of texts) await hook.emit("said", { text });
|
|
124
|
+
} catch (e) {
|
|
125
|
+
entry.pending.unshift(...texts);
|
|
126
|
+
throw e;
|
|
127
|
+
}
|
|
128
|
+
changed();
|
|
129
|
+
}
|
|
130
|
+
return messages.map((m, i): Message => {
|
|
131
|
+
const texts = said[i];
|
|
132
|
+
if (!texts?.length || m.role !== "user") return m;
|
|
133
|
+
const blocks: Block[] = [
|
|
134
|
+
{ kind: "text", text: MARKER, origin: { by: "plugin", id: ID }, trust: "trusted" },
|
|
135
|
+
...texts.map((text): Block => ({ kind: "text", text, origin: { by: "user" }, trust: "trusted" })),
|
|
136
|
+
];
|
|
137
|
+
return { ...m, content: [...m.content, ...blocks] };
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
});
|
package/plugins/suggest/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// jade/suggest:每一轮正常结束后,预测用户下一条想发的消息,灰色显示在输入框里,Tab 或 → 接受。默认关着(enabled)。
|
|
2
2
|
//
|
|
3
|
-
// 模型经 models@1:配置 model 是 /model
|
|
3
|
+
// 模型经 models@1:配置 model 是 /model 保存过的模型名或当前服务上的模型名,不设时用会话的模型。
|
|
4
4
|
// /suggest 在 TUI 里开关、选模型,马上生效,记在 $JADE_HOME/state/suggest.json,盖过 config.json 里的 enabled 和 model。
|
|
5
5
|
// 对话从 context.project(每次请求模型前的消息)和 model.after(这一轮最后的回复)取,轮次结束从 turn.ended 事件知道。
|
|
6
6
|
// 从旧 jade 的 examples/plugins/suggest 移植;提示词、对话的整理和截取、回复的清理参考 dsh-ghost-prompt。
|
|
@@ -9,9 +9,8 @@ import { randomBytes } from "node:crypto";
|
|
|
9
9
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import type { Delta, Message, ModelRequest } from "uncarved";
|
|
12
|
-
import { definePlugin, type UI } from "
|
|
13
|
-
import type { Commands } from "
|
|
14
|
-
import type { Models } from "../models/index.ts";
|
|
12
|
+
import { definePlugin, type UI } from "@uncarved/jade-api";
|
|
13
|
+
import type { Commands, Models } from "@uncarved/jade-api/services";
|
|
15
14
|
|
|
16
15
|
export const SYSTEM = [
|
|
17
16
|
"You predict the next message the USER will type to an AI coding assistant.",
|
|
@@ -21,6 +20,9 @@ export const SYSTEM = [
|
|
|
21
20
|
"- Match the language and tone the user has been writing in. If the user writes Chinese, answer in Chinese.",
|
|
22
21
|
"- Keep it short: one sentence, at most about 20 words or 40 CJK characters.",
|
|
23
22
|
"- Prefer the obvious next step: answering a question the assistant just asked, approving a proposed plan, verifying or continuing the work.",
|
|
23
|
+
"- The user gives instructions; write an instruction or a short answer, not a question.",
|
|
24
|
+
'- Never summarize or describe the work that was done (wrong: "the Title weights are fixed now"). That is the assistant\'s job, not the user\'s.',
|
|
25
|
+
'- Never speak as the assistant: no offers or plans like "want me to...", "I will...", "需要我…吗", "我会…". When the assistant offered something, the user accepts or declines it (assistant: "I can commit this if you want" -> user: "commit it").',
|
|
24
26
|
"- Never repeat a request the user already made, and never invent facts, file names or numbers not in the conversation.",
|
|
25
27
|
"- If no next message is reasonably predictable, output exactly: NONE",
|
|
26
28
|
'Output only the message text on one line. No quotes, no prefix like "User:", no explanation, no Markdown.',
|
|
@@ -84,11 +86,12 @@ const LEADING_PREFIX = /^(?:user|用户)\s*[::]\s*/i;
|
|
|
84
86
|
const LEADING_QUOTES = /^["'“”‘’`「『]+/;
|
|
85
87
|
const TRAILING_QUOTES = /["'“”‘’`」』]+$/;
|
|
86
88
|
|
|
87
|
-
/** 模型回复的第一行整理成建议:去掉 "User:" 前缀和包着的引号;NONE
|
|
89
|
+
/** 模型回复的第一行整理成建议:去掉 "User:" 前缀和包着的引号;NONE、空或问句的时候 undefined */
|
|
88
90
|
export function tidy(reply: string): string | undefined {
|
|
89
91
|
let line = reply.trimStart().split(/\r?\n/)[0]!.trim().replace(LEADING_PREFIX, "");
|
|
90
92
|
if (LEADING_QUOTES.test(line)) line = line.replace(LEADING_QUOTES, "").replace(TRAILING_QUOTES, "").trim();
|
|
91
|
-
|
|
93
|
+
// 问句多半是模型把助手的"要不要我…?"当成了用户的话,猜中用户真要问什么的少,不显示
|
|
94
|
+
if (!line || /^none\.?$/i.test(line) || /[??]$/.test(line)) return undefined;
|
|
92
95
|
return line.length > 300 ? `${line.slice(0, 299)}…` : line;
|
|
93
96
|
}
|
|
94
97
|
|
|
@@ -135,7 +138,7 @@ export default definePlugin({
|
|
|
135
138
|
...(await readState(file)),
|
|
136
139
|
};
|
|
137
140
|
const models = ctx.require<Models>("models@1");
|
|
138
|
-
const describe = () => `suggestions are ${settings.enabled ? "on" : "off"}, predicted by ${settings.model ? `the
|
|
141
|
+
const describe = () => `suggestions are ${settings.enabled ? "on" : "off"}, predicted by ${settings.model ? `the model ${settings.model}` : "the session's model"}`;
|
|
139
142
|
const update = async (next: Partial<Settings>) => {
|
|
140
143
|
settings = { ...settings, ...next };
|
|
141
144
|
for (const fn of changed) fn();
|
|
@@ -153,7 +156,9 @@ export default definePlugin({
|
|
|
153
156
|
const [sub = "", ...rest] = args.trim().split(/\s+/);
|
|
154
157
|
if (sub === "on" || sub === "off") return update({ enabled: sub === "on" });
|
|
155
158
|
if (sub === "model") {
|
|
156
|
-
|
|
159
|
+
// 能选的:/model 保存过的,加上当前服务提供的(不用先在 /model 里保存)
|
|
160
|
+
const [saved, listed] = await Promise.all([models.saved?.() ?? ([] as string[]), models.list().catch((): string[] => [])]);
|
|
161
|
+
const names = [...new Set([...saved, ...listed])];
|
|
157
162
|
let name: string | undefined = rest.join(" ");
|
|
158
163
|
if (!name) {
|
|
159
164
|
const SESSION = "\0session";
|
|
@@ -162,15 +167,15 @@ export default definePlugin({
|
|
|
162
167
|
title: "Which model predicts your next message?",
|
|
163
168
|
options: [
|
|
164
169
|
{ label: "The session's model", value: SESSION },
|
|
165
|
-
...
|
|
170
|
+
...names.map((m) => ({ label: m, value: m, ...(m === settings.model ? { hint: "current" } : saved.includes(m) ? { hint: "saved" } : {}) })),
|
|
166
171
|
],
|
|
167
172
|
},
|
|
168
173
|
c.signal,
|
|
169
174
|
);
|
|
170
175
|
if (picked === undefined) return;
|
|
171
176
|
name = picked === SESSION ? undefined : picked;
|
|
172
|
-
} else if (models.saved && !
|
|
173
|
-
return `${name} is not a model saved by /model. ${
|
|
177
|
+
} else if (models.saved && !names.includes(name)) {
|
|
178
|
+
return `${name} is not a model saved by /model or offered by the current service. ${names.length ? `Available: ${names.join(", ")}.` : "Add one with /model first."}`;
|
|
174
179
|
}
|
|
175
180
|
return update({ model: name });
|
|
176
181
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"model": {
|
|
14
14
|
"default": "",
|
|
15
|
-
"description": "the model that predicts
|
|
15
|
+
"description": "the model that predicts: a name saved with /model or a model of the current service; empty uses the session's model; /suggest model overrides it"
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
package/plugins/task/index.ts
CHANGED
|
@@ -4,23 +4,11 @@
|
|
|
4
4
|
// 登记随登记者的作用域撤销。主会话里的工具对象是各插件私有的,子 Agent 拿到的是登记者另给的一份。
|
|
5
5
|
|
|
6
6
|
import type { Tool, Usage } from "uncarved";
|
|
7
|
-
import { definePlugin, type UI } from "
|
|
8
|
-
import type { Approval } from "
|
|
9
|
-
import type { Models } from "../models/index.ts";
|
|
10
|
-
import type { Renderers } from "../renderers/index.ts";
|
|
7
|
+
import { definePlugin, type UI } from "@uncarved/jade-api";
|
|
8
|
+
import type { Approval, Models, Prompts, Renderers, Task } from "@uncarved/jade-api/services";
|
|
11
9
|
import { taskTool, type ApproveSubagent, type TaskProgress } from "./subagent.ts";
|
|
12
10
|
import { clip, dim, red } from "./style.ts";
|
|
13
11
|
|
|
14
|
-
/** task@1 */
|
|
15
|
-
export interface Task {
|
|
16
|
-
/**
|
|
17
|
-
* 给子 Agent 登记一个只读工具(effect 必须是 "read"),返回撤销函数;登记者的作用域关闭时自动撤销。
|
|
18
|
-
* 工具名已被登记时抛错。要求批准的情形(工作目录之外的路径、url 参数)由子 Agent 自己判断,经 ui@1 问用户。
|
|
19
|
-
* opts.when:每次启动子 Agent 时调用,返回 false 时这次不给它这个工具(例如没有配置搜索服务时的 web_search)
|
|
20
|
-
*/
|
|
21
|
-
tool(tool: Tool, opts?: { when?: () => boolean }): () => void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
12
|
const DEFAULT_MAX_STEPS = 40;
|
|
25
13
|
const MAX_DETAIL_LINES = 40;
|
|
26
14
|
|
|
@@ -51,7 +39,6 @@ export default definePlugin({
|
|
|
51
39
|
ctx.provide("task@1", (caller): Task => ({
|
|
52
40
|
tool(tool, opts) {
|
|
53
41
|
if (typeof tool?.name !== "string" || typeof tool.execute !== "function") throw new Error("task.tool: a tool needs a name and execute");
|
|
54
|
-
if (tool.effect !== "read") throw new Error(`task.tool: ${tool.name} is not read-only (effect ${JSON.stringify(tool.effect)}); sub-agents only get read-only tools`);
|
|
55
42
|
// 同一个插件重复登记是正常的:换会话时新会话先登记,旧会话随后撤销它的那份;取最后登记的
|
|
56
43
|
const taken = registry.find((r) => r.tool.name === tool.name && r.plugin !== caller.plugin);
|
|
57
44
|
if (taken) throw new Error(`task.tool: ${tool.name} is already registered by ${taken.plugin}`);
|
|
@@ -117,6 +104,8 @@ export default definePlugin({
|
|
|
117
104
|
const usage = new Map<string, Usage>();
|
|
118
105
|
const configured = ctx.config.maxSteps;
|
|
119
106
|
const maxSteps = typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_MAX_STEPS;
|
|
107
|
+
// 子 Agent 用的模型:/model 保存过的名字,或当前服务上的另一个模型;不设时用会话的模型
|
|
108
|
+
const model = typeof ctx.config.model === "string" && ctx.config.model ? ctx.config.model : undefined;
|
|
120
109
|
const approve: ApproveSubagent = (call, signal) => {
|
|
121
110
|
const ui = ctx.service<UI>("ui@1");
|
|
122
111
|
if (!ui?.interactive) return Promise.resolve({ approved: false, reason: "Nobody can approve this action for a sub-agent. Report what you need instead." });
|
|
@@ -140,11 +129,13 @@ export default definePlugin({
|
|
|
140
129
|
ctx.kernel.tool(
|
|
141
130
|
taskTool({
|
|
142
131
|
cwd: ctx.cwd,
|
|
143
|
-
provider: { id: ctx.plugin, complete: (req, o) => models.complete(req, o) },
|
|
132
|
+
provider: { id: ctx.plugin, complete: (req, o) => models.complete(req, model ? { ...o, model } : o) },
|
|
144
133
|
tools: available,
|
|
145
134
|
maxSteps,
|
|
146
135
|
approve,
|
|
147
136
|
allowed: (call) => ctx.service<Approval>("approval@1")?.allows(ctx.session.id, call) ?? false,
|
|
137
|
+
// 用到的时候再取:prompts@1 的提供者在自己的 session() 里才读指令文件,可能排在本插件后面
|
|
138
|
+
...(ctx.config.instructions === false ? {} : { instructions: () => ctx.service<Prompts>("prompts@1")?.instructions?.(ctx.session.id) ?? [] }),
|
|
148
139
|
id: ctx.plugin,
|
|
149
140
|
usage: (toolUseId, u) => void usage.set(toolUseId, u),
|
|
150
141
|
contextWindow: () => models.current()?.contextWindow,
|