@uncarved/jade 0.1.2 → 0.2.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/bin/jade.js +5 -4
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -28
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +156 -1223
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +55 -0
- package/dist/update.js +258 -0
- package/dist/update.js.map +1 -0
- package/package.json +12 -9
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -84
- package/plugins/approval/review.ts +192 -0
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +68 -39
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +112 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +3 -4
- package/{src/tools → plugins/fs}/fs.ts +64 -46
- package/{src/tools → plugins/fs}/grep.ts +4 -3
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/plugins/fs/renderers.ts +138 -0
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +23 -27
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +36 -21
- package/{src → plugins/shell}/sys.ts +19 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +53 -1
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/{src/ui → plugins/tui}/markdown.ts +258 -219
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/plugins/tui/render.ts +67 -0
- package/plugins/tui/screen.ts +268 -0
- package/{src/ui → plugins/tui}/transcript.ts +179 -111
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/plugins/web/web.ts +713 -0
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
- package/plugins-dist/approval/review.js +176 -0
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
- package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/plugins-dist/fs/renderers.js +132 -0
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +22 -19
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
- package/{dist → plugins-dist/shell}/sys.js +20 -44
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/plugins-dist/tui/render.js +61 -0
- package/plugins-dist/tui/screen.js +201 -0
- package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
- package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/plugins-dist/web/web.js +660 -0
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -28
- package/src/install.ts +355 -0
- package/src/main.ts +152 -1263
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -0
- package/LICENSE +0 -21
- package/README.md +0 -198
- package/dist/commands.d.ts +0 -30
- package/dist/commands.js +0 -106
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -104
- package/dist/distro.js +0 -312
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -251
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -22
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -70
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -42
- package/dist/plugins/core.js +0 -190
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -182
- package/dist/plugins/loader.js +0 -253
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -96
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -38
- package/dist/plugins/prompts.js +0 -196
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -9
- package/dist/plugins/repeats.js +0 -90
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -16
- package/dist/plugins/review.js +0 -92
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/provider.d.ts +0 -111
- package/dist/provider.js.map +0 -1
- package/dist/sessions.d.ts +0 -22
- package/dist/sessions.js +0 -53
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -48
- package/dist/sys.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -35
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -35
- package/dist/tools/task.js +0 -89
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -23
- package/dist/tools/web.js +0 -426
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -378
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -33
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -17
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -15
- package/dist/ui/render.js +0 -94
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -98
- package/dist/ui/screen.js +0 -108
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -33
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -45
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -120
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -400
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -239
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -31
- package/src/plugins/core.ts +0 -217
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -386
- package/src/plugins/prompts.ts +0 -234
- package/src/plugins/repeats.ts +0 -96
- package/src/plugins/review.ts +0 -109
- package/src/sessions.ts +0 -61
- package/src/tools/task.ts +0 -109
- package/src/tools/web.ts +0 -451
- package/src/ui/configure.ts +0 -408
- package/src/ui/render.ts +0 -83
- package/src/ui/screen.ts +0 -169
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
package/src/commands.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
// 自定义命令:commands 目录里的每个 Markdown 文件是一个斜杠命令,文件名就是命令名,内容是发给模型的提示词。
|
|
2
|
-
//
|
|
3
|
-
// 用户层在 $JADE_HOME/commands,项目层在仓库根目录到工作目录之间每一级的 .jade/commands;
|
|
4
|
-
// 同名时离工作目录近的覆盖远的,项目层覆盖用户层。命令在启动时读一次。
|
|
5
|
-
//
|
|
6
|
-
// 文件开头可以有 YAML 风格的 front matter(只认 description 和 argument-hint 两个键):
|
|
7
|
-
// ---
|
|
8
|
-
// description: 审查当前的改动
|
|
9
|
-
// argument-hint: [文件或目录]
|
|
10
|
-
// ---
|
|
11
|
-
// 正文里的 $ARGUMENTS 换成命令后面的全部参数,$1…$9 换成按空白分开的第几个参数;
|
|
12
|
-
// 正文里没有这些占位符而命令带了参数时,参数接在正文后面。
|
|
13
|
-
|
|
14
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
15
|
-
import path from "node:path";
|
|
16
|
-
|
|
17
|
-
export interface CustomCommand {
|
|
18
|
-
name: string;
|
|
19
|
-
description: string;
|
|
20
|
-
/** 参数提示,显示在菜单里 */
|
|
21
|
-
args?: string;
|
|
22
|
-
body: string;
|
|
23
|
-
/** 文件的绝对路径 */
|
|
24
|
-
file: string;
|
|
25
|
-
layer: "user" | "project";
|
|
26
|
-
/** 来自哪个插件 */
|
|
27
|
-
plugin?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
31
|
-
|
|
32
|
-
/** 解析一个命令文件 */
|
|
33
|
-
export function parseCommand(name: string, text: string, file: string, layer: CustomCommand["layer"]): CustomCommand {
|
|
34
|
-
let body = text.replace(/^/, "");
|
|
35
|
-
const meta: Record<string, string> = {};
|
|
36
|
-
const fm = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(body);
|
|
37
|
-
if (fm) {
|
|
38
|
-
for (const line of fm[1]!.split(/\r?\n/)) {
|
|
39
|
-
const m = /^\s*([A-Za-z][\w-]*)\s*:\s*(.*?)\s*$/.exec(line);
|
|
40
|
-
if (m) meta[m[1]!.toLowerCase()] = m[2]!.replace(/^(["'])(.*)\1$/, "$2");
|
|
41
|
-
}
|
|
42
|
-
body = body.slice(fm[0].length);
|
|
43
|
-
}
|
|
44
|
-
body = body.trim();
|
|
45
|
-
const firstLine = body.split("\n").find((l) => l.trim() !== "")?.replace(/^#+\s*/, "").trim() ?? "";
|
|
46
|
-
return {
|
|
47
|
-
name,
|
|
48
|
-
description: meta.description || (firstLine.length > 80 ? firstLine.slice(0, 80) + "…" : firstLine) || "(custom command)",
|
|
49
|
-
args: meta["argument-hint"] || undefined,
|
|
50
|
-
body,
|
|
51
|
-
file,
|
|
52
|
-
layer,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** 把参数填进命令正文,得到要发给模型的消息 */
|
|
57
|
-
export function expandCommand(cmd: Pick<CustomCommand, "body">, args: string): string {
|
|
58
|
-
const words = args.trim() ? args.trim().split(/\s+/) : [];
|
|
59
|
-
let used = false;
|
|
60
|
-
const text = cmd.body
|
|
61
|
-
.replace(/\$ARGUMENTS\b/g, () => {
|
|
62
|
-
used = true;
|
|
63
|
-
return args.trim();
|
|
64
|
-
})
|
|
65
|
-
.replace(/\$([1-9])\b/g, (_, n: string) => {
|
|
66
|
-
used = true;
|
|
67
|
-
return words[Number(n) - 1] ?? "";
|
|
68
|
-
});
|
|
69
|
-
return !used && args.trim() ? `${text}\n\n${args.trim()}` : text;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async function loadDir(dir: string, layer: CustomCommand["layer"], into: Map<string, CustomCommand>, plugin?: string) {
|
|
73
|
-
let names: string[];
|
|
74
|
-
try {
|
|
75
|
-
names = await readdir(dir);
|
|
76
|
-
} catch {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
for (const n of names.sort()) {
|
|
80
|
-
if (!n.toLowerCase().endsWith(".md")) continue;
|
|
81
|
-
const name = n.slice(0, -3).toLowerCase();
|
|
82
|
-
if (!NAME.test(name)) continue;
|
|
83
|
-
const file = path.join(dir, n);
|
|
84
|
-
try {
|
|
85
|
-
const cmd = parseCommand(name, await readFile(file, "utf8"), file, layer);
|
|
86
|
-
into.set(name, plugin ? { ...cmd, plugin } : cmd);
|
|
87
|
-
} catch {
|
|
88
|
-
// 读不了的文件(目录、权限)跳过
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** 读取用户层和项目层的命令;root 是仓库根目录(不在仓库里时等于 cwd) */
|
|
94
|
-
export async function loadCommands(opts: {
|
|
95
|
-
home: string;
|
|
96
|
-
root: string;
|
|
97
|
-
cwd: string;
|
|
98
|
-
/** 插件带的 commands 目录,优先级低于同一层的 commands 目录 */
|
|
99
|
-
plugins?: { plugin: string; dir: string; layer: CustomCommand["layer"] }[];
|
|
100
|
-
}): Promise<CustomCommand[]> {
|
|
101
|
-
const out = new Map<string, CustomCommand>();
|
|
102
|
-
const fromPlugins = async (layer: CustomCommand["layer"]) => {
|
|
103
|
-
for (const p of opts.plugins ?? []) if (p.layer === layer) await loadDir(p.dir, layer, out, p.plugin);
|
|
104
|
-
};
|
|
105
|
-
await fromPlugins("user");
|
|
106
|
-
await loadDir(path.join(opts.home, "commands"), "user", out);
|
|
107
|
-
await fromPlugins("project");
|
|
108
|
-
for (const d of projectDirs(opts.root, opts.cwd)) await loadDir(path.join(d, ".jade", "commands"), "project", out);
|
|
109
|
-
return [...out.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** 从仓库根目录到工作目录的每一级目录,远的在前;工作目录不在仓库里时只有工作目录 */
|
|
113
|
-
export function projectDirs(root: string, cwd: string): string[] {
|
|
114
|
-
const rel = path.relative(root, cwd);
|
|
115
|
-
const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
|
|
116
|
-
if (!inside) return [cwd];
|
|
117
|
-
const dirs = [root];
|
|
118
|
-
if (rel) for (const seg of rel.split(path.sep)) dirs.push(path.join(dirs.at(-1)!, seg));
|
|
119
|
-
return dirs;
|
|
120
|
-
}
|
package/src/context.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// 模型的上下文窗口(最大输入 token 数),以及由它推出的压缩阈值。
|
|
2
|
-
//
|
|
3
|
-
// 窗口优先取 JADE_CONTEXT_WINDOW;不设时按模型名在一张小表里找(只收录确定的、取偏小的值),
|
|
4
|
-
// 找不到用 128000。估小了只是压缩得早一些;估大了请求会因为超长被拒,宿主看到这种错误会先压缩再重试一次。
|
|
5
|
-
|
|
6
|
-
import { parseTokens } from "./config.ts";
|
|
7
|
-
import { providerInfo } from "./provider.ts";
|
|
8
|
-
|
|
9
|
-
type Env = Record<string, string | undefined>;
|
|
10
|
-
|
|
11
|
-
/** 写错的 JADE_MAX_TOKENS 在创建 provider 时报错,这里当作没设 */
|
|
12
|
-
function tokensOrZero(text: string): number {
|
|
13
|
-
try {
|
|
14
|
-
return parseTokens("JADE_MAX_TOKENS", text);
|
|
15
|
-
} catch {
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** 认不出模型时的窗口 */
|
|
21
|
-
export const DEFAULT_CONTEXT_WINDOW = 128_000;
|
|
22
|
-
|
|
23
|
-
/** 模型名(不区分大小写,可以带 "anthropic/" 这类前缀)→ 窗口;按顺序取第一个匹配的 */
|
|
24
|
-
const KNOWN_WINDOWS: [RegExp, number][] = [
|
|
25
|
-
[/claude/i, 200_000],
|
|
26
|
-
[/gemini/i, 1_000_000],
|
|
27
|
-
[/gpt-4\.1/i, 1_000_000],
|
|
28
|
-
// GPT-5 的总窗口是 400k,其中输入最多 272k
|
|
29
|
-
[/gpt-5/i, 272_000],
|
|
30
|
-
[/(^|\/)o[134](-|$)/i, 200_000],
|
|
31
|
-
[/gpt-4o/i, 128_000],
|
|
32
|
-
[/deepseek/i, 128_000],
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
export type WindowSource = "env" | "model" | "default";
|
|
36
|
-
|
|
37
|
-
/** 上下文窗口和它的来源 */
|
|
38
|
-
export function contextWindowInfo(env: Env = process.env): { tokens: number; source: WindowSource } {
|
|
39
|
-
if (env.JADE_CONTEXT_WINDOW) return { tokens: parseTokens("JADE_CONTEXT_WINDOW", env.JADE_CONTEXT_WINDOW), source: "env" };
|
|
40
|
-
const model = providerInfo(env).model;
|
|
41
|
-
const known = KNOWN_WINDOWS.find(([re]) => re.test(model));
|
|
42
|
-
return known ? { tokens: known[1], source: "model" } : { tokens: DEFAULT_CONTEXT_WINDOW, source: "default" };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function contextWindowFromEnv(env: Env = process.env): number {
|
|
46
|
-
return contextWindowInfo(env).tokens;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 默认的压缩阈值:窗口的 80%,并给一次回复的输出留出位置(JADE_MAX_TOKENS,Claude 默认 64000),
|
|
51
|
-
* 但不低于窗口的一半
|
|
52
|
-
*/
|
|
53
|
-
export function compactThreshold(window: number, env: Env = process.env): number {
|
|
54
|
-
const output = env.JADE_MAX_TOKENS ? tokensOrZero(env.JADE_MAX_TOKENS) : providerInfo(env).kind === "anthropic" ? 64_000 : 0;
|
|
55
|
-
return Math.max(Math.floor(window * 0.5), Math.min(Math.floor(window * 0.8), window - output));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 服务端因为请求超出上下文窗口而拒绝的错误。各家的说法不同,按常见的措辞匹配 */
|
|
59
|
-
const OVERFLOW =
|
|
60
|
-
/context[_ ]length[_ ]exceeded|maximum context length|context window|prompt is too long|input is too long|exceeds? the (model'?s? )?(maximum|max|context)|request too large|input length .* exceed|reduce the length of the (messages|input|prompt)/i;
|
|
61
|
-
|
|
62
|
-
export function isContextOverflow(message: string | undefined): boolean {
|
|
63
|
-
return message !== undefined && OVERFLOW.test(message);
|
|
64
|
-
}
|
package/src/distro.ts
DELETED
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
// 组装发行版:内核之外的功能都是插件。内置插件(见 plugins/builtins.ts)和第三方插件用同一套接口,
|
|
2
|
-
// 在这里拼成一份插件清单。宿主(main.ts)和测试都通过这里创建,内核本身不知道这些插件的存在。
|
|
3
|
-
//
|
|
4
|
-
// 用户可以停用内置插件($JADE_HOME/plugins.json),第三方插件可以用 replaces 代替内置插件;jade/policy 两者都不行。
|
|
5
|
-
|
|
6
|
-
import path from "node:path";
|
|
7
|
-
import { checkCompat, definePlugin, type LogStore, type ModelRequest, type Plugin, type Provider, type Tool } from "uncarved";
|
|
8
|
-
import { budget } from "./plugins/budget.ts";
|
|
9
|
-
import { BUILTINS, BUILTIN_IDS, REQUIRED_IDS } from "./plugins/builtins.ts";
|
|
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";
|
|
12
|
-
import { Memory, memoryTool } from "./memory.ts";
|
|
13
|
-
import { mcpTools, type McpClient } from "./mcp.ts";
|
|
14
|
-
import { skillTool, skillsPrompt, type Skill } from "./skills.ts";
|
|
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, type PolicyOptions } from "./plugins/policy.ts";
|
|
18
|
-
import { prompts, realPath, repoRoot } from "./plugins/prompts.ts";
|
|
19
|
-
import { repeats } from "./plugins/repeats.ts";
|
|
20
|
-
import { fsTools } from "./tools/fs.ts";
|
|
21
|
-
import { Checkpoints } from "./tools/checkpoint.ts";
|
|
22
|
-
import { shellTools } from "./tools/shell.ts";
|
|
23
|
-
import { taskTool, type ApproveSubagent } from "./tools/task.ts";
|
|
24
|
-
import { todoTool } from "./tools/todo.ts";
|
|
25
|
-
import { webTools } from "./tools/web.ts";
|
|
26
|
-
import { screenshotTool } from "./tools/screenshot.ts";
|
|
27
|
-
import { visionFromEnv } from "./provider.ts";
|
|
28
|
-
|
|
29
|
-
const READ_ONLY = new Set(["read_file", "list_dir", "glob", "grep"]);
|
|
30
|
-
|
|
31
|
-
export interface JadeOptions {
|
|
32
|
-
cwd: string;
|
|
33
|
-
/** 用户层配置目录 */
|
|
34
|
-
home: string;
|
|
35
|
-
store: LogStore;
|
|
36
|
-
provider: Provider;
|
|
37
|
-
mode?: Mode;
|
|
38
|
-
/** 已经通过 loadProjectPlugin 确认过的项目层插件,原样加入 */
|
|
39
|
-
projectPlugins?: Plugin[];
|
|
40
|
-
/** 用 loadPlugin 加载的第三方插件(用户层和项目层),每次 createJade 创建一套新实例 */
|
|
41
|
-
extensions?: LoadedPlugin[];
|
|
42
|
-
/** 停用的插件:内置插件的 id,或者第三方插件的 id(第三方插件按目录名停用由宿主在加载前处理) */
|
|
43
|
-
disabled?: Iterable<string>;
|
|
44
|
-
/** 压缩阈值;传函数时每次投影前取值 */
|
|
45
|
-
compactTokens?: number | (() => number);
|
|
46
|
-
maxSteps?: number;
|
|
47
|
-
/** 当前配置的模型,写进主 Agent 的系统提示词(见 prompts 的 model);每次请求时取 */
|
|
48
|
-
model?: () => { name: string; via: string } | undefined;
|
|
49
|
-
/** 测试用 */
|
|
50
|
-
today?: string;
|
|
51
|
-
/** 读取搜索服务配置用,默认 process.env;测试用 */
|
|
52
|
-
env?: Record<string, string | undefined>;
|
|
53
|
-
/** web 工具用的 fetch;测试用 */
|
|
54
|
-
fetch?: typeof fetch;
|
|
55
|
-
/** web 工具解析主机名用;测试用 */
|
|
56
|
-
lookup?: (hostname: string) => Promise<string[]>;
|
|
57
|
-
/** 截图用的浏览器;不给时按 JADE_BROWSER 和常见安装位置找,null 表示不提供截图工具 */
|
|
58
|
-
browser?: string | null;
|
|
59
|
-
/** 子 Agent 要用户批准的调用(例如 web_fetch)交给宿主;不给就拒绝 */
|
|
60
|
-
approveSubagent?: ApproveSubagent;
|
|
61
|
-
/** 子 Agent 也遵守的"总是允许"规则(主会话的),每次判断时取 */
|
|
62
|
-
sharedRules?: () => AllowRule[];
|
|
63
|
-
/** 运行中切换、还没记进日志的权限模式(见 PolicyOptions.pendingMode) */
|
|
64
|
-
pendingMode?: () => Mode | undefined;
|
|
65
|
-
/** auto 模式下审查规则判断不了的调用(见 PolicyOptions.review);不给时 auto 模式不审查 */
|
|
66
|
-
review?: PolicyOptions["review"];
|
|
67
|
-
/**
|
|
68
|
-
* 编辑后检查的命令第一次运行前由宿主确认;不给就不做编辑后检查。
|
|
69
|
-
* 检查会执行仓库里的代码,所以不能默认放行
|
|
70
|
-
*/
|
|
71
|
-
approveCheck?: ApproveCheck;
|
|
72
|
-
/** /checks 显示一条检查是否已经确认过 */
|
|
73
|
-
checkConfirmed?: (check: Check) => Promise<boolean>;
|
|
74
|
-
/** 没有 approveCheck 时 /checks 给出的原因 */
|
|
75
|
-
checksUnavailable?: string;
|
|
76
|
-
/** 已连接的 MCP 服务,它们的工具加进主会话(声明只读的也给子 Agent) */
|
|
77
|
-
mcp?: McpClient[];
|
|
78
|
-
/** loadSkills 找到的 skill */
|
|
79
|
-
skills?: Skill[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface BuiltinState {
|
|
83
|
-
id: string;
|
|
84
|
-
about: string;
|
|
85
|
-
required?: boolean;
|
|
86
|
-
/** on:加载了;disabled:用户停用;replaced:被第三方插件代替 */
|
|
87
|
-
state: "on" | "disabled" | "replaced";
|
|
88
|
-
/** 代替它的插件 */
|
|
89
|
-
by?: string;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface Jade {
|
|
93
|
-
plugins: Plugin[];
|
|
94
|
-
policy: Policy;
|
|
95
|
-
/** jade/compact 停用或被代替时没有 */
|
|
96
|
-
compact?: Compactor;
|
|
97
|
-
/** write_file / edit_file 写入前的快照,供 /undo */
|
|
98
|
-
checkpoints: Checkpoints;
|
|
99
|
-
/** 跨会话的记忆;jade/memory 停用或被代替时没有 */
|
|
100
|
-
memory?: Memory;
|
|
101
|
-
/** 编辑后检查;没有 shell、宿主没给 approveCheck、jade/checks 停用时为 undefined */
|
|
102
|
-
checks?: Checks;
|
|
103
|
-
/** 每个内置插件的状态 */
|
|
104
|
-
builtins: BuiltinState[];
|
|
105
|
-
/** 成功加入本会话的第三方插件实例 */
|
|
106
|
-
extensions: { source: LoadedPlugin; plugin: JadePlugin }[];
|
|
107
|
-
/** 插件(内置的和第三方的)提供的斜杠命令,按小写的名字 */
|
|
108
|
-
commands: Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>;
|
|
109
|
-
/** 主会话的工具;宿主用 read_file / list_dir 读取 @ 引用的文件 */
|
|
110
|
-
tools: Tool[];
|
|
111
|
-
/** 宿主退出时调用:杀掉后台 shell */
|
|
112
|
-
shutdown(): void;
|
|
113
|
-
/** 启动时要告诉用户的问题,例如找不到 shell */
|
|
114
|
-
warnings: string[];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export async function createJade(opts: JadeOptions): Promise<Jade> {
|
|
118
|
-
const { cwd, store, provider } = opts;
|
|
119
|
-
const skills = opts.skills ?? [];
|
|
120
|
-
const mcp = opts.mcp ?? [];
|
|
121
|
-
const warnings: string[] = [];
|
|
122
|
-
|
|
123
|
-
const disabled = new Set(opts.disabled ?? []);
|
|
124
|
-
for (const id of REQUIRED_IDS) {
|
|
125
|
-
if (disabled.has(id)) {
|
|
126
|
-
warnings.push(`${id} cannot be disabled (it decides which tool calls need your approval); it stays on`);
|
|
127
|
-
disabled.delete(id);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const off = (id: string) => disabled.has(id);
|
|
131
|
-
|
|
132
|
-
const checkpoints = new Checkpoints(path.join(opts.home, "checkpoints"));
|
|
133
|
-
// run 也给插件和编辑后检查用,所以 jade/shell 停用时也创建,只是不把工具交给模型
|
|
134
|
-
const shell = shellTools({ cwd });
|
|
135
|
-
const root = await repoRoot(cwd);
|
|
136
|
-
const host: HostContext = { jade: JADE_VERSION, cwd: realPath(cwd), root: realPath(root), home: opts.home, definePlugin, run: shell.run };
|
|
137
|
-
|
|
138
|
-
// 第三方插件先创建:要先知道它们代替哪些内置插件
|
|
139
|
-
const made = await createExtensions(opts.extensions ?? [], host, disabled, warnings);
|
|
140
|
-
|
|
141
|
-
// ---------- 内置插件(jade/prompts 最后创建:它要知道最终有哪些工具) ----------
|
|
142
|
-
const built = new Map<string, JadePlugin>();
|
|
143
|
-
const add = (p: JadePlugin) => built.set(p.id, p);
|
|
144
|
-
|
|
145
|
-
const pol = policy({ cwd, mode: opts.mode, pendingMode: opts.pendingMode, review: opts.review, readRoots: off("jade/skills") ? [] : skills.map((x) => x.dir) });
|
|
146
|
-
add(pol.plugin);
|
|
147
|
-
// 占位,组装完成后换成真正的提示词插件
|
|
148
|
-
if (!off("jade/prompts")) add({ id: "jade/prompts", version: "0.3.0", kernel: "^0.1" });
|
|
149
|
-
|
|
150
|
-
// 文件工具据此判断读取和修改是不是同一次回复里发出的
|
|
151
|
-
const responses = { calls: 0 };
|
|
152
|
-
if (!off("jade/fs")) add(withCounter({ id: "jade/fs", version: "0.1.0", kernel: "^0.1", tools: fsTools(cwd, { checkpoints, responses }) }, responses));
|
|
153
|
-
if (!off("jade/shell")) add({ id: "jade/shell", version: "0.1.0", kernel: "^0.1", tools: shell.tools });
|
|
154
|
-
let web: Tool[] = [];
|
|
155
|
-
let hasScreenshot = false;
|
|
156
|
-
if (!off("jade/web")) {
|
|
157
|
-
try {
|
|
158
|
-
web = webTools({ env: opts.env, fetch: opts.fetch, lookup: opts.lookup }).tools;
|
|
159
|
-
} catch (err) {
|
|
160
|
-
warnings.push(`web tools are disabled: ${err instanceof Error ? err.message : String(err)}`);
|
|
161
|
-
}
|
|
162
|
-
// 截图只在模型能看图片时有用,否则截图到了模型那里只剩占位说明。/model 运行中会换模型、改 JADE_VISION,
|
|
163
|
-
// 所以找到浏览器就注册,每次请求前按当时的设置决定发不发给模型,不用重启
|
|
164
|
-
const canSee = () => {
|
|
165
|
-
try {
|
|
166
|
-
return visionFromEnv(opts.env ?? process.env);
|
|
167
|
-
} catch {
|
|
168
|
-
// 写错的 JADE_VISION 在创建 provider 时报错
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
const shot = opts.browser !== null ? screenshotTool({ cwd, browser: opts.browser, env: opts.env, available: canSee }) : undefined;
|
|
173
|
-
hasScreenshot = shot !== undefined;
|
|
174
|
-
add({
|
|
175
|
-
id: "jade/web",
|
|
176
|
-
version: "0.2.0",
|
|
177
|
-
kernel: "^0.1",
|
|
178
|
-
tools: shot ? [...web, shot] : web,
|
|
179
|
-
...(shot
|
|
180
|
-
? {
|
|
181
|
-
needs: ["transform:context.build"],
|
|
182
|
-
hooks: [
|
|
183
|
-
{
|
|
184
|
-
kind: "transform",
|
|
185
|
-
point: "context.build",
|
|
186
|
-
fn: (req: ModelRequest) => (canSee() ? req : { ...req, tools: req.tools.filter((t) => t.name !== shot.name) }),
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
}
|
|
190
|
-
: {}),
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
if (!off("jade/todo")) add({ id: "jade/todo", version: "0.1.0", kernel: "^0.1", tools: [todoTool()] });
|
|
194
|
-
|
|
195
|
-
let memory: Memory | undefined;
|
|
196
|
-
if (!off("jade/memory")) {
|
|
197
|
-
memory = new Memory(opts.home, root);
|
|
198
|
-
const text = await memory.prompt();
|
|
199
|
-
add(withSystem({ id: "jade/memory", version: "0.1.0", kernel: "^0.1", tools: [memoryTool(memory)], commands: [memoryCommand(memory)] }, text ? [{ text, trust: "trusted" }] : []));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** 最终加载了的内置插件,子 Agent 据此决定给哪些工具;组装完成后才填上 */
|
|
203
|
-
const kept = new Set<string>();
|
|
204
|
-
/** 子 Agent 的提示词,组装完成后生成 */
|
|
205
|
-
const subSystem: { plugin?: Plugin } = {};
|
|
206
|
-
if (!off("jade/task")) {
|
|
207
|
-
const subagentPlugins = subagent(opts, subSystem, () => ({ fs: kept.has("jade/fs"), web: kept.has("jade/web") ? web : [], mcp: kept.has("jade/mcp") ? mcp : [] }));
|
|
208
|
-
add({ id: "jade/task", version: "0.1.0", kernel: "^0.1", tools: [taskTool({ store, provider, plugins: subagentPlugins, approve: opts.approveSubagent })] });
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (!off("jade/skills")) {
|
|
212
|
-
const list = skillsPrompt(skills);
|
|
213
|
-
// 有随仓库分发的 skill 时这段是 untrusted
|
|
214
|
-
const trust = skills.every((x) => x.layer === "user") ? "trusted" : "untrusted";
|
|
215
|
-
add(
|
|
216
|
-
withSystem(
|
|
217
|
-
{ id: "jade/skills", version: "0.1.0", kernel: "^0.1", tools: skills.length ? [skillTool(skills)] : [], commands: [skillsCommand(skills, { cwd, home: opts.home })] },
|
|
218
|
-
list ? [{ text: list, trust }] : [],
|
|
219
|
-
),
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
if (!off("jade/mcp")) {
|
|
223
|
-
add(withSystem({ id: "jade/mcp", version: "0.1.0", kernel: "^0.1", tools: mcpTools(mcp), commands: [mcpCommand(mcp, { cwd, home: opts.home })] }, mcpInstructions(mcp)));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let checks: Checks | undefined;
|
|
227
|
-
if (!off("jade/checks")) {
|
|
228
|
-
checks =
|
|
229
|
-
shell.run && opts.approveCheck
|
|
230
|
-
? checksPlugin({ cwd: realPath(cwd), root: realPath(root), home: opts.home, run: shell.run, approve: opts.approveCheck })
|
|
231
|
-
: undefined;
|
|
232
|
-
const command = checksCommand(checks, {
|
|
233
|
-
cwd,
|
|
234
|
-
home: opts.home,
|
|
235
|
-
changed: async (sessionId) => [...new Set((await checkpoints.list(sessionId)).map((c) => c.path))],
|
|
236
|
-
confirmed: opts.checkConfirmed,
|
|
237
|
-
unavailable: opts.checksUnavailable ?? (shell.run ? "Edit-time checks are turned off." : "Edit-time checks need a shell; see the warning at startup."),
|
|
238
|
-
});
|
|
239
|
-
add(checks ? { ...checks.plugin, commands: [command] } : { id: "jade/checks", version: "0.1.0", kernel: "^0.1", commands: [command] });
|
|
240
|
-
}
|
|
241
|
-
let compact: Compactor | undefined;
|
|
242
|
-
if (!off("jade/compact")) {
|
|
243
|
-
compact = compactor({ provider, thresholdTokens: opts.compactTokens });
|
|
244
|
-
add({ ...compact.plugin, commands: [compactCommand(compact)] });
|
|
245
|
-
}
|
|
246
|
-
if (!off("jade/budget")) add(budget({ maxSteps: opts.maxSteps }));
|
|
247
|
-
if (!off("jade/repeats")) {
|
|
248
|
-
// 自己数回复次数:不依赖 jade/fs 是否加载
|
|
249
|
-
const own = { calls: 0 };
|
|
250
|
-
add(withCounter(repeats({ responses: own }), own));
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// ---------- 代替关系:被代替的内置插件让位,代替者的工具名可以和它重复 ----------
|
|
254
|
-
const claims = (p: JadePlugin) => (p.replaces ?? []).filter((id) => BUILTIN_IDS.has(id) && !REQUIRED_IDS.has(id) && built.has(id));
|
|
255
|
-
for (const { source, plugin } of made) {
|
|
256
|
-
for (const id of plugin.replaces ?? []) {
|
|
257
|
-
if (REQUIRED_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): cannot replace ${id}; add a gate hook to make approvals stricter instead`);
|
|
258
|
-
else if (!BUILTIN_IDS.has(id)) warnings.push(`plugin ${plugin.id} (${source.layer}): replaces unknown built-in plugin ${id}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
// 从"全部声明都生效"开始;被拒绝的插件声明的代替撤销,内置插件回来之后可能又拒绝别的插件,直到不再变化
|
|
262
|
-
let replaced = new Set(made.flatMap((m) => claims(m.plugin)));
|
|
263
|
-
let result: ReturnType<typeof accept>;
|
|
264
|
-
for (;;) {
|
|
265
|
-
result = accept(made, [...built.values()].filter((p) => !replaced.has(p.id)));
|
|
266
|
-
const next = new Set(result.accepted.flatMap((m) => claims(m.plugin)));
|
|
267
|
-
if (next.size === replaced.size) break;
|
|
268
|
-
replaced = next;
|
|
269
|
-
}
|
|
270
|
-
warnings.push(...result.rejected);
|
|
271
|
-
const added = result.accepted;
|
|
272
|
-
const builtin = [...built.values()].filter((p) => !replaced.has(p.id));
|
|
273
|
-
for (const p of builtin) kept.add(p.id);
|
|
274
|
-
|
|
275
|
-
const allTools = [...builtin, ...added.map((a) => a.plugin)].flatMap((p) => p.tools ?? []);
|
|
276
|
-
const toolNames = new Set(allTools.map((t) => t.name));
|
|
277
|
-
const webNames = kept.has("jade/web") ? web.map((t) => t.name) : [];
|
|
278
|
-
const at = builtin.findIndex((p) => p.id === "jade/prompts");
|
|
279
|
-
if (at >= 0) {
|
|
280
|
-
builtin[at] = await prompts({
|
|
281
|
-
cwd,
|
|
282
|
-
home: opts.home,
|
|
283
|
-
today: opts.today,
|
|
284
|
-
// bash 由别的插件提供时不知道它用什么 shell,不写
|
|
285
|
-
shell: toolNames.has("bash") ? (kept.has("jade/shell") ? (shell.executable ?? null) : undefined) : null,
|
|
286
|
-
web: webNames,
|
|
287
|
-
screenshot: hasScreenshot,
|
|
288
|
-
checks: kept.has("jade/checks") && Boolean(checks),
|
|
289
|
-
tools: toolNames,
|
|
290
|
-
model: opts.model,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
if (kept.has("jade/task")) subSystem.plugin = await prompts({ cwd, home: opts.home, role: "subagent", today: opts.today, web: webNames });
|
|
294
|
-
|
|
295
|
-
const builtins: BuiltinState[] = BUILTINS.map((b) => {
|
|
296
|
-
if (kept.has(b.id)) return { ...b, state: "on" as const };
|
|
297
|
-
const by = added.find((a) => claims(a.plugin).includes(b.id))?.plugin.id;
|
|
298
|
-
return by ? { ...b, state: "replaced" as const, by } : { ...b, state: "disabled" as const };
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
const plugins = [...builtin, ...(opts.projectPlugins ?? []), ...added.map((a) => a.plugin)];
|
|
302
|
-
const commands = new Map<string, { plugin: string; command: PluginCommand; builtin: boolean }>();
|
|
303
|
-
for (const p of [...builtin, ...added.map((a) => a.plugin)] as JadePlugin[]) {
|
|
304
|
-
const isBuiltin = BUILTIN_IDS.has(p.id) && builtin.includes(p);
|
|
305
|
-
for (const c of p.commands ?? []) {
|
|
306
|
-
const taken = commands.get(c.name.toLowerCase());
|
|
307
|
-
if (taken) warnings.push(`plugin ${p.id}: command /${c.name} is ignored: plugin ${taken.plugin} already provides it`);
|
|
308
|
-
else commands.set(c.name.toLowerCase(), { plugin: p.id, command: c, builtin: isBuiltin });
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
if (shell.unavailable && kept.has("jade/shell")) warnings.push(shell.unavailable);
|
|
312
|
-
return {
|
|
313
|
-
plugins,
|
|
314
|
-
policy: pol,
|
|
315
|
-
compact: kept.has("jade/compact") ? compact : undefined,
|
|
316
|
-
checkpoints,
|
|
317
|
-
memory: kept.has("jade/memory") ? memory : undefined,
|
|
318
|
-
checks: kept.has("jade/checks") ? checks : undefined,
|
|
319
|
-
builtins,
|
|
320
|
-
extensions: added,
|
|
321
|
-
commands,
|
|
322
|
-
tools: allTools,
|
|
323
|
-
shutdown: shell.shutdown,
|
|
324
|
-
warnings,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* 创建第三方插件的实例。有问题的插件跳过并给出警告,而不是让整个 jade 起不来:工厂出错、内核不兼容、命令格式不对。
|
|
330
|
-
* 只带内容(skills、命令、MCP 配置)的插件没有实例,由宿主处理
|
|
331
|
-
*/
|
|
332
|
-
async function createExtensions(sources: LoadedPlugin[], host: HostContext, disabled: Set<string>, warnings: string[]) {
|
|
333
|
-
const out: { source: LoadedPlugin; plugin: JadePlugin }[] = [];
|
|
334
|
-
for (const source of sources) {
|
|
335
|
-
if (!source.create) continue;
|
|
336
|
-
const where = `plugin ${source.name} (${source.layer})`;
|
|
337
|
-
let plugin: JadePlugin;
|
|
338
|
-
try {
|
|
339
|
-
plugin = await source.create(host);
|
|
340
|
-
checkCompat(plugin);
|
|
341
|
-
} catch (err) {
|
|
342
|
-
warnings.push(`${where} is skipped: ${err instanceof Error ? err.message : String(err)}`);
|
|
343
|
-
continue;
|
|
344
|
-
}
|
|
345
|
-
if (disabled.has(plugin.id)) continue;
|
|
346
|
-
if (plugin.replaces !== undefined && !(Array.isArray(plugin.replaces) && plugin.replaces.every((x) => typeof x === "string"))) {
|
|
347
|
-
warnings.push(`${where} is skipped: "replaces" must be an array of plugin ids`);
|
|
348
|
-
continue;
|
|
349
|
-
}
|
|
350
|
-
const commands = (plugin.commands ?? []).filter((c) => {
|
|
351
|
-
const ok = c && typeof c.name === "string" && COMMAND_NAME.test(c.name) && typeof c.run === "function";
|
|
352
|
-
if (!ok) warnings.push(`${where}: command ${JSON.stringify(c?.name)} is ignored: it needs a name of letters, digits, - and _, and a run function`);
|
|
353
|
-
return ok;
|
|
354
|
-
});
|
|
355
|
-
// 原地修改而不是复制:内核只认加载器返回的那个项目层插件对象(宪法 7.1)
|
|
356
|
-
if (plugin.commands) plugin.commands = commands;
|
|
357
|
-
out.push({ source, plugin });
|
|
358
|
-
}
|
|
359
|
-
return out;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/** 按顺序检查第三方插件的 id 和工具名不和已有的(留下的内置插件、排在前面的第三方插件)重复 */
|
|
363
|
-
function accept(made: { source: LoadedPlugin; plugin: JadePlugin }[], existing: Plugin[]) {
|
|
364
|
-
const ids = new Set(existing.map((p) => p.id));
|
|
365
|
-
const toolNames = new Set(existing.flatMap((p) => (p.tools ?? []).map((t) => t.name)));
|
|
366
|
-
const accepted: typeof made = [];
|
|
367
|
-
const rejected: string[] = [];
|
|
368
|
-
for (const m of made) {
|
|
369
|
-
const where = `plugin ${m.source.name} (${m.source.layer})`;
|
|
370
|
-
if (ids.has(m.plugin.id)) {
|
|
371
|
-
rejected.push(`${where} is skipped: another plugin already has the id ${m.plugin.id}`);
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
const clash = (m.plugin.tools ?? []).find((t) => toolNames.has(t.name));
|
|
375
|
-
if (clash) {
|
|
376
|
-
rejected.push(`${where} is skipped: tool ${clash.name} already exists`);
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
ids.add(m.plugin.id);
|
|
380
|
-
for (const t of m.plugin.tools ?? []) toolNames.add(t.name);
|
|
381
|
-
accepted.push(m);
|
|
382
|
-
}
|
|
383
|
-
return { accepted, rejected };
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/** 子 Agent 的插件:只读工具(含 web 工具)、子 Agent 提示词、只读策略(加上主会话的规则)、步数上限。每次调用返回新实例 */
|
|
387
|
-
function subagent(opts: JadeOptions, system: { plugin?: Plugin }, available: () => { fs: boolean; web: Tool[]; mcp: McpClient[] }): () => Plugin[] {
|
|
388
|
-
// 有哪些工具要到组装完成才知道,所以每次调用时再取
|
|
389
|
-
return () => {
|
|
390
|
-
const { fs, web, mcp } = available();
|
|
391
|
-
const tools: Plugin = {
|
|
392
|
-
id: "jade/tools-readonly",
|
|
393
|
-
version: "0.1.0",
|
|
394
|
-
kernel: "^0.1",
|
|
395
|
-
tools: [...(fs ? fsTools(opts.cwd).filter((t) => READ_ONLY.has(t.name)) : []), ...web, ...mcpTools(mcp, { readOnly: true })],
|
|
396
|
-
};
|
|
397
|
-
const pol = policy({ cwd: opts.cwd, mode: "readonly", id: "jade/policy-subagent", rules: opts.sharedRules });
|
|
398
|
-
return [tools, ...(system.plugin ? [system.plugin] : []), pol.plugin, budget({ maxSteps: 40, id: "jade/budget-subagent" })];
|
|
399
|
-
};
|
|
400
|
-
}
|