@uncarved/jade 0.1.1 → 0.1.3
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 +18 -6
- package/bin/jade.js +23 -0
- package/dist/commands.d.ts +20 -0
- package/dist/commands.js +20 -0
- package/dist/commands.js.map +1 -1
- package/dist/distro.d.ts +51 -7
- package/dist/distro.js +199 -48
- package/dist/distro.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/main.js +479 -303
- package/dist/main.js.map +1 -1
- package/dist/mcp.js +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/plugin-cli.d.ts +1 -1
- package/dist/plugin-cli.js +79 -36
- package/dist/plugin-cli.js.map +1 -1
- package/dist/plugins/budget.d.ts +2 -2
- package/dist/plugins/budget.js +2 -2
- package/dist/plugins/budget.js.map +1 -1
- package/dist/plugins/builtins.js +6 -3
- package/dist/plugins/builtins.js.map +1 -1
- package/dist/plugins/checks.d.ts +2 -1
- package/dist/plugins/checks.js +25 -5
- package/dist/plugins/checks.js.map +1 -1
- package/dist/plugins/compact.js +45 -1
- package/dist/plugins/compact.js.map +1 -1
- package/dist/plugins/core.d.ts +5 -0
- package/dist/plugins/core.js +39 -0
- package/dist/plugins/core.js.map +1 -1
- package/dist/plugins/host.d.ts +52 -0
- package/dist/plugins/host.js +115 -0
- package/dist/plugins/host.js.map +1 -0
- package/dist/plugins/install.d.ts +1 -1
- package/dist/plugins/loader.d.ts +238 -10
- package/dist/plugins/loader.js +175 -21
- package/dist/plugins/loader.js.map +1 -1
- package/dist/plugins/policy.d.ts +23 -5
- package/dist/plugins/policy.js +63 -10
- package/dist/plugins/policy.js.map +1 -1
- package/dist/plugins/prompts.d.ts +14 -1
- package/dist/plugins/prompts.js +118 -16
- package/dist/plugins/prompts.js.map +1 -1
- package/dist/plugins/repeats.d.ts +7 -0
- package/dist/plugins/repeats.js +74 -13
- package/dist/plugins/repeats.js.map +1 -1
- package/dist/plugins/review.d.ts +18 -0
- package/dist/plugins/review.js +130 -0
- package/dist/plugins/review.js.map +1 -0
- package/dist/plugins/sessions.d.ts +7 -0
- package/dist/plugins/sessions.js +110 -0
- package/dist/plugins/sessions.js.map +1 -0
- package/dist/provider.d.ts +57 -3
- package/dist/provider.js +80 -10
- package/dist/provider.js.map +1 -1
- package/dist/session-lifecycle.d.ts +61 -0
- package/dist/session-lifecycle.js +167 -0
- package/dist/session-lifecycle.js.map +1 -0
- package/dist/session-scope.d.ts +53 -0
- package/dist/session-scope.js +116 -0
- package/dist/session-scope.js.map +1 -0
- package/dist/sessions.d.ts +6 -0
- package/dist/sessions.js +20 -0
- package/dist/sessions.js.map +1 -1
- package/dist/sys.d.ts +4 -1
- package/dist/sys.js +18 -1
- package/dist/sys.js.map +1 -1
- package/dist/tools/ask.d.ts +11 -0
- package/dist/tools/ask.js +62 -0
- package/dist/tools/ask.js.map +1 -0
- package/dist/tools/fs.d.ts +4 -0
- package/dist/tools/fs.js +53 -12
- package/dist/tools/fs.js.map +1 -1
- package/dist/tools/grep.js +3 -2
- package/dist/tools/grep.js.map +1 -1
- package/dist/tools/shell.js +5 -1
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/task.d.ts +10 -2
- package/dist/tools/task.js +40 -9
- package/dist/tools/task.js.map +1 -1
- package/dist/tools/web.d.ts +33 -3
- package/dist/tools/web.js +351 -143
- package/dist/tools/web.js.map +1 -1
- package/dist/ui/configure.js +144 -66
- package/dist/ui/configure.js.map +1 -1
- package/dist/ui/diff.d.ts +1 -1
- package/dist/ui/diff.js +1 -2
- package/dist/ui/diff.js.map +1 -1
- package/dist/ui/editor.d.ts +8 -0
- package/dist/ui/editor.js +50 -1
- package/dist/ui/editor.js.map +1 -1
- package/dist/ui/markdown.d.ts +22 -0
- package/dist/ui/markdown.js +242 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/ui/render.d.ts +9 -8
- package/dist/ui/render.js +35 -62
- package/dist/ui/render.js.map +1 -1
- package/dist/ui/renderers.d.ts +8 -0
- package/dist/ui/renderers.js +169 -0
- package/dist/ui/renderers.js.map +1 -0
- package/dist/ui/screen.d.ts +25 -2
- package/dist/ui/screen.js +104 -12
- package/dist/ui/screen.js.map +1 -1
- package/dist/ui/transcript.d.ts +13 -0
- package/dist/ui/transcript.js +157 -31
- package/dist/ui/transcript.js.map +1 -1
- package/dist/ui/tui.d.ts +2 -0
- package/dist/ui/tui.js +383 -81
- package/dist/ui/tui.js.map +1 -1
- package/dist/update.d.ts +53 -0
- package/dist/update.js +255 -0
- package/dist/update.js.map +1 -0
- package/package.json +7 -6
- package/src/commands.ts +24 -0
- package/src/distro.ts +234 -52
- package/src/index.ts +3 -0
- package/src/main.ts +459 -300
- package/src/mcp.ts +1 -1
- package/src/plugin-cli.ts +73 -34
- package/src/plugins/budget.ts +4 -4
- package/src/plugins/builtins.ts +6 -3
- package/src/plugins/checks.ts +25 -6
- package/src/plugins/compact.ts +40 -1
- package/src/plugins/core.ts +40 -0
- package/src/plugins/host.ts +146 -0
- package/src/plugins/install.ts +1 -1
- package/src/plugins/loader.ts +379 -23
- package/src/plugins/policy.ts +70 -13
- package/src/plugins/prompts.ts +128 -16
- package/src/plugins/repeats.ts +75 -14
- package/src/plugins/review.ts +146 -0
- package/src/plugins/sessions.ts +109 -0
- package/src/provider.ts +117 -14
- package/src/session-lifecycle.ts +194 -0
- package/src/session-scope.ts +135 -0
- package/src/sessions.ts +17 -0
- package/src/sys.ts +18 -1
- package/src/tools/ask.ts +72 -0
- package/src/tools/fs.ts +53 -12
- package/src/tools/grep.ts +3 -2
- package/src/tools/shell.ts +5 -1
- package/src/tools/task.ts +56 -12
- package/src/tools/web.ts +370 -140
- package/src/ui/configure.ts +141 -67
- package/src/ui/diff.ts +1 -2
- package/src/ui/editor.ts +50 -1
- package/src/ui/markdown.ts +258 -0
- package/src/ui/render.ts +35 -48
- package/src/ui/renderers.ts +183 -0
- package/src/ui/screen.ts +113 -16
- package/src/ui/transcript.ts +164 -35
- package/src/ui/tui.tsx +424 -79
- package/src/update.ts +262 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uncarved/jade",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A coding agent harness built on the uncarved kernel",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,16 +42,17 @@
|
|
|
42
42
|
"prepublishOnly": "node ../../scripts/require-bun-publish.mjs && bun run build"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@uncarved/plugin-stdio": "0.
|
|
46
|
-
"@uncarved/provider-anthropic": "0.1.
|
|
47
|
-
"@uncarved/provider-openai-compat": "0.1.
|
|
48
|
-
"@uncarved/provider-openai-responses": "0.1.
|
|
45
|
+
"@uncarved/plugin-stdio": "0.2.0",
|
|
46
|
+
"@uncarved/provider-anthropic": "0.1.2",
|
|
47
|
+
"@uncarved/provider-openai-compat": "0.1.4",
|
|
48
|
+
"@uncarved/provider-openai-responses": "0.1.4",
|
|
49
49
|
"@uncarved/store-jsonl": "0.1.0",
|
|
50
|
+
"htmlparser2": "^10.0.0",
|
|
50
51
|
"ink": "7.1.1",
|
|
51
52
|
"picomatch": "^4.0.3",
|
|
52
53
|
"react": "^19.2.0",
|
|
53
54
|
"string-width": "^8.2.0",
|
|
54
|
-
"uncarved": "0.1.
|
|
55
|
+
"uncarved": "0.1.3",
|
|
55
56
|
"wrap-ansi": "^10.0.2"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
package/src/commands.ts
CHANGED
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
import { readdir, readFile } from "node:fs/promises";
|
|
15
15
|
import path from "node:path";
|
|
16
|
+
import type { Jade } from "./distro.ts";
|
|
17
|
+
import type { CommandInfo } from "./ui/screen.ts";
|
|
16
18
|
|
|
17
19
|
export interface CustomCommand {
|
|
18
20
|
name: string;
|
|
@@ -118,3 +120,25 @@ export function projectDirs(root: string, cwd: string): string[] {
|
|
|
118
120
|
if (rel) for (const seg of rel.split(path.sep)) dirs.push(path.join(dirs.at(-1)!, seg));
|
|
119
121
|
return dirs;
|
|
120
122
|
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 斜杠命令同名时谁生效:宿主命令 > 内置插件的命令 > 自定义命令和 skill > 第三方插件(第三方之间先到先得)。
|
|
126
|
+
* 内置插件和第三方插件之间的先后由 createJade 定(jade.commands 里内置插件优先;内置插件被代替或停用时,第三方插件可以用它的命令名);
|
|
127
|
+
* 这里再让第三方插件给宿主命令、自定义命令和 skill 让位。返回菜单里内置插件的和第三方插件的命令,以及被忽略的命令的警告
|
|
128
|
+
*/
|
|
129
|
+
export function pluginMenu(
|
|
130
|
+
commands: Jade["commands"],
|
|
131
|
+
taken: { host: Set<string>; custom: { has(name: string): boolean }; skill: { has(name: string): boolean } },
|
|
132
|
+
): { builtin: CommandInfo[]; plugins: CommandInfo[]; warnings: string[] } {
|
|
133
|
+
const out = { builtin: [] as CommandInfo[], plugins: [] as CommandInfo[], warnings: [] as string[] };
|
|
134
|
+
for (const [name, { plugin, command: c, builtin }] of commands) {
|
|
135
|
+
if (builtin) {
|
|
136
|
+
out.builtin.push({ name: c.name, args: c.args, about: c.description ?? "" });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const what = taken.host.has(name) ? "a built-in command" : taken.custom.has(name) ? "a custom command" : taken.skill.has(name) ? "a skill" : undefined;
|
|
140
|
+
if (what) out.warnings.push(`command /${c.name} of plugin ${plugin} is ignored: ${what} has that name`);
|
|
141
|
+
else out.plugins.push({ name: c.name, args: c.args, about: `${c.description ?? ""} (plugin ${plugin})`.trim() });
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
144
|
+
}
|
package/src/distro.ts
CHANGED
|
@@ -1,32 +1,39 @@
|
|
|
1
1
|
// 组装发行版:内核之外的功能都是插件。内置插件(见 plugins/builtins.ts)和第三方插件用同一套接口,
|
|
2
2
|
// 在这里拼成一份插件清单。宿主(main.ts)和测试都通过这里创建,内核本身不知道这些插件的存在。
|
|
3
3
|
//
|
|
4
|
-
// 用户可以停用内置插件($JADE_HOME/plugins.json
|
|
4
|
+
// 用户可以停用内置插件($JADE_HOME/plugins.json),第三方插件可以在 plugin.json 里用 replaces 代替内置插件;jade/policy 两者都不行。
|
|
5
5
|
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { checkCompat, definePlugin, type LogStore, type ModelRequest, type Plugin, type Provider, type Tool } from "uncarved";
|
|
7
|
+
import { checkCompat, definePlugin, subsetPlugin, type LogStore, type ModelRequest, type Plugin, type Provider, type Tool } from "uncarved";
|
|
8
8
|
import { budget } from "./plugins/budget.ts";
|
|
9
9
|
import { BUILTINS, BUILTIN_IDS, REQUIRED_IDS } from "./plugins/builtins.ts";
|
|
10
10
|
import { checks as checksPlugin, type ApproveCheck, type Check, type Checks } from "./plugins/checks.ts";
|
|
11
|
-
import { checksCommand, compactCommand, mcpCommand, mcpInstructions, memoryCommand, skillsCommand, withCounter, withSystem } from "./plugins/core.ts";
|
|
11
|
+
import { checksCommand, compactCommand, mcpCommand, mcpInstructions, memoryCommand, searchCommand, skillsCommand, withCounter, withSystem } from "./plugins/core.ts";
|
|
12
12
|
import { Memory, memoryTool } from "./memory.ts";
|
|
13
13
|
import { mcpTools, type McpClient } from "./mcp.ts";
|
|
14
14
|
import { skillTool, skillsPrompt, type Skill } from "./skills.ts";
|
|
15
15
|
import { compactor, type Compactor } from "./plugins/compact.ts";
|
|
16
|
-
import { COMMAND_NAME, JADE_VERSION, type HostContext, type JadePlugin, type LoadedPlugin, type PluginCommand } from "./plugins/loader.ts";
|
|
17
|
-
import { policy, type AllowRule, type Mode, type Policy } from "./plugins/policy.ts";
|
|
16
|
+
import { COMMAND_NAME, DISPOSE_TIMEOUT_MS, JADE_VERSION, KEY_SPEC, RESERVED_KEYS, type HostContext, type HostInput, type PluginKey, type ToolRenderer, type JadePlugin, type LoadedPlugin, type PluginCommand } from "./plugins/loader.ts";
|
|
17
|
+
import { policy, type AllowRule, type Mode, type Policy, type PolicyOptions } from "./plugins/policy.ts";
|
|
18
18
|
import { prompts, realPath, repoRoot } from "./plugins/prompts.ts";
|
|
19
19
|
import { repeats } from "./plugins/repeats.ts";
|
|
20
|
+
import { sessionsPlugin, undoPlugin } from "./plugins/sessions.ts";
|
|
20
21
|
import { fsTools } from "./tools/fs.ts";
|
|
21
22
|
import { Checkpoints } from "./tools/checkpoint.ts";
|
|
22
23
|
import { shellTools } from "./tools/shell.ts";
|
|
23
|
-
import { taskTool, type ApproveSubagent } from "./tools/task.ts";
|
|
24
|
+
import { taskTool, type ApproveSubagent, type SubagentControl } from "./tools/task.ts";
|
|
24
25
|
import { todoTool } from "./tools/todo.ts";
|
|
26
|
+
import { askUserTool, type AskUser } from "./tools/ask.ts";
|
|
25
27
|
import { webTools } from "./tools/web.ts";
|
|
26
28
|
import { screenshotTool } from "./tools/screenshot.ts";
|
|
29
|
+
import { askRenderers, fsRenderers, memoryRenderers, shellRenderers, taskRenderers, todoRenderers, webRenderers } from "./ui/renderers.ts";
|
|
27
30
|
import { visionFromEnv } from "./provider.ts";
|
|
28
31
|
|
|
29
32
|
const READ_ONLY = new Set(["read_file", "list_dir", "glob", "grep"]);
|
|
33
|
+
/** 子 Agent 也执行的第三方插件 hook */
|
|
34
|
+
const TOOL_HOOKS: ReadonlySet<string> = new Set(["tool.gate", "tool.before", "tool.after"]);
|
|
35
|
+
/** 子 Agent 一轮最多调用模型的次数(子 Agent 的提示词里写的是同一个数) */
|
|
36
|
+
const SUBAGENT_STEPS = 40;
|
|
30
37
|
|
|
31
38
|
export interface JadeOptions {
|
|
32
39
|
cwd: string;
|
|
@@ -39,11 +46,15 @@ export interface JadeOptions {
|
|
|
39
46
|
projectPlugins?: Plugin[];
|
|
40
47
|
/** 用 loadPlugin 加载的第三方插件(用户层和项目层),每次 createJade 创建一套新实例 */
|
|
41
48
|
extensions?: LoadedPlugin[];
|
|
42
|
-
/**
|
|
49
|
+
/** 停用的内置插件的 id(第三方插件由宿主在加载前按 id 筛掉,见 resolvePlugins) */
|
|
43
50
|
disabled?: Iterable<string>;
|
|
44
51
|
/** 压缩阈值;传函数时每次投影前取值 */
|
|
45
52
|
compactTokens?: number | (() => number);
|
|
46
53
|
maxSteps?: number;
|
|
54
|
+
/** 当前配置的模型,写进主 Agent 的系统提示词(见 prompts 的 model);每次请求时取 */
|
|
55
|
+
model?: () => { name: string; via: string } | undefined;
|
|
56
|
+
/** 会话的临时目录:写进提示词让模型把临时文件放这里;关卡按工作目录对待,修改前不用先读 */
|
|
57
|
+
scratch?: string;
|
|
47
58
|
/** 测试用 */
|
|
48
59
|
today?: string;
|
|
49
60
|
/** 读取搜索服务配置用,默认 process.env;测试用 */
|
|
@@ -54,12 +65,16 @@ export interface JadeOptions {
|
|
|
54
65
|
lookup?: (hostname: string) => Promise<string[]>;
|
|
55
66
|
/** 截图用的浏览器;不给时按 JADE_BROWSER 和常见安装位置找,null 表示不提供截图工具 */
|
|
56
67
|
browser?: string | null;
|
|
68
|
+
/** ask_user 工具向用户提问;不给就不提供这个工具 */
|
|
69
|
+
askUser?: AskUser;
|
|
57
70
|
/** 子 Agent 要用户批准的调用(例如 web_fetch)交给宿主;不给就拒绝 */
|
|
58
71
|
approveSubagent?: ApproveSubagent;
|
|
59
72
|
/** 子 Agent 也遵守的"总是允许"规则(主会话的),每次判断时取 */
|
|
60
73
|
sharedRules?: () => AllowRule[];
|
|
61
74
|
/** 运行中切换、还没记进日志的权限模式(见 PolicyOptions.pendingMode) */
|
|
62
75
|
pendingMode?: () => Mode | undefined;
|
|
76
|
+
/** auto 模式下审查规则判断不了的调用(见 PolicyOptions.review);不给时 auto 模式不审查 */
|
|
77
|
+
review?: PolicyOptions["review"];
|
|
63
78
|
/**
|
|
64
79
|
* 编辑后检查的命令第一次运行前由宿主确认;不给就不做编辑后检查。
|
|
65
80
|
* 检查会执行仓库里的代码,所以不能默认放行
|
|
@@ -73,6 +88,14 @@ export interface JadeOptions {
|
|
|
73
88
|
mcp?: McpClient[];
|
|
74
89
|
/** loadSkills 找到的 skill */
|
|
75
90
|
skills?: Skill[];
|
|
91
|
+
/** 插件用 ctx.status 设置状态栏上自己的那一段;plugin 是插件的 id,text 为 undefined 时去掉 */
|
|
92
|
+
onStatus?(plugin: string, text: string | undefined): void;
|
|
93
|
+
/** 终端界面的输入框,给用户层插件的 ctx.input(多一个参数:调用的插件的 id);-p 时没有 */
|
|
94
|
+
input?: HostInput;
|
|
95
|
+
/** 用户层插件的 ctx.send:替用户提交一行;plugin 是插件的 id。-p 时没有 */
|
|
96
|
+
send?(plugin: string, text: string): void;
|
|
97
|
+
/** 插件的 ctx.signal:这套实例的会话结束时中止(见 SessionScope);不给时永不中止 */
|
|
98
|
+
signal?: AbortSignal;
|
|
76
99
|
}
|
|
77
100
|
|
|
78
101
|
export interface BuiltinState {
|
|
@@ -99,17 +122,39 @@ export interface Jade {
|
|
|
99
122
|
/** 每个内置插件的状态 */
|
|
100
123
|
builtins: BuiltinState[];
|
|
101
124
|
/** 成功加入本会话的第三方插件实例 */
|
|
102
|
-
extensions:
|
|
125
|
+
extensions: Extension[];
|
|
103
126
|
/** 插件(内置的和第三方的)提供的斜杠命令,按小写的名字 */
|
|
104
127
|
commands: Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>;
|
|
128
|
+
/** 第三方插件为自己的工具注册的显示方式,按工具名 */
|
|
129
|
+
renderers: Map<string, { plugin: string; renderer: ToolRenderer }>;
|
|
130
|
+
/** 第三方插件的快捷键,按 KEY_SPEC 的写法(小写) */
|
|
131
|
+
keys: Map<string, { plugin: string; key: PluginKey }>;
|
|
105
132
|
/** 主会话的工具;宿主用 read_file / list_dir 读取 @ 引用的文件 */
|
|
106
133
|
tools: Tool[];
|
|
134
|
+
/**
|
|
135
|
+
* 不再用这套实例时调用(在 shutdown 和会话收尾之后):调用第三方插件的 dispose,同时进行、各自限时。
|
|
136
|
+
* 只执行一次;返回要告诉用户的问题
|
|
137
|
+
*/
|
|
138
|
+
dispose(): Promise<string[]>;
|
|
107
139
|
/** 宿主退出时调用:杀掉后台 shell */
|
|
108
140
|
shutdown(): void;
|
|
109
141
|
/** 启动时要告诉用户的问题,例如找不到 shell */
|
|
110
142
|
warnings: string[];
|
|
111
143
|
}
|
|
112
144
|
|
|
145
|
+
/**
|
|
146
|
+
* 加入本会话的一个第三方插件实例,和 jade 从它上面检查过、留下的扩展点。jade 只用这里的,不改写实例:
|
|
147
|
+
* 进程外插件的实例是在会话之间共用的进程对象(它的快捷键和命令每套单独生成,见 LoadedPlugin.adapters),
|
|
148
|
+
* 项目层插件的实例是内核认的那个对象(宪法 7.1)。不合格的扩展点不在这里,并且已经给出警告
|
|
149
|
+
*/
|
|
150
|
+
export interface Extension {
|
|
151
|
+
source: LoadedPlugin;
|
|
152
|
+
plugin: JadePlugin;
|
|
153
|
+
commands: PluginCommand[];
|
|
154
|
+
keys: PluginKey[];
|
|
155
|
+
renderers: ToolRenderer[];
|
|
156
|
+
}
|
|
157
|
+
|
|
113
158
|
export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
114
159
|
const { cwd, store, provider } = opts;
|
|
115
160
|
const skills = opts.skills ?? [];
|
|
@@ -129,24 +174,24 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
129
174
|
// run 也给插件和编辑后检查用,所以 jade/shell 停用时也创建,只是不把工具交给模型
|
|
130
175
|
const shell = shellTools({ cwd });
|
|
131
176
|
const root = await repoRoot(cwd);
|
|
132
|
-
const host: HostContext = { jade: JADE_VERSION, cwd: realPath(cwd), root: realPath(root), home: opts.home, definePlugin, run: shell.run };
|
|
177
|
+
const host: HostContext = { jade: JADE_VERSION, cwd: realPath(cwd), root: realPath(root), home: opts.home, definePlugin, run: shell.run, complete: completer(provider), status: (plugin, text) => opts.onStatus?.(plugin, text), checkpoints, input: opts.input, send: opts.send, signal: opts.signal ?? new AbortController().signal };
|
|
133
178
|
|
|
134
179
|
// 第三方插件先创建:要先知道它们代替哪些内置插件
|
|
135
|
-
const made = await createExtensions(opts.extensions ?? [], host,
|
|
180
|
+
const made = await createExtensions(opts.extensions ?? [], host, warnings);
|
|
136
181
|
|
|
137
182
|
// ---------- 内置插件(jade/prompts 最后创建:它要知道最终有哪些工具) ----------
|
|
138
183
|
const built = new Map<string, JadePlugin>();
|
|
139
184
|
const add = (p: JadePlugin) => built.set(p.id, p);
|
|
140
185
|
|
|
141
|
-
const pol = policy({ cwd, mode: opts.mode, pendingMode: opts.pendingMode, readRoots: off("jade/skills") ? [] : skills.map((x) => x.dir) });
|
|
186
|
+
const pol = policy({ cwd, mode: opts.mode, pendingMode: opts.pendingMode, review: opts.review, readRoots: off("jade/skills") ? [] : skills.map((x) => x.dir), scratch: opts.scratch });
|
|
142
187
|
add(pol.plugin);
|
|
143
188
|
// 占位,组装完成后换成真正的提示词插件
|
|
144
189
|
if (!off("jade/prompts")) add({ id: "jade/prompts", version: "0.3.0", kernel: "^0.1" });
|
|
145
190
|
|
|
146
191
|
// 文件工具据此判断读取和修改是不是同一次回复里发出的
|
|
147
192
|
const responses = { calls: 0 };
|
|
148
|
-
if (!off("jade/fs")) add(withCounter({ id: "jade/fs", version: "0.1.0", kernel: "^0.1", tools: fsTools(cwd, { checkpoints, responses }) }, responses));
|
|
149
|
-
if (!off("jade/shell")) add({ id: "jade/shell", version: "0.1.0", kernel: "^0.1", tools: shell.tools });
|
|
193
|
+
if (!off("jade/fs")) add(withCounter({ id: "jade/fs", version: "0.1.0", kernel: "^0.1", tools: fsTools(cwd, { checkpoints, responses, scratch: opts.scratch }), renderers: fsRenderers(cwd) }, responses));
|
|
194
|
+
if (!off("jade/shell")) add({ id: "jade/shell", version: "0.1.0", kernel: "^0.1", tools: shell.tools, renderers: shellRenderers });
|
|
150
195
|
let web: Tool[] = [];
|
|
151
196
|
let hasScreenshot = false;
|
|
152
197
|
if (!off("jade/web")) {
|
|
@@ -172,6 +217,8 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
172
217
|
version: "0.2.0",
|
|
173
218
|
kernel: "^0.1",
|
|
174
219
|
tools: shot ? [...web, shot] : web,
|
|
220
|
+
renderers: webRenderers,
|
|
221
|
+
commands: [searchCommand({ envFile: path.join(opts.home, ".env"), env: opts.env })],
|
|
175
222
|
...(shot
|
|
176
223
|
? {
|
|
177
224
|
needs: ["transform:context.build"],
|
|
@@ -186,22 +233,30 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
186
233
|
: {}),
|
|
187
234
|
});
|
|
188
235
|
}
|
|
189
|
-
if (!off("jade/todo")) add({ id: "jade/todo", version: "0.1.0", kernel: "^0.1", tools: [todoTool()] });
|
|
236
|
+
if (!off("jade/todo")) add({ id: "jade/todo", version: "0.1.0", kernel: "^0.1", tools: [todoTool()], renderers: todoRenderers });
|
|
237
|
+
if (!off("jade/ask") && opts.askUser) add({ id: "jade/ask", version: "0.1.0", kernel: "^0.1", tools: [askUserTool(opts.askUser)], renderers: askRenderers });
|
|
190
238
|
|
|
191
239
|
let memory: Memory | undefined;
|
|
192
240
|
if (!off("jade/memory")) {
|
|
193
241
|
memory = new Memory(opts.home, root);
|
|
194
242
|
const text = await memory.prompt();
|
|
195
|
-
add(withSystem({ id: "jade/memory", version: "0.1.0", kernel: "^0.1", tools: [memoryTool(memory)], commands: [memoryCommand(memory)] }, text ? [{ text, trust: "trusted" }] : []));
|
|
243
|
+
add(withSystem({ id: "jade/memory", version: "0.1.0", kernel: "^0.1", tools: [memoryTool(memory)], commands: [memoryCommand(memory)], renderers: memoryRenderers }, text ? [{ text, trust: "trusted" }] : []));
|
|
196
244
|
}
|
|
197
245
|
|
|
198
246
|
/** 最终加载了的内置插件,子 Agent 据此决定给哪些工具;组装完成后才填上 */
|
|
199
247
|
const kept = new Set<string>();
|
|
200
248
|
/** 子 Agent 的提示词,组装完成后生成 */
|
|
201
249
|
const subSystem: { plugin?: Plugin } = {};
|
|
250
|
+
/** 第三方插件(项目层和用户层),组装完成后填上 */
|
|
251
|
+
let thirdParty: Plugin[] = [];
|
|
202
252
|
if (!off("jade/task")) {
|
|
203
|
-
const subagentPlugins = subagent(opts, subSystem, () => ({
|
|
204
|
-
|
|
253
|
+
const subagentPlugins = subagent(opts, subSystem, () => ({
|
|
254
|
+
fs: kept.has("jade/fs"),
|
|
255
|
+
web: kept.has("jade/web") ? web : [],
|
|
256
|
+
mcp: kept.has("jade/mcp") ? mcp : [],
|
|
257
|
+
extensions: thirdParty,
|
|
258
|
+
}));
|
|
259
|
+
add({ id: "jade/task", version: "0.1.0", kernel: "^0.1", tools: [taskTool({ store, provider, plugins: subagentPlugins, approve: opts.approveSubagent })], renderers: taskRenderers });
|
|
205
260
|
}
|
|
206
261
|
|
|
207
262
|
if (!off("jade/skills")) {
|
|
@@ -240,31 +295,41 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
240
295
|
add({ ...compact.plugin, commands: [compactCommand(compact)] });
|
|
241
296
|
}
|
|
242
297
|
if (!off("jade/budget")) add(budget({ maxSteps: opts.maxSteps }));
|
|
298
|
+
if (!off("jade/sessions")) add(sessionsPlugin());
|
|
299
|
+
if (!off("jade/undo")) add(undoPlugin(host));
|
|
243
300
|
if (!off("jade/repeats")) {
|
|
244
301
|
// 自己数回复次数:不依赖 jade/fs 是否加载
|
|
245
302
|
const own = { calls: 0 };
|
|
246
|
-
add(withCounter(repeats({ responses: own }), own));
|
|
303
|
+
add(withCounter(repeats({ responses: own, cwd }), own));
|
|
247
304
|
}
|
|
248
305
|
|
|
249
306
|
// ---------- 代替关系:被代替的内置插件让位,代替者的工具名可以和它重复 ----------
|
|
250
|
-
|
|
307
|
+
// 代替关系写在清单里(plugin.json 的 replaces),不看实例
|
|
308
|
+
const claims = (m: Extension) => (m.source.info.replaces ?? []).filter((id) => BUILTIN_IDS.has(id) && !REQUIRED_IDS.has(id) && built.has(id));
|
|
251
309
|
for (const { source, plugin } of made) {
|
|
252
|
-
for (const id of
|
|
310
|
+
for (const id of source.info.replaces ?? []) {
|
|
253
311
|
if (REQUIRED_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): cannot replace ${id}; add a gate hook to make approvals stricter instead`);
|
|
254
312
|
else if (!BUILTIN_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): replaces unknown built-in plugin ${id}`);
|
|
255
313
|
}
|
|
256
314
|
}
|
|
257
315
|
// 从"全部声明都生效"开始;被拒绝的插件声明的代替撤销,内置插件回来之后可能又拒绝别的插件,直到不再变化
|
|
258
|
-
let replaced = new Set(made.flatMap(
|
|
316
|
+
let replaced = new Set(made.flatMap(claims));
|
|
259
317
|
let result: ReturnType<typeof accept>;
|
|
260
318
|
for (;;) {
|
|
261
319
|
result = accept(made, [...built.values()].filter((p) => !replaced.has(p.id)));
|
|
262
|
-
const next = new Set(result.accepted.flatMap(
|
|
320
|
+
const next = new Set(result.accepted.flatMap(claims));
|
|
263
321
|
if (next.size === replaced.size) break;
|
|
264
322
|
replaced = next;
|
|
265
323
|
}
|
|
266
324
|
warnings.push(...result.rejected);
|
|
267
325
|
const added = result.accepted;
|
|
326
|
+
// 被拒绝的实例不会再用:现在就收尾
|
|
327
|
+
for (const m of made) {
|
|
328
|
+
if (added.includes(m)) continue;
|
|
329
|
+
const w = await disposeInstance(m.source, m.plugin);
|
|
330
|
+
if (w) warnings.push(w);
|
|
331
|
+
}
|
|
332
|
+
let disposing: Promise<string[]> | undefined;
|
|
268
333
|
const builtin = [...built.values()].filter((p) => !replaced.has(p.id));
|
|
269
334
|
for (const p of builtin) kept.add(p.id);
|
|
270
335
|
|
|
@@ -272,6 +337,8 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
272
337
|
const toolNames = new Set(allTools.map((t) => t.name));
|
|
273
338
|
const webNames = kept.has("jade/web") ? web.map((t) => t.name) : [];
|
|
274
339
|
const at = builtin.findIndex((p) => p.id === "jade/prompts");
|
|
340
|
+
// 子 Agent 的提示词和主 Agent 的同时生成:两者都要跑几个 git 命令
|
|
341
|
+
const subPrompts = kept.has("jade/task") ? prompts({ cwd, home: opts.home, role: "subagent", today: opts.today, web: webNames }) : undefined;
|
|
275
342
|
if (at >= 0) {
|
|
276
343
|
builtin[at] = await prompts({
|
|
277
344
|
cwd,
|
|
@@ -282,25 +349,39 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
282
349
|
web: webNames,
|
|
283
350
|
screenshot: hasScreenshot,
|
|
284
351
|
checks: kept.has("jade/checks") && Boolean(checks),
|
|
352
|
+
scratch: opts.scratch,
|
|
285
353
|
tools: toolNames,
|
|
354
|
+
model: opts.model,
|
|
286
355
|
});
|
|
287
356
|
}
|
|
288
|
-
if (
|
|
357
|
+
if (subPrompts) subSystem.plugin = await subPrompts;
|
|
289
358
|
|
|
290
359
|
const builtins: BuiltinState[] = BUILTINS.map((b) => {
|
|
291
360
|
if (kept.has(b.id)) return { ...b, state: "on" as const };
|
|
292
|
-
const by = added.find((a) => claims(a
|
|
361
|
+
const by = added.find((a) => claims(a).includes(b.id))?.plugin.id;
|
|
293
362
|
return by ? { ...b, state: "replaced" as const, by } : { ...b, state: "disabled" as const };
|
|
294
363
|
});
|
|
295
364
|
|
|
296
|
-
|
|
365
|
+
thirdParty = [...(opts.projectPlugins ?? []), ...added.map((a) => a.plugin)];
|
|
366
|
+
const plugins = [...builtin, ...thirdParty];
|
|
297
367
|
const commands = new Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>();
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
368
|
+
const owners = [
|
|
369
|
+
...(builtin as JadePlugin[]).map((p) => ({ id: p.id, commands: p.commands ?? [], builtin: BUILTIN_IDS.has(p.id) })),
|
|
370
|
+
...added.map((a) => ({ id: a.plugin.id, commands: a.commands, builtin: false })),
|
|
371
|
+
];
|
|
372
|
+
for (const p of owners) {
|
|
373
|
+
for (const c of p.commands) {
|
|
301
374
|
const taken = commands.get(c.name.toLowerCase());
|
|
302
375
|
if (taken) warnings.push(`plugin ${p.id}: command /${c.name} is ignored: plugin ${taken.plugin} already provides it`);
|
|
303
|
-
else commands.set(c.name.toLowerCase(), { plugin: p.id, command: c, builtin:
|
|
376
|
+
else commands.set(c.name.toLowerCase(), { plugin: p.id, command: c, builtin: p.builtin });
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const keys = new Map<string, { plugin: string; key: PluginKey }>();
|
|
380
|
+
for (const { plugin, keys: own } of added) {
|
|
381
|
+
for (const k of own) {
|
|
382
|
+
const taken = keys.get(k.key);
|
|
383
|
+
if (taken) warnings.push(`plugin ${plugin.id}: key ${k.key} is ignored: plugin ${taken.plugin} already uses it`);
|
|
384
|
+
else keys.set(k.key, { plugin: plugin.id, key: k });
|
|
304
385
|
}
|
|
305
386
|
}
|
|
306
387
|
if (shell.unavailable && kept.has("jade/shell")) warnings.push(shell.unavailable);
|
|
@@ -314,6 +395,13 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
314
395
|
builtins,
|
|
315
396
|
extensions: added,
|
|
316
397
|
commands,
|
|
398
|
+
keys,
|
|
399
|
+
renderers: new Map(
|
|
400
|
+
[...(builtin as JadePlugin[]).map((p) => ({ id: p.id, renderers: p.renderers ?? [] })), ...added.map((a) => ({ id: a.plugin.id, renderers: a.renderers }))].flatMap((p) =>
|
|
401
|
+
p.renderers.map((r) => [r.tool, { plugin: p.id, renderer: r }] as const),
|
|
402
|
+
),
|
|
403
|
+
),
|
|
404
|
+
dispose: () => (disposing ??= Promise.all(added.map(({ source, plugin }) => disposeInstance(source, plugin))).then((ws) => ws.filter((w): w is string => w !== undefined))),
|
|
317
405
|
tools: allTools,
|
|
318
406
|
shutdown: shell.shutdown,
|
|
319
407
|
warnings,
|
|
@@ -324,48 +412,114 @@ export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
|
324
412
|
* 创建第三方插件的实例。有问题的插件跳过并给出警告,而不是让整个 jade 起不来:工厂出错、内核不兼容、命令格式不对。
|
|
325
413
|
* 只带内容(skills、命令、MCP 配置)的插件没有实例,由宿主处理
|
|
326
414
|
*/
|
|
327
|
-
async function createExtensions(sources: LoadedPlugin[], host: HostContext,
|
|
328
|
-
const out:
|
|
415
|
+
async function createExtensions(sources: LoadedPlugin[], host: HostContext, warnings: string[]): Promise<Extension[]> {
|
|
416
|
+
const out: Extension[] = [];
|
|
417
|
+
/** 创建了却不用的实例也要收尾 */
|
|
418
|
+
const discard = async (source: LoadedPlugin, plugin: JadePlugin) => {
|
|
419
|
+
const w = await disposeInstance(source, plugin);
|
|
420
|
+
if (w) warnings.push(w);
|
|
421
|
+
};
|
|
329
422
|
for (const source of sources) {
|
|
330
423
|
if (!source.create) continue;
|
|
331
|
-
const where = `plugin ${source.
|
|
332
|
-
let
|
|
424
|
+
const where = `plugin ${source.id} (${source.layer})`;
|
|
425
|
+
let created: JadePlugin | undefined;
|
|
333
426
|
try {
|
|
334
|
-
|
|
335
|
-
|
|
427
|
+
created = await source.create(host);
|
|
428
|
+
// 清单里的 id 决定了停用、重复检查和状态栏,实例不能换成别的
|
|
429
|
+
if (created.id !== source.id) throw new Error(`its id ${JSON.stringify(created.id)} does not match "id" in plugin.json (use ctx.definePlugin, which fills it in)`);
|
|
430
|
+
checkCompat(created);
|
|
336
431
|
} catch (err) {
|
|
337
432
|
warnings.push(`${where} is skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
433
|
+
if (created) await discard(source, created);
|
|
338
434
|
continue;
|
|
339
435
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
436
|
+
const plugin = created;
|
|
437
|
+
// disposeInstance 只调用函数:不合格的不用删
|
|
438
|
+
if (plugin.dispose !== undefined && typeof plugin.dispose !== "function") warnings.push(`${where}: dispose is ignored: it must be a function`);
|
|
439
|
+
if ("replaces" in plugin) warnings.push(`${where}: replaces is ignored: write it in plugin.json instead ("replaces": ["jade/…"])`);
|
|
440
|
+
// 进程外插件的快捷键和命令按清单为这一套生成;模块插件的就在实例上
|
|
441
|
+
const parts = source.adapters ? source.adapters(host) : plugin;
|
|
442
|
+
const commands = listOf(parts.commands).filter((c): c is PluginCommand => {
|
|
443
|
+
const ok = Boolean(c) && typeof c.name === "string" && COMMAND_NAME.test(c.name) && typeof c.run === "function";
|
|
347
444
|
if (!ok) warnings.push(`${where}: command ${JSON.stringify(c?.name)} is ignored: it needs a name of letters, digits, - and _, and a run function`);
|
|
348
445
|
return ok;
|
|
349
446
|
});
|
|
350
|
-
//
|
|
351
|
-
if (plugin
|
|
352
|
-
|
|
447
|
+
// 模型服务不属于某套插件实例:改成在模块里导出(export const providers),加载时就注册。jade 不读实例上的 providers
|
|
448
|
+
if ("providers" in plugin) warnings.push(`${where}: providers is ignored: export it from the plugin module instead (export const providers = [...])`);
|
|
449
|
+
const keys = listOf(parts.keys).flatMap((k): PluginKey[] => {
|
|
450
|
+
const key = typeof k?.key === "string" ? k.key.toLowerCase() : undefined;
|
|
451
|
+
if (key !== undefined && KEY_SPEC.test(key) && !RESERVED_KEYS.has(key) && typeof k.run === "function") return [{ key, description: k.description, run: (ctx) => k.run(ctx) }];
|
|
452
|
+
warnings.push(`${where}: key ${JSON.stringify(k?.key)} is ignored: it needs a run function and a key like ctrl+<letter> or alt+<letter or digit> that jade does not use itself`);
|
|
453
|
+
return [];
|
|
454
|
+
});
|
|
455
|
+
const own = new Set((plugin.tools ?? []).map((t) => t.name));
|
|
456
|
+
const seen = new Set<string>();
|
|
457
|
+
// 只认自己的工具:别的工具的显示(尤其是审批时的预览)不能由插件改
|
|
458
|
+
const renderers = listOf(plugin.renderers).filter((r) => {
|
|
459
|
+
const tool = r?.tool;
|
|
460
|
+
const fields = r as unknown as Record<string, unknown> | undefined;
|
|
461
|
+
const fns = Boolean(fields) && ["summary", "details", "preview", "before", "result"].every((k) => fields![k] === undefined || typeof fields![k] === "function");
|
|
462
|
+
let why: string | undefined;
|
|
463
|
+
if (typeof tool !== "string" || !fns) why = "it needs a tool name, and summary, details, preview, before and result must be functions";
|
|
464
|
+
else if (!own.has(tool)) why = "a plugin can only render its own tools";
|
|
465
|
+
else if (seen.has(tool)) why = "the tool already has a renderer";
|
|
466
|
+
if (why) warnings.push(`${where}: renderer for ${JSON.stringify(tool)} is ignored: ${why}`);
|
|
467
|
+
else seen.add(tool!);
|
|
468
|
+
return !why;
|
|
469
|
+
});
|
|
470
|
+
// jade 不再提供的扩展点:写了也不起作用,提示一次
|
|
471
|
+
for (const gone of REMOVED) if (gone in plugin) warnings.push(`${where}: ${gone} is ignored: jade does not offer it to plugins`);
|
|
472
|
+
out.push({ source, plugin, commands, keys, renderers });
|
|
353
473
|
}
|
|
354
474
|
return out;
|
|
355
475
|
}
|
|
356
476
|
|
|
477
|
+
/** 去掉了的扩展点(见 docs/design/jade-plugin-lifecycle.md 第 9 节) */
|
|
478
|
+
const REMOVED = ["responder", "suggest", "beforeSend"] as const;
|
|
479
|
+
|
|
480
|
+
/** 插件给的列表:没给时为空;给的不是数组时当作一个不合格的项,好让上面提示 */
|
|
481
|
+
function listOf<T>(v: T[] | undefined): T[] {
|
|
482
|
+
return v === undefined ? [] : Array.isArray(v) ? v : [undefined as T];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* 调用第三方插件实例的 dispose,限时 DISPOSE_TIMEOUT_MS;返回要告诉用户的问题,没有时 undefined。
|
|
487
|
+
* 进程外插件的进程在会话之间共用,不在这里结束(见 LoadedPlugin.close)
|
|
488
|
+
*/
|
|
489
|
+
async function disposeInstance(source: LoadedPlugin, plugin: JadePlugin): Promise<string | undefined> {
|
|
490
|
+
if (source.kind === "process" || typeof plugin.dispose !== "function") return undefined;
|
|
491
|
+
const where = `plugin ${source.id} (${source.layer})`;
|
|
492
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
493
|
+
const timeout = new Promise<"timeout">((resolve) => {
|
|
494
|
+
timer = setTimeout(() => resolve("timeout"), DISPOSE_TIMEOUT_MS);
|
|
495
|
+
});
|
|
496
|
+
try {
|
|
497
|
+
const result = await Promise.race([Promise.resolve().then(() => plugin.dispose!()), timeout]);
|
|
498
|
+
return result === "timeout" ? `${where}: dispose did not finish within ${DISPOSE_TIMEOUT_MS / 1000}s` : undefined;
|
|
499
|
+
} catch (err) {
|
|
500
|
+
return `${where}: dispose failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
501
|
+
} finally {
|
|
502
|
+
clearTimeout(timer);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
357
506
|
/** 按顺序检查第三方插件的 id 和工具名不和已有的(留下的内置插件、排在前面的第三方插件)重复 */
|
|
358
|
-
function accept(made:
|
|
507
|
+
function accept(made: Extension[], existing: Plugin[]) {
|
|
359
508
|
const ids = new Set(existing.map((p) => p.id));
|
|
360
509
|
const toolNames = new Set(existing.flatMap((p) => (p.tools ?? []).map((t) => t.name)));
|
|
361
510
|
const accepted: typeof made = [];
|
|
362
511
|
const rejected: string[] = [];
|
|
363
512
|
for (const m of made) {
|
|
364
|
-
const where = `plugin ${m.source.
|
|
513
|
+
const where = `plugin ${m.source.id} (${m.source.layer})`;
|
|
365
514
|
if (ids.has(m.plugin.id)) {
|
|
366
515
|
rejected.push(`${where} is skipped: another plugin already has the id ${m.plugin.id}`);
|
|
367
516
|
continue;
|
|
368
517
|
}
|
|
518
|
+
// jade、jade/… 留给内置插件:会话里记的键按 id 划分(jade/undo 的撤销记录等),代替内置插件用 replaces,不用它的 id
|
|
519
|
+
if (m.plugin.id === "jade" || m.plugin.id.startsWith("jade/")) {
|
|
520
|
+
rejected.push(`${where} is skipped: the id ${m.plugin.id} is reserved for jade's built-in plugins (use "replaces" in plugin.json to stand in for one)`);
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
369
523
|
const clash = (m.plugin.tools ?? []).find((t) => toolNames.has(t.name));
|
|
370
524
|
if (clash) {
|
|
371
525
|
rejected.push(`${where} is skipped: tool ${clash.name} already exists`);
|
|
@@ -378,11 +532,15 @@ function accept(made: { source: LoadedPlugin; plugin: JadePlugin }[], existing:
|
|
|
378
532
|
return { accepted, rejected };
|
|
379
533
|
}
|
|
380
534
|
|
|
381
|
-
/** 子 Agent 的插件:只读工具(含 web 工具)、子 Agent
|
|
382
|
-
function subagent(
|
|
535
|
+
/** 子 Agent 的插件:只读工具(含 web 工具)、子 Agent 提示词、只读策略(加上主会话的规则)、压缩、步数上限。每次调用返回新实例 */
|
|
536
|
+
function subagent(
|
|
537
|
+
opts: JadeOptions,
|
|
538
|
+
system: { plugin?: Plugin },
|
|
539
|
+
available: () => { fs: boolean; web: Tool[]; mcp: McpClient[]; extensions: Plugin[] },
|
|
540
|
+
): (control: SubagentControl) => Plugin[] {
|
|
383
541
|
// 有哪些工具要到组装完成才知道,所以每次调用时再取
|
|
384
|
-
return () => {
|
|
385
|
-
const { fs, web, mcp } = available();
|
|
542
|
+
return (control) => {
|
|
543
|
+
const { fs, web, mcp, extensions } = available();
|
|
386
544
|
const tools: Plugin = {
|
|
387
545
|
id: "jade/tools-readonly",
|
|
388
546
|
version: "0.1.0",
|
|
@@ -390,6 +548,30 @@ function subagent(opts: JadeOptions, system: { plugin?: Plugin }, available: ()
|
|
|
390
548
|
tools: [...(fs ? fsTools(opts.cwd).filter((t) => READ_ONLY.has(t.name)) : []), ...web, ...mcpTools(mcp, { readOnly: true })],
|
|
391
549
|
};
|
|
392
550
|
const pol = policy({ cwd: opts.cwd, mode: "readonly", id: "jade/policy-subagent", rules: opts.sharedRules });
|
|
393
|
-
|
|
551
|
+
// 大范围调研时读的文件多:没有压缩会撑爆上下文,前面的调研全部白做
|
|
552
|
+
const compact = compactor({ provider: opts.provider, thresholdTokens: opts.compactTokens, id: "jade/compact-subagent" }).plugin;
|
|
553
|
+
const steps = budget({ maxSteps: () => (control.wrapUp ? 1 : SUBAGENT_STEPS), id: "jade/budget-subagent" });
|
|
554
|
+
// 第三方插件只带工具级的 hook(拦截、改写参数、给结果脱敏),子 Agent 读到的内容也经过它们;
|
|
555
|
+
// 不带它们的工具、提示词和 observe hook(例如按轮次触发的功能不该被子 Agent 触发)
|
|
556
|
+
const tooling = extensions
|
|
557
|
+
.map((p) => subsetPlugin(p, { tools: () => false, hooks: (h) => TOOL_HOOKS.has(h.point) }))
|
|
558
|
+
.filter((p) => p.hooks?.length);
|
|
559
|
+
return [tools, ...(system.plugin ? [system.plugin] : []), pol.plugin, compact, steps, ...tooling];
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/** 插件上下文的 complete:用会话的 provider 发一次不带工具的请求 */
|
|
564
|
+
function completer(provider: Provider): HostContext["complete"] {
|
|
565
|
+
const origin = { by: "plugin", id: "jade/extension" } as const;
|
|
566
|
+
return async (req, signal) => {
|
|
567
|
+
const res = await provider.complete(
|
|
568
|
+
{
|
|
569
|
+
system: req.system ? [{ text: req.system, stability: "stable", origin, trust: "trusted" }] : [],
|
|
570
|
+
messages: [{ role: "user", content: [{ kind: "text", text: req.prompt, origin, trust: "untrusted" }] }],
|
|
571
|
+
tools: [],
|
|
572
|
+
},
|
|
573
|
+
{ signal, onDelta: req.onText && ((d) => void (d.kind === "text" && req.onText!(d.text))) },
|
|
574
|
+
);
|
|
575
|
+
return { text: res.content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join(""), model: res.model, usage: res.usage };
|
|
394
576
|
};
|
|
395
577
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./plugins/budget.ts";
|
|
|
7
7
|
export * from "./plugins/compact.ts";
|
|
8
8
|
export * from "./plugins/checks.ts";
|
|
9
9
|
export * from "./plugins/policy.ts";
|
|
10
|
+
export * from "./plugins/review.ts";
|
|
10
11
|
export * from "./plugins/prompts.ts";
|
|
11
12
|
export * from "./plugins/schema.ts";
|
|
12
13
|
export * from "./tools/fs.ts";
|
|
@@ -17,6 +18,7 @@ export * from "./tools/shell.ts";
|
|
|
17
18
|
export * from "./tools/task.ts";
|
|
18
19
|
export * from "./tools/checkpoint.ts";
|
|
19
20
|
export * from "./tools/todo.ts";
|
|
21
|
+
export * from "./tools/ask.ts";
|
|
20
22
|
export * from "./config.ts";
|
|
21
23
|
export * from "./context.ts";
|
|
22
24
|
export * from "./commands.ts";
|
|
@@ -25,3 +27,4 @@ export * from "./plugins/install.ts";
|
|
|
25
27
|
export * from "./plugins/builtins.ts";
|
|
26
28
|
export * from "./mcp.ts";
|
|
27
29
|
export * from "./skills.ts";
|
|
30
|
+
export * from "./plugins/host.ts";
|