@uncarved/jade 0.1.3 → 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 -27
- 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 -30
- package/dist/index.js +11 -30
- 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 +159 -1362
- 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 +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -100
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- 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 +48 -38
- 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 +73 -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 +2 -2
- package/{src/tools → plugins/fs}/fs.ts +19 -42
- package/{src/tools → plugins/fs}/grep.ts +1 -1
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- 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 +16 -119
- 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 +31 -20
- package/{src → plugins/shell}/sys.ts +2 -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 +3 -0
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +74 -99
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
- 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/{src/tools → plugins/web}/web.ts +58 -26
- 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 -81
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- 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 +46 -35
- 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 +51 -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 +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
- package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- 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 +18 -81
- 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 +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- 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 +3 -1
- 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 +0 -1
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
- 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/{dist/tools → plugins-dist/web}/web.js +50 -24
- 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 -30
- package/src/install.ts +355 -0
- package/src/main.ts +155 -1387
- 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 -262
- package/LICENSE +0 -21
- package/README.md +0 -204
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- 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 -141
- package/dist/distro.js +0 -462
- 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 -294
- 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 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- 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 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.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 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- 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/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- 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 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.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 -39
- 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 -39
- package/dist/tools/task.js +0 -117
- 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 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- 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 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { readFile, stat } from "node:fs/promises";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { display, listFiles, statOrUndefined } from "./fs.js";
|
|
9
|
-
import { globMatcher, spawn, text } from "
|
|
9
|
+
import { globMatcher, spawn, text } from "./sys.js";
|
|
10
10
|
const MAX_MATCHES = 200;
|
|
11
11
|
const MAX_FILES = 500;
|
|
12
12
|
const MAX_CONTEXT = 10;
|
|
@@ -241,4 +241,3 @@ async function jsGrep(s) {
|
|
|
241
241
|
}
|
|
242
242
|
return { files, truncated: false };
|
|
243
243
|
}
|
|
244
|
-
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// jade/fs:文件工具 read_file、write_file、edit_file、multi_edit、list_dir、glob、grep。
|
|
2
|
+
import { definePlugin } from "../../dist/api.js";
|
|
3
|
+
import { fsTools } from "./fs.js";
|
|
4
|
+
import { fsRenderers } from "./renderers.js";
|
|
5
|
+
export default definePlugin({
|
|
6
|
+
process(ctx) {
|
|
7
|
+
// 显示方式和会话无关,登记一次留到进程结束;没有 renderers@1(例如 print)时用前端的默认显示
|
|
8
|
+
const renderers = ctx.service("renderers@1");
|
|
9
|
+
if (renderers)
|
|
10
|
+
for (const r of fsRenderers(ctx.cwd))
|
|
11
|
+
renderers.tool(r);
|
|
12
|
+
},
|
|
13
|
+
session(ctx) {
|
|
14
|
+
// 数模型调用的次数:同一次回复里先读后改的,改的内容是看到读取结果之前写好的
|
|
15
|
+
const responses = { calls: 0 };
|
|
16
|
+
ctx.kernel.hook({
|
|
17
|
+
kind: "transform",
|
|
18
|
+
point: "model.before",
|
|
19
|
+
fn: () => {
|
|
20
|
+
responses.calls++;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
for (const tool of fsTools(ctx.cwd, { responses }))
|
|
24
|
+
ctx.kernel.tool(tool);
|
|
25
|
+
// 子 Agent(jade/task)的只读工具:另一套实例,子 Agent 读过的文件不算主会话读过
|
|
26
|
+
// jade/task 被隔离时它的服务已失效:子 Agent 没有文件工具,文件工具本身照常
|
|
27
|
+
try {
|
|
28
|
+
const task = ctx.service("task@1");
|
|
29
|
+
if (task)
|
|
30
|
+
for (const tool of fsTools(ctx.cwd))
|
|
31
|
+
if (tool.effect === "read")
|
|
32
|
+
task.tool(tool);
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
// jade
|
|
2
|
-
//
|
|
1
|
+
// 文件工具在对话和审批里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植,去掉了检查点。
|
|
2
|
+
//
|
|
3
|
+
// 审批插件的 tool.before 把 path 换成了绝对路径,审批预览、before、result 拿到的都是绝对路径;
|
|
4
|
+
// 显示时用 display 换回工作目录内的相对路径。没有登记 renderer 的部分用前端的默认显示。
|
|
3
5
|
import { readFileSync } from "node:fs";
|
|
4
6
|
import { readFile } from "node:fs/promises";
|
|
5
7
|
import path from "node:path";
|
|
6
|
-
import { applyEditsToText, display } from "../tools/fs.js";
|
|
7
8
|
import { diffLines, diffStats, renderDiff } from "./diff.js";
|
|
8
|
-
import {
|
|
9
|
-
import { dim, green, red, yellow } from "./
|
|
10
|
-
const args = (input) => (input
|
|
11
|
-
|
|
9
|
+
import { applyEditsToText, display } from "./fs.js";
|
|
10
|
+
import { clip, dim, green, red, yellow } from "./style.js";
|
|
11
|
+
const args = (input) => (input !== null && typeof input === "object" ? input : {});
|
|
12
|
+
/** 显示用的路径;工作目录本身显示成 "."(display 对它给的是绝对路径,审批插件会把 "." 换成工作目录) */
|
|
13
|
+
function pathOf(cwd, i) {
|
|
14
|
+
if (typeof i.path !== "string")
|
|
15
|
+
return "";
|
|
16
|
+
const full = path.resolve(cwd, i.path);
|
|
17
|
+
return path.relative(cwd, full) === "" ? "." : display(cwd, full);
|
|
18
|
+
}
|
|
12
19
|
/** 预览里的多行文字:每行前面加上标记,最多 max 行 */
|
|
13
20
|
function marked(s, mark, color, max = 30) {
|
|
14
21
|
const all = s.split("\n");
|
|
@@ -17,7 +24,7 @@ function marked(s, mark, color, max = 30) {
|
|
|
17
24
|
shown.push(dim(` … ${all.length - max} more lines`));
|
|
18
25
|
return shown.join("\n");
|
|
19
26
|
}
|
|
20
|
-
/**
|
|
27
|
+
/** 折叠内容里的多行文字(缩进由前端加),最多 max 行 */
|
|
21
28
|
function capped(lines, color, max) {
|
|
22
29
|
const shown = lines.slice(0, max).map(color);
|
|
23
30
|
if (lines.length > max)
|
|
@@ -57,7 +64,7 @@ const MAX_DIFF_LINES = 400;
|
|
|
57
64
|
const MAX_RESULT_LINES = 2000;
|
|
58
65
|
/**
|
|
59
66
|
* 执行前后的差异。在工具执行之前调用(读的是修改前的文件),同步读文件:
|
|
60
|
-
*
|
|
67
|
+
* 执行前的通知是同步的,等异步读完文件可能已经改了。替换不成立时返回 undefined
|
|
61
68
|
*/
|
|
62
69
|
function fileDiff(cwd, tool, input) {
|
|
63
70
|
const i = args(input);
|
|
@@ -103,67 +110,23 @@ function fileRenderer(cwd, tool, summary) {
|
|
|
103
110
|
};
|
|
104
111
|
}
|
|
105
112
|
export function fsRenderers(cwd) {
|
|
113
|
+
// 默认摘要是 path 参数,审批插件换成绝对路径后太长:统一换回相对路径
|
|
114
|
+
const where = (input) => pathOf(cwd, args(input));
|
|
106
115
|
const search = (input) => {
|
|
107
116
|
const i = args(input);
|
|
108
|
-
const
|
|
109
|
-
return `${i.pattern}${
|
|
117
|
+
const at = pathOf(cwd, i);
|
|
118
|
+
return `${i.pattern}${at && at !== "." ? ` in ${at}` : ""}`;
|
|
110
119
|
};
|
|
111
120
|
return [
|
|
112
|
-
|
|
121
|
+
{ tool: "read_file", summary: where },
|
|
122
|
+
{ tool: "list_dir", summary: where },
|
|
123
|
+
fileRenderer(cwd, "edit_file", where),
|
|
113
124
|
fileRenderer(cwd, "multi_edit", (input) => {
|
|
114
125
|
const i = args(input);
|
|
115
126
|
return `${pathOf(cwd, i)}, ${Array.isArray(i.edits) ? i.edits.length : 0} edits`;
|
|
116
127
|
}),
|
|
117
|
-
fileRenderer(cwd, "write_file"),
|
|
128
|
+
fileRenderer(cwd, "write_file", where),
|
|
118
129
|
{ tool: "grep", summary: search },
|
|
119
130
|
{ tool: "glob", summary: search },
|
|
120
131
|
];
|
|
121
132
|
}
|
|
122
|
-
// ---------- 其他内置工具 ----------
|
|
123
|
-
export const shellRenderers = [
|
|
124
|
-
{
|
|
125
|
-
tool: "bash",
|
|
126
|
-
summary: (input) => clip(String(args(input).command ?? "").split("\n")[0], 120),
|
|
127
|
-
// 摘要省略了内容时(多行或很长的命令),展开后先显示完整的命令
|
|
128
|
-
details: (input) => {
|
|
129
|
-
const lines = String(args(input).command ?? "").split("\n");
|
|
130
|
-
if (lines.length === 1 && lines[0].length <= 120)
|
|
131
|
-
return undefined;
|
|
132
|
-
return capped(lines.map((l, i) => `${i === 0 ? "$" : " "} ${l}`), dim, 200);
|
|
133
|
-
},
|
|
134
|
-
preview: (input) => marked(String(args(input).command ?? ""), "$", (s) => s),
|
|
135
|
-
},
|
|
136
|
-
{ tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
|
|
137
|
-
{ tool: "kill_shell", summary: (input) => String(args(input).id ?? "") },
|
|
138
|
-
];
|
|
139
|
-
export const webRenderers = [
|
|
140
|
-
{ tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
|
|
141
|
-
{ tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
|
|
142
|
-
];
|
|
143
|
-
export const todoRenderers = [
|
|
144
|
-
{ tool: "todo_write", summary: (input) => `${Array.isArray(args(input).todos) ? args(input).todos.length : 0} items` },
|
|
145
|
-
];
|
|
146
|
-
export const askRenderers = [
|
|
147
|
-
{
|
|
148
|
-
tool: "ask_user",
|
|
149
|
-
summary: (input) => {
|
|
150
|
-
const q = args(input).questions;
|
|
151
|
-
return Array.isArray(q) && q.length === 1 ? clip(String(q[0]?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
export const memoryRenderers = [
|
|
156
|
-
{
|
|
157
|
-
tool: "memory",
|
|
158
|
-
summary: (input) => {
|
|
159
|
-
const i = args(input);
|
|
160
|
-
return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
|
|
161
|
-
},
|
|
162
|
-
preview: (input) => {
|
|
163
|
-
const i = args(input);
|
|
164
|
-
return `${i.action === "remove" ? red("- ") : green("+ ")}${String(i.text ?? "")}`;
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
export const taskRenderers = [{ tool: "task", summary: (input) => String(args(input).description ?? "") }];
|
|
169
|
-
//# sourceMappingURL=renderers.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// 显示用的小工具:截断和 ANSI 颜色。从旧 jade 的 ui/render.ts、ui/screen.ts 复制过来:
|
|
2
|
+
// 插件之间不共享代码(只能共享类型),所以 shell 插件也有一份。
|
|
3
|
+
export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
4
|
+
// 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
|
|
5
|
+
const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
6
|
+
/**
|
|
7
|
+
* 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
|
|
8
|
+
* 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
|
|
9
|
+
*/
|
|
10
|
+
const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
|
|
11
|
+
export const dim = paint("2", "22");
|
|
12
|
+
export const red = paint("31", "39");
|
|
13
|
+
export const green = paint("32", "39");
|
|
14
|
+
export const yellow = paint("33", "39");
|
|
15
|
+
export const bold = paint("1", "22");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// 跨运行时的进程和 glob:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
|
|
2
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
3
|
+
import picomatch from "picomatch";
|
|
4
|
+
const EMPTY = { async *[Symbol.asyncIterator]() { } };
|
|
5
|
+
/**
|
|
6
|
+
* 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
|
|
7
|
+
* 调用方用 try/catch 判断"没装",和 Bun.spawn 同步抛错的用法一致
|
|
8
|
+
*/
|
|
9
|
+
export function spawn(cmd, opts = {}) {
|
|
10
|
+
const child = nodeSpawn(cmd[0], cmd.slice(1), {
|
|
11
|
+
cwd: opts.cwd,
|
|
12
|
+
stdio: ["ignore", opts.stdout ?? "pipe", opts.stderr ?? "pipe"],
|
|
13
|
+
detached: opts.detached ?? false,
|
|
14
|
+
env: opts.env,
|
|
15
|
+
// Windows 上不弹出控制台窗口
|
|
16
|
+
windowsHide: true,
|
|
17
|
+
});
|
|
18
|
+
const exited = new Promise((resolve) => child.once("exit", (code) => resolve(code)));
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
child.once("error", reject);
|
|
21
|
+
child.once("spawn", () => {
|
|
22
|
+
child.off("error", reject);
|
|
23
|
+
// 启动之后的错误(例如 kill 一个已经退出的进程)不应该变成未处理的异常
|
|
24
|
+
child.on("error", () => { });
|
|
25
|
+
resolve({
|
|
26
|
+
pid: child.pid,
|
|
27
|
+
stdout: child.stdout ?? EMPTY,
|
|
28
|
+
stderr: child.stderr ?? EMPTY,
|
|
29
|
+
exited,
|
|
30
|
+
kill: () => void child.kill(),
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** 运行一条命令,返回 stdout 文本和退出码;启动失败时 reject */
|
|
36
|
+
export async function run(cmd, opts = {}) {
|
|
37
|
+
const proc = await spawn(cmd, { cwd: opts.cwd, stderr: "ignore" });
|
|
38
|
+
const [stdout, code] = await Promise.all([text(proc.stdout), proc.exited]);
|
|
39
|
+
return { code, stdout };
|
|
40
|
+
}
|
|
41
|
+
export async function text(stream) {
|
|
42
|
+
const decoder = new TextDecoder();
|
|
43
|
+
let out = "";
|
|
44
|
+
for await (const chunk of stream)
|
|
45
|
+
out += decoder.decode(chunk, { stream: true });
|
|
46
|
+
return out + decoder.decode();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 编译 glob,返回匹配函数。路径用正斜杠、相对于搜索根目录。
|
|
50
|
+
* 和原先的 Bun.Glob#match 一致:* 也匹配点开头的文件,反斜杠是转义符而不是分隔符
|
|
51
|
+
*/
|
|
52
|
+
export function globMatcher(pattern) {
|
|
53
|
+
return picomatch(pattern, { dot: true, windows: false });
|
|
54
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// jade/keys:快捷键的注册表。前端在输入框有焦点时按下自己不用的键,查这里找到插件的处理函数。
|
|
2
|
+
import { definePlugin } from "../../dist/api.js";
|
|
3
|
+
/** "ctrl+<字母>"、"alt+<字母或数字>" 或 "shift+tab" */
|
|
4
|
+
export const KEY_SPEC = /^(ctrl\+[a-z]|alt\+[a-z0-9]|shift\+tab)$/;
|
|
5
|
+
/**
|
|
6
|
+
* 前端自己用的键,插件不能用:编辑(ctrl+a/e/d/w/u/k,按词移动的 alt+f/b)、搜索历史(ctrl+r)、重画(ctrl+l)、展开(ctrl+o)、
|
|
7
|
+
* 中断和退出(ctrl+c),以及终端里等同于退格、Tab、回车的 ctrl+h/i/j/m
|
|
8
|
+
*/
|
|
9
|
+
export const RESERVED_KEYS = new Set([..."acdehijklmoruw"].map((c) => `ctrl+${c}`).concat("alt+f", "alt+b"));
|
|
10
|
+
const registry = new Map();
|
|
11
|
+
export default definePlugin({
|
|
12
|
+
process(ctx) {
|
|
13
|
+
ctx.provide("keys@1", (caller) => ({
|
|
14
|
+
register(key) {
|
|
15
|
+
const spec = String(key?.key ?? "").toLowerCase();
|
|
16
|
+
if (!KEY_SPEC.test(spec))
|
|
17
|
+
throw new Error(`invalid key ${JSON.stringify(key?.key)}: use ctrl+<letter>, alt+<letter or digit> or shift+tab`);
|
|
18
|
+
if (RESERVED_KEYS.has(spec))
|
|
19
|
+
throw new Error(`key ${spec} is reserved by the frontend`);
|
|
20
|
+
const taken = registry.get(spec);
|
|
21
|
+
if (taken)
|
|
22
|
+
throw new Error(`key ${spec} is already registered by ${taken.plugin}`);
|
|
23
|
+
const entry = { key, plugin: caller.plugin };
|
|
24
|
+
registry.set(spec, entry);
|
|
25
|
+
const revoke = () => {
|
|
26
|
+
if (registry.get(spec) === entry)
|
|
27
|
+
registry.delete(spec);
|
|
28
|
+
};
|
|
29
|
+
caller.onDispose(revoke);
|
|
30
|
+
return revoke;
|
|
31
|
+
},
|
|
32
|
+
get: (spec) => registry.get(spec.toLowerCase()),
|
|
33
|
+
list: () => [...registry.entries()].map(([k, { key, plugin }]) => ({ key: k, ...(key.description ? { description: key.description } : {}), plugin })).sort((a, b) => a.key.localeCompare(b.key)),
|
|
34
|
+
}));
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// jade/mcp:配置的 MCP 服务的工具交给模型(声明只读的也经 task@1 交给子 Agent);/mcp 查看状态、重连。
|
|
2
|
+
//
|
|
3
|
+
// 服务是进程级的资源:第一个会话打开时读配置、确认项目层的服务、连接,之后各会话共用;进程退出时(进程作用域关闭)全部关掉。
|
|
4
|
+
// 一个会话里的工具列表不变(否则提示缓存失效):第一个会话最多等 STARTUP_WAIT_MS,没连上的在后台接着连,
|
|
5
|
+
// 它们的工具从下一个会话(/clear)开始提供。不能交互时(-p)只有这一个会话,照常等到每个服务连上或超时。
|
|
6
|
+
// 服务进程退出后,下一次调用它的工具时重新连接一次。
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { definePlugin } from "../../dist/api.js";
|
|
9
|
+
import { describeServer, loadMcpConfig, McpClient, mcpTools, mcpTrustHash } from "./mcp.js";
|
|
10
|
+
import { bold, clip, dim, display, green, realPath, red, repoRoot, TrustFile, yellow } from "./project.js";
|
|
11
|
+
const ID = "jade/mcp";
|
|
12
|
+
/** 第一个会话最多等 MCP 服务连接这么久(能交互时),没连上的在后台接着连 */
|
|
13
|
+
const STARTUP_WAIT_MS = 5000;
|
|
14
|
+
const errorText = (err) => (err instanceof Error ? err.message : String(err));
|
|
15
|
+
/** 本进程的 MCP 服务 */
|
|
16
|
+
class Servers {
|
|
17
|
+
clients = [];
|
|
18
|
+
#ctx;
|
|
19
|
+
#started;
|
|
20
|
+
#closing = false;
|
|
21
|
+
constructor(ctx) {
|
|
22
|
+
this.#ctx = ctx;
|
|
23
|
+
}
|
|
24
|
+
/** 用到时才取:ui@1 的提供者可能排在后面激活(3.3) */
|
|
25
|
+
ui() {
|
|
26
|
+
try {
|
|
27
|
+
return this.#ctx.service("ui@1");
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
notify(text, level = "info") {
|
|
34
|
+
if (this.#closing)
|
|
35
|
+
return;
|
|
36
|
+
try {
|
|
37
|
+
this.ui()?.notify(text, level);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// 前端已经关了
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** 第一次调用时读配置、确认、连接;之后等同一次。失败时关掉已经建的连接,下次调用重来,免得一次失败让 MCP 一直用不了 */
|
|
44
|
+
start() {
|
|
45
|
+
this.#started ??= this.#start().catch(async (e) => {
|
|
46
|
+
await Promise.all(this.clients.splice(0).map((c) => c.close().catch(() => { })));
|
|
47
|
+
this.#started = undefined;
|
|
48
|
+
throw e;
|
|
49
|
+
});
|
|
50
|
+
return this.#started;
|
|
51
|
+
}
|
|
52
|
+
async #start() {
|
|
53
|
+
const ctx = this.#ctx;
|
|
54
|
+
const cwd = realPath(ctx.cwd);
|
|
55
|
+
const root = realPath(repoRoot(cwd));
|
|
56
|
+
const trust = new TrustFile(path.join(ctx.home, "trust.jsonl"));
|
|
57
|
+
const { servers, warnings } = await loadMcpConfig({ home: ctx.home, root, cwd });
|
|
58
|
+
for (const w of warnings)
|
|
59
|
+
this.notify(`${ID}: ${w}`, "warning");
|
|
60
|
+
const ui = this.ui();
|
|
61
|
+
const connecting = [];
|
|
62
|
+
for (const entry of servers) {
|
|
63
|
+
if (entry.config.disabled)
|
|
64
|
+
continue;
|
|
65
|
+
if (entry.layer === "project") {
|
|
66
|
+
// 项目层的服务随仓库分发,启动它就是执行仓库指定的命令:第一次启动前(配置变了也算)请用户确认
|
|
67
|
+
const hash = mcpTrustHash(root, entry);
|
|
68
|
+
if (!(await trust.has(hash))) {
|
|
69
|
+
const ok = ui?.interactive
|
|
70
|
+
? (await ui.select({
|
|
71
|
+
title: `MCP server "${entry.name}" from ${display(cwd, entry.file)} is new or changed. Start it?`,
|
|
72
|
+
detail: `${entry.config.command !== undefined ? "runs" : "connects to"}: ${describeServer(entry.config)}`,
|
|
73
|
+
options: [
|
|
74
|
+
{ label: "No", value: "no" },
|
|
75
|
+
{ label: "Yes, start it", value: "yes" },
|
|
76
|
+
],
|
|
77
|
+
}, ctx.signal)) === "yes"
|
|
78
|
+
: false;
|
|
79
|
+
if (!ok) {
|
|
80
|
+
this.notify(`[skipped] MCP server ${entry.name}: not confirmed${ui?.interactive ? "" : " (run jade interactively in this directory once to confirm it)"}`, "warning");
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
await trust.add(hash, entry.file);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const client = new McpClient(entry, {
|
|
87
|
+
cwd,
|
|
88
|
+
onDisconnect: (c, why) => this.notify(`MCP server ${c.name} disconnected: ${why}. jade reconnects on its next tool call; /mcp shows details`, "warning"),
|
|
89
|
+
});
|
|
90
|
+
this.clients.push(client);
|
|
91
|
+
connecting.push(client.connect().catch((err) => this.notify(`MCP server ${client.name} is unavailable: ${errorText(err)}`, "warning")));
|
|
92
|
+
}
|
|
93
|
+
if (this.clients.length === 0)
|
|
94
|
+
return;
|
|
95
|
+
const all = Promise.all(connecting);
|
|
96
|
+
let timer;
|
|
97
|
+
if (ui?.interactive)
|
|
98
|
+
await Promise.race([all, new Promise((resolve) => (timer = setTimeout(resolve, STARTUP_WAIT_MS)))]);
|
|
99
|
+
else
|
|
100
|
+
await all;
|
|
101
|
+
clearTimeout(timer);
|
|
102
|
+
for (const c of this.clients.filter((x) => x.status === "connecting")) {
|
|
103
|
+
this.notify(`MCP server ${c.name} is still starting; its tools are available from the next session (/clear) once it is connected`);
|
|
104
|
+
void c.connect().then(() => this.notify(`MCP server ${c.name} connected; its tools are available from the next session (/clear)`), () => { });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async close() {
|
|
108
|
+
this.#closing = true;
|
|
109
|
+
await Promise.all(this.clients.map((c) => c.close().catch(() => { })));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** 服务在初始化时给出的使用说明,放进系统提示词。来自外部,标为不可信 */
|
|
113
|
+
function instructions(clients) {
|
|
114
|
+
return clients
|
|
115
|
+
.filter((c) => c.status === "connected" && c.instructions)
|
|
116
|
+
.map((c) => `# Instructions from the MCP server "${c.name}" (about its mcp__${c.name}__* tools)
|
|
117
|
+
|
|
118
|
+
${c.instructions}`);
|
|
119
|
+
}
|
|
120
|
+
/** 当前进程的服务;process() 里创建,session() 里用 */
|
|
121
|
+
let current;
|
|
122
|
+
export default definePlugin({
|
|
123
|
+
async process(ctx) {
|
|
124
|
+
const servers = new Servers(ctx);
|
|
125
|
+
current = servers;
|
|
126
|
+
// 后台资源:进程作用域关闭时关掉所有服务(服务本身到第一个会话打开时才启动)
|
|
127
|
+
await ctx.effect(() => () => servers.close());
|
|
128
|
+
ctx.service("commands@1")?.register({
|
|
129
|
+
name: "mcp",
|
|
130
|
+
args: "[reconnect <name>]",
|
|
131
|
+
description: "MCP servers: status and tools",
|
|
132
|
+
instant: true,
|
|
133
|
+
async run(args) {
|
|
134
|
+
await servers.start();
|
|
135
|
+
const clients = servers.clients;
|
|
136
|
+
const words = args.trim().split(/\s+/).filter(Boolean);
|
|
137
|
+
if (words[0] === "reconnect") {
|
|
138
|
+
const c = clients.find((x) => x.name === words[1]);
|
|
139
|
+
if (!c)
|
|
140
|
+
return red(`usage: /mcp reconnect <name>; servers: ${clients.map((x) => x.name).join(", ") || "(none)"}`);
|
|
141
|
+
await c.close();
|
|
142
|
+
try {
|
|
143
|
+
await c.connect();
|
|
144
|
+
return green(`${c.name} connected, ${c.tools.length} tools; new tools are available from the next session (/clear)`);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
return red(`${c.name}: ${errorText(err)}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (words.length > 0)
|
|
151
|
+
return red("usage: /mcp [reconnect <name>]");
|
|
152
|
+
if (clients.length === 0) {
|
|
153
|
+
return dim(`(no MCP servers) configure them in ${display(ctx.cwd, path.join(ctx.home, "mcp.json"))}, .mcp.json or .jade/mcp.json`);
|
|
154
|
+
}
|
|
155
|
+
const lines = [];
|
|
156
|
+
for (const c of clients) {
|
|
157
|
+
const state = c.status === "connected" ? green("connected") : c.status === "failed" ? red("failed") : yellow(c.status);
|
|
158
|
+
const info = c.serverInfo?.name ? ` · ${c.serverInfo.name}${c.serverInfo.version ? ` ${c.serverInfo.version}` : ""}` : "";
|
|
159
|
+
lines.push(`${bold(c.name)} ${state} ${dim(`${c.entry.layer} · ${display(ctx.cwd, c.entry.file)} · ${describeServer(c.entry.config)}${info}`)}`);
|
|
160
|
+
if (c.error)
|
|
161
|
+
lines.push(red(` ${c.error}`));
|
|
162
|
+
if (c.tools.length)
|
|
163
|
+
lines.push(` tools ${c.tools.map((t) => `${t.name}${t.annotations?.readOnlyHint ? dim(" (read)") : ""}`).join(", ")}`);
|
|
164
|
+
if (c.status === "failed" && c.stderr.length)
|
|
165
|
+
lines.push(dim(c.stderr.map((l) => ` │ ${clip(l, 200)}`).join("\n")));
|
|
166
|
+
}
|
|
167
|
+
return lines.join("\n");
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
async session(ctx) {
|
|
172
|
+
const servers = current;
|
|
173
|
+
if (!servers)
|
|
174
|
+
return;
|
|
175
|
+
await servers.start();
|
|
176
|
+
for (const tool of mcpTools(servers.clients))
|
|
177
|
+
ctx.kernel.tool(tool);
|
|
178
|
+
// 子 Agent(jade/task)只拿声明了只读(readOnlyHint)的工具:另一套实例,和 jade/fs 一样
|
|
179
|
+
const task = ctx.service("task@1");
|
|
180
|
+
if (task)
|
|
181
|
+
for (const tool of mcpTools(servers.clients, { readOnly: true }))
|
|
182
|
+
task.tool(tool);
|
|
183
|
+
const prompts = ctx.service("prompts@1");
|
|
184
|
+
for (const text of instructions(servers.clients))
|
|
185
|
+
prompts?.add({ text, untrusted: true });
|
|
186
|
+
},
|
|
187
|
+
});
|
|
@@ -3,19 +3,29 @@
|
|
|
3
3
|
// 配置兼容 Claude Code 的 .mcp.json:{ "mcpServers": { "<name>": { command, args, env } | { type: "http", url, headers } } }。
|
|
4
4
|
// 读取顺序(同名时后面的覆盖前面的):
|
|
5
5
|
// $JADE_HOME/mcp.json(用户层)、<仓库根目录>/.mcp.json、仓库根目录到工作目录每一级的 .jade/mcp.json(项目层)。
|
|
6
|
-
//
|
|
6
|
+
// 项目层的服务随仓库分发,启动它就是执行仓库指定的命令,所以第一次启动前要用户确认(按配置内容记录,见 index.ts)。
|
|
7
7
|
//
|
|
8
8
|
// 传输:stdio(一行一条 JSON-RPC 消息)和 Streamable HTTP(POST,回复是 JSON 或 SSE)。旧的 HTTP+SSE 传输不支持。
|
|
9
|
-
//
|
|
9
|
+
// 从旧 jade 的 src/mcp.ts 移植;旧 jade 的"插件自带 MCP 配置"(PluginBundle)没有移植:新的插件宿主没有内容包的概念。
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
|
-
import { statSync } from "node:fs";
|
|
12
|
+
import { readFileSync, statSync } from "node:fs";
|
|
13
13
|
import { readFile } from "node:fs/promises";
|
|
14
14
|
import path from "node:path";
|
|
15
|
-
import { projectDirs } from "./
|
|
16
|
-
import { VERSION } from "./sys.js";
|
|
15
|
+
import { projectDirs } from "./project.js";
|
|
17
16
|
export const PROTOCOL_VERSION = "2025-06-18";
|
|
18
|
-
|
|
17
|
+
/** 告诉服务端的客户端版本:jade 的版本(和 jade/tui 一样从 apps/jade/package.json 读) */
|
|
18
|
+
const CLIENT_INFO = {
|
|
19
|
+
name: "jade",
|
|
20
|
+
version: (() => {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8")).version;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return "0.0.0";
|
|
26
|
+
}
|
|
27
|
+
})(),
|
|
28
|
+
};
|
|
19
29
|
/** 一次工具调用结果里文本的上限,超过时保留开头 */
|
|
20
30
|
const MAX_RESULT_CHARS = 60_000;
|
|
21
31
|
const STDERR_LINES = 20;
|
|
@@ -24,36 +34,31 @@ const MAX_TOOL_NAME = 64;
|
|
|
24
34
|
// ---------- 配置 ----------
|
|
25
35
|
/** 用户层在前,项目层从仓库根目录往下;同名的后面覆盖前面 */
|
|
26
36
|
export async function loadMcpConfig(opts) {
|
|
27
|
-
const
|
|
37
|
+
const env = opts.env ?? process.env;
|
|
28
38
|
const files = [
|
|
29
|
-
...(opts.plugins ?? []),
|
|
30
39
|
{ file: path.join(opts.home, "mcp.json"), layer: "user" },
|
|
31
40
|
{ file: path.join(opts.root, ".mcp.json"), layer: "project" },
|
|
32
41
|
...projectDirs(opts.root, opts.cwd).map((d) => ({ file: path.join(d, ".jade", "mcp.json"), layer: "project" })),
|
|
33
42
|
];
|
|
34
43
|
const out = new Map();
|
|
35
44
|
const warnings = [];
|
|
36
|
-
for (const { file, layer
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
catch (err) {
|
|
52
|
-
warnings.push(`${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
servers = json?.mcpServers;
|
|
45
|
+
for (const { file, layer } of files) {
|
|
46
|
+
let text;
|
|
47
|
+
try {
|
|
48
|
+
text = await readFile(file, "utf8");
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let json;
|
|
54
|
+
try {
|
|
55
|
+
json = JSON.parse(text);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
warnings.push(`${file}: ${err instanceof Error ? err.message : String(err)}`);
|
|
59
|
+
continue;
|
|
56
60
|
}
|
|
61
|
+
const servers = json?.mcpServers;
|
|
57
62
|
if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
|
|
58
63
|
warnings.push(`${file}: expected { "mcpServers": { ... } }`);
|
|
59
64
|
continue;
|
|
@@ -79,7 +84,7 @@ export async function loadMcpConfig(opts) {
|
|
|
79
84
|
}
|
|
80
85
|
if (config.cwd && !path.isAbsolute(config.cwd))
|
|
81
86
|
config.cwd = path.resolve(path.dirname(file), config.cwd);
|
|
82
|
-
out.set(name, { name, layer, file, config
|
|
87
|
+
out.set(name, { name, layer, file, config });
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
return { servers: [...out.values()], warnings };
|
|
@@ -637,4 +642,3 @@ export function toBlocks(tool, r) {
|
|
|
637
642
|
function errorText(err) {
|
|
638
643
|
return err instanceof Error ? err.message : String(err);
|
|
639
644
|
}
|
|
640
|
-
//# sourceMappingURL=mcp.js.map
|