@uncarved/jade 0.1.3 → 0.2.1
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 +161 -150
- package/bin/jade.js +14 -25
- 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 +160 -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 +311 -0
- package/plugins/approval/plugin.json +22 -0
- package/{src/plugins → plugins/approval}/policy.ts +45 -104
- 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 +80 -39
- 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 +89 -46
- package/{src/tools → plugins/fs}/grep.ts +36 -8
- package/plugins/fs/index.ts +37 -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 +99 -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 +213 -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 +160 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +111 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +258 -0
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +84 -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 +168 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +343 -0
- package/plugins/todo/index.ts +93 -0
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +619 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +153 -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 +79 -100
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
- package/plugins/tui/vendor.ts +16 -0
- package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
- package/plugins/undo/index.ts +143 -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 +64 -31
- package/plugins-dist/approval/index.js +287 -0
- package/plugins-dist/approval/plugin.json +28 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
- 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 +58 -34
- 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 +82 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
- package/plugins-dist/fs/index.js +39 -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 +87 -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 +181 -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 +172 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +85 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +231 -0
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +58 -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 +152 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +284 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +609 -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 +153 -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 +79 -99
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
- package/plugins-dist/tui/vendor.js +13822 -0
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
- package/plugins-dist/undo/index.js +143 -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 +56 -29
- 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 +156 -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/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/tools/todo.ts +0 -67
- 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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/web",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.ts",
|
|
6
|
+
"optional": ["ui@1", "commands@1", "prompts@1", "renderers@1", "task@1"],
|
|
7
|
+
"config": {
|
|
8
|
+
"search": {
|
|
9
|
+
"description": "search services to use, in order: a list or comma-separated names (tinyfish, anysearch, tavily, exa, firecrawl, jina); default: every service with an API key. Keys are read from the environment and $JADE_HOME/.env (/search sets them). $JADE_SEARCH still works"
|
|
10
|
+
},
|
|
11
|
+
"results": {
|
|
12
|
+
"description": "results per web_search, 1-20, default 10; $JADE_SEARCH_RESULTS still works"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// web_fetch、web_search 在对话里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植。
|
|
2
|
+
|
|
3
|
+
import type { ToolRenderer } from "../renderers/index.ts";
|
|
4
|
+
|
|
5
|
+
const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
6
|
+
const args = (input: unknown) => (input !== null && typeof input === "object" ? input : {}) as Record<string, unknown>;
|
|
7
|
+
|
|
8
|
+
export const webRenderers: ToolRenderer[] = [
|
|
9
|
+
{ tool: "web_fetch", summary: (input) => clip(String(args(input).url ?? ""), 120) },
|
|
10
|
+
{ tool: "web_search", summary: (input) => clip(String(args(input).query ?? ""), 120) },
|
|
11
|
+
];
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
// web_fetch 拒绝 localhost 和内网地址:网页里的提示注入不能借它去访问本机的服务。
|
|
9
9
|
// 主机名要先解析,解析出的地址也要检查,否则 127.0.0.1.nip.io 这类域名就能绕过。
|
|
10
10
|
// 检查和 fetch 各自解析一次,DNS 重绑定仍有很小的窗口;要彻底杜绝需要按解析出的 IP 连接。
|
|
11
|
-
// web_search
|
|
11
|
+
// web_search 只在配置了搜索服务时发给模型(见 index.ts),否则模型每次调用都会失败。
|
|
12
|
+
//
|
|
13
|
+
// 从旧 jade 的 tools/web.ts 移植。服务的 key 每次调用时取(search()),/search 改了 key 当前会话立即用上,不用重开会话。
|
|
12
14
|
|
|
13
15
|
import { lookup as dnsLookup } from "node:dns/promises";
|
|
14
16
|
import { isIP } from "node:net";
|
|
15
|
-
import { Parser } from "htmlparser2";
|
|
16
17
|
import type { Block, Tool } from "uncarved";
|
|
18
|
+
import type { Env } from "./env.ts";
|
|
17
19
|
|
|
18
20
|
/** 一次返回的最多字符数,更长的用 offset 分页 */
|
|
19
21
|
const MAX_CHARS = 30_000;
|
|
@@ -31,8 +33,12 @@ const MAX_RESULTS = 20;
|
|
|
31
33
|
const USER_AGENT = "Mozilla/5.0 (compatible; jade/0.1; +https://github.com/MochiNek0/uncarved)";
|
|
32
34
|
|
|
33
35
|
export interface WebOptions {
|
|
34
|
-
/**
|
|
35
|
-
env?:
|
|
36
|
+
/** API key 所在的环境,每次调用时取;默认 process.env */
|
|
37
|
+
env?: Env | (() => Env);
|
|
38
|
+
/** 用哪些搜索服务、按什么顺序(服务名);不给时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序 */
|
|
39
|
+
order?: string[];
|
|
40
|
+
/** 每次搜索返回的条数,默认 DEFAULT_RESULTS */
|
|
41
|
+
results?: number;
|
|
36
42
|
/** 测试用 */
|
|
37
43
|
fetch?: typeof fetch;
|
|
38
44
|
/** 主机名解析出的地址;测试用 */
|
|
@@ -42,17 +48,19 @@ export interface WebOptions {
|
|
|
42
48
|
const defaultLookup = async (hostname: string) => (await dnsLookup(hostname, { all: true })).map((a) => a.address);
|
|
43
49
|
|
|
44
50
|
export interface WebTools {
|
|
45
|
-
/** web_fetch
|
|
51
|
+
/** web_fetch 和 web_search;没有配置搜索服务时 web_search 返回错误,不应发给模型 */
|
|
46
52
|
tools: Tool[];
|
|
53
|
+
/** 当前配了 key 的搜索服务名,按调用顺序 */
|
|
54
|
+
search(): string[];
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
export function webTools(opts: WebOptions = {}): WebTools {
|
|
50
|
-
const env = opts.env ?? process.env;
|
|
58
|
+
const env = typeof opts.env === "function" ? opts.env : () => (opts.env as Env | undefined) ?? process.env;
|
|
51
59
|
const fetchImpl = opts.fetch ?? fetch;
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
return { tools };
|
|
60
|
+
if (opts.order) checkOrder(opts.order);
|
|
61
|
+
const services = () => backends(env(), opts.order, fetchImpl);
|
|
62
|
+
const tools = [webFetchTool(fetchImpl, opts.lookup ?? defaultLookup, () => services().filter((s) => s.read)), webSearchTool(services, opts.results ?? DEFAULT_RESULTS)];
|
|
63
|
+
return { tools, search: () => services().map((s) => s.name) };
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
// ---------- web_fetch ----------
|
|
@@ -78,7 +86,7 @@ const THIN_CHARS = 200;
|
|
|
78
86
|
type Lookup = (hostname: string) => Promise<string[]>;
|
|
79
87
|
|
|
80
88
|
/** readers:能读网页的搜索服务;直接下载不成功时按顺序试 */
|
|
81
|
-
function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: Backend[]): Tool {
|
|
89
|
+
function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: () => Backend[]): Tool {
|
|
82
90
|
const cache = new Map<string, Page>();
|
|
83
91
|
return {
|
|
84
92
|
name: "web_fetch",
|
|
@@ -124,7 +132,7 @@ function webFetchTool(fetchImpl: typeof fetch, lookup: Lookup, readers: Backend[
|
|
|
124
132
|
// 直接下载被拦、出错或只拿到 JS 外壳时,交给能读网页的服务;404 这类明确的结果直接返回
|
|
125
133
|
const failures: string[] = [];
|
|
126
134
|
if ("content" in direct ? direct.retry : direct.thin) {
|
|
127
|
-
for (const r of readers) {
|
|
135
|
+
for (const r of readers()) {
|
|
128
136
|
try {
|
|
129
137
|
page = { at: Date.now(), url: target.href, via: r.name, text: await r.read!(target.href, signal) };
|
|
130
138
|
break;
|
|
@@ -220,7 +228,7 @@ async function download(fetchImpl: typeof fetch, lookup: Lookup, target: URL, si
|
|
|
220
228
|
if (!res.ok) {
|
|
221
229
|
const body = await res.text().catch(() => "");
|
|
222
230
|
return {
|
|
223
|
-
content: `HTTP ${res.status} ${res.statusText} from ${url.href}${body ? `\n${clip(htmlToMarkdown(body).text || body, 1000)}` : ""}`,
|
|
231
|
+
content: `HTTP ${res.status} ${res.statusText} from ${url.href}${body ? `\n${clip((await htmlToMarkdown(body)).text || body, 1000)}` : ""}`,
|
|
224
232
|
isError: true,
|
|
225
233
|
retry: res.status === 403 || res.status === 429 || res.status >= 500,
|
|
226
234
|
};
|
|
@@ -241,7 +249,7 @@ async function download(fetchImpl: typeof fetch, lookup: Lookup, target: URL, si
|
|
|
241
249
|
const charset = /charset=([^;]+)/i.exec(res.headers.get("content-type") ?? "")?.[1]?.trim();
|
|
242
250
|
const raw = decode(buf, charset);
|
|
243
251
|
if (type === "text/html" || type === "application/xhtml+xml" || (!type && /^\s*<(!doctype|html)/i.test(raw))) {
|
|
244
|
-
const { title, text } = htmlToMarkdown(raw, url.href);
|
|
252
|
+
const { title, text } = await htmlToMarkdown(raw, url.href);
|
|
245
253
|
return { at: Date.now(), url: url.href, title, text, thin: text.length < THIN_CHARS };
|
|
246
254
|
}
|
|
247
255
|
if (type.startsWith("text/") || /json|xml|javascript|yaml|toml/.test(type) || !type) {
|
|
@@ -294,9 +302,11 @@ const BLOCKS = new Set(["p", "div", "section", "article", "main", "header", "ul"
|
|
|
294
302
|
|
|
295
303
|
/**
|
|
296
304
|
* 用 htmlparser2 把网页转成 markdown 风格的文本:标题、段落、列表、链接、代码块,去掉脚本、样式和导航。
|
|
297
|
-
* 不追求还原排版,只要模型能读。Node 和 Bun 都能用(Bun 的 HTMLRewriter 在 Node
|
|
305
|
+
* 不追求还原排版,只要模型能读。Node 和 Bun 都能用(Bun 的 HTMLRewriter 在 Node 里没有)。
|
|
306
|
+
* htmlparser2 第一次用到时才加载:导入要几十毫秒,每次启动都付不值得
|
|
298
307
|
*/
|
|
299
|
-
export function htmlToMarkdown(html: string, base?: string): { title?: string; text: string } {
|
|
308
|
+
export async function htmlToMarkdown(html: string, base?: string): Promise<{ title?: string; text: string }> {
|
|
309
|
+
const { Parser } = await import("htmlparser2");
|
|
300
310
|
const out: string[] = [];
|
|
301
311
|
let skip = 0;
|
|
302
312
|
let pre = 0;
|
|
@@ -599,29 +609,51 @@ export const SEARCH_PROVIDERS: SearchProvider[] = [
|
|
|
599
609
|
];
|
|
600
610
|
|
|
601
611
|
/**
|
|
602
|
-
* 配置了 key 的服务,按调用顺序。
|
|
603
|
-
*
|
|
612
|
+
* 配置了 key 的服务,按调用顺序。order 是服务名,决定顺序和范围(没 key 的跳过);
|
|
613
|
+
* 不给时用所有配了 key 的服务,按 SEARCH_PROVIDERS 的顺序
|
|
604
614
|
*/
|
|
605
|
-
function backends(env:
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
function backends(env: Env, order: string[] | undefined, fetchImpl: typeof fetch): Backend[] {
|
|
616
|
+
const list = order?.length ? order.map((n) => SEARCH_PROVIDERS.find((p) => p.name === n)!) : SEARCH_PROVIDERS;
|
|
617
|
+
return list.flatMap((p) => (env[p.env] ? [p.make(env[p.env]!, fetchImpl)] : []));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function checkOrder(order: string[]): void {
|
|
621
|
+
const unknown = order.filter((n) => !SEARCH_PROVIDERS.some((p) => p.name === n));
|
|
622
|
+
if (unknown.length) throw new Error(`unknown search service ${unknown.join(", ")}; choose from ${SEARCH_PROVIDERS.map((p) => p.name).join(", ")}`);
|
|
611
623
|
}
|
|
612
624
|
|
|
613
|
-
/**
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
625
|
+
/**
|
|
626
|
+
* 配置项 search(或旧 jade 的 JADE_SEARCH):逗号分隔的服务名或服务名的数组。不设时返回 undefined;
|
|
627
|
+
* 不认识的服务名抛错,错误信息里带来源 label
|
|
628
|
+
*/
|
|
629
|
+
export function parseOrder(value: unknown, label: string): string[] | undefined {
|
|
630
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
631
|
+
const list = typeof value === "string" ? value.split(",") : Array.isArray(value) && value.every((v) => typeof v === "string") ? (value as string[]) : undefined;
|
|
632
|
+
if (!list) throw new Error(`${label} must be a comma-separated list of search services, got ${JSON.stringify(value)}`);
|
|
633
|
+
const named = list.map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
634
|
+
try {
|
|
635
|
+
checkOrder(named);
|
|
636
|
+
} catch (e) {
|
|
637
|
+
throw new Error(`${label}: ${(e as Error).message}`);
|
|
638
|
+
}
|
|
639
|
+
return named.length ? named : undefined;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** 配置项 results(或旧 jade 的 JADE_SEARCH_RESULTS):每次搜索返回的条数,1 到 MAX_RESULTS */
|
|
643
|
+
export function parseResults(value: unknown, label: string): number {
|
|
644
|
+
const raw = typeof value === "string" ? value.trim() : value;
|
|
645
|
+
if (raw === undefined || raw === null || raw === "") return DEFAULT_RESULTS;
|
|
617
646
|
const n = Number(raw);
|
|
618
|
-
if (!Number.isInteger(n) || n < 1 || n > MAX_RESULTS) throw new Error(
|
|
647
|
+
if (!Number.isInteger(n) || n < 1 || n > MAX_RESULTS) throw new Error(`${label} must be an integer from 1 to ${MAX_RESULTS}, got ${JSON.stringify(value)}`);
|
|
619
648
|
return n;
|
|
620
649
|
}
|
|
621
650
|
|
|
622
651
|
// ---------- web_search ----------
|
|
623
652
|
|
|
624
|
-
|
|
653
|
+
/** 没有配置搜索服务时调用 web_search 的结果(正常情况下这时 web_search 不发给模型) */
|
|
654
|
+
export const SEARCH_OFF = "Web search is not set up. The user can turn it on with the /search command.";
|
|
655
|
+
|
|
656
|
+
function webSearchTool(live: () => Backend[], count: number): Tool {
|
|
625
657
|
return {
|
|
626
658
|
name: "web_search",
|
|
627
659
|
description:
|
|
@@ -639,6 +671,8 @@ function webSearchTool(services: Backend[], count: number): Tool {
|
|
|
639
671
|
async execute(input, { signal }) {
|
|
640
672
|
const { query } = input as { query: string };
|
|
641
673
|
if (!query.trim()) return { content: "query must not be empty", isError: true };
|
|
674
|
+
const services = live();
|
|
675
|
+
if (!services.length) return { content: SEARCH_OFF, isError: true };
|
|
642
676
|
// 按顺序试,出错或没有结果时换下一个
|
|
643
677
|
const failures: string[] = [];
|
|
644
678
|
let failed = false;
|
|
@@ -678,4 +712,3 @@ function errorText(err: unknown): string {
|
|
|
678
712
|
}
|
|
679
713
|
|
|
680
714
|
const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
681
|
-
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
// jade/approval:审批。tool.before 把路径统一成绝对路径,tool.gate 按模式和规则决定,要问时经 ui@1 问用户。
|
|
2
|
+
// auto 模式下规则判断不了、本来要问的调用先让模型审一次(review.ts):它只能放行或转给用户,不能替用户拒绝。
|
|
3
|
+
//
|
|
4
|
+
// 没有这个插件(停用、坏掉、被隔离)时,核心的兜底关卡拒绝所有非只读工具(第 7 节),所以这里出错不会放行。
|
|
5
|
+
// 用户选的"总是允许"记进日志(derived),恢复会话后仍然有效;模式是进程级的,来自配置,可以经 approval@1 改。
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { definePlugin } from "../../dist/api.js";
|
|
8
|
+
import { describeRule, MODES, policy } from "./policy.js";
|
|
9
|
+
import { reviewer } from "./review.js";
|
|
10
|
+
const ANSWERS = ["once", "always", "deny"];
|
|
11
|
+
/** derived 里保存"总是允许"规则的键 */
|
|
12
|
+
const RULES_KEY = "jade/approval/rules";
|
|
13
|
+
/** 等用户回答的默认时限:内核要求 hook 有有限的超时,超时按拒绝处理。配置 askTimeoutMinutes 可以改 */
|
|
14
|
+
const ASK_TIMEOUT_MS = 24 * 60 * 60 * 1000;
|
|
15
|
+
/** askTimeoutMinutes 的上限:内核的定时器最长约 24.8 天 */
|
|
16
|
+
const MAX_ASK_TIMEOUT_MINUTES = 7 * 24 * 60;
|
|
17
|
+
const MAX_DETAIL_CHARS = 2000;
|
|
18
|
+
/** 等工具的审批预览的时限,过了就用默认的 detail */
|
|
19
|
+
const PREVIEW_TIMEOUT_MS = 5000;
|
|
20
|
+
/**
|
|
21
|
+
* 带 URL 的只读工具审查放行之后,完全相同的调用不再审查。不按主机记:同一主机上换一个路径或查询参数
|
|
22
|
+
* 就能把本地数据带出去,正是审查要拦的
|
|
23
|
+
*/
|
|
24
|
+
const reviewedKey = (call) => {
|
|
25
|
+
const url = call.input?.url;
|
|
26
|
+
if (call.tool.effect !== "read" || typeof url !== "string")
|
|
27
|
+
return undefined;
|
|
28
|
+
return `${call.name} ${JSON.stringify(call.input)}`;
|
|
29
|
+
};
|
|
30
|
+
let mode = "ask";
|
|
31
|
+
/** 配置里写错的模式:第一个会话打开时告诉用户(process 里可能还拿不到 ui@1:它的提供者可能排在后面激活) */
|
|
32
|
+
let badMode;
|
|
33
|
+
let askTimeoutMs = ASK_TIMEOUT_MS;
|
|
34
|
+
/** 配置里写错的 askTimeoutMinutes,和 badMode 一样在第一个会话打开时告诉用户 */
|
|
35
|
+
let badTimeout;
|
|
36
|
+
/** 经 allowRead 登记的目录;policy 每次判断时读它 */
|
|
37
|
+
const readRoots = [];
|
|
38
|
+
/** 经 allowWrite 登记的目录;policy 每次判断时读它 */
|
|
39
|
+
const writeRoots = [];
|
|
40
|
+
/** 经 addApprover 登记的审批渠道 */
|
|
41
|
+
const approvers = new Set();
|
|
42
|
+
/** 打开着的会话:会话 id → 判断只读调用能不能不问就执行(allows) */
|
|
43
|
+
const sessionChecks = new Map();
|
|
44
|
+
export default definePlugin({
|
|
45
|
+
process(ctx) {
|
|
46
|
+
const configured = ctx.config.mode;
|
|
47
|
+
if (typeof configured === "string" && MODES.includes(configured))
|
|
48
|
+
mode = configured;
|
|
49
|
+
else if (configured !== undefined)
|
|
50
|
+
badMode = JSON.stringify(configured);
|
|
51
|
+
const minutes = ctx.config.askTimeoutMinutes;
|
|
52
|
+
askTimeoutMs = ASK_TIMEOUT_MS;
|
|
53
|
+
badTimeout = undefined;
|
|
54
|
+
if (typeof minutes === "number" && Number.isFinite(minutes) && minutes > 0 && minutes <= MAX_ASK_TIMEOUT_MINUTES)
|
|
55
|
+
askTimeoutMs = minutes * 60_000;
|
|
56
|
+
else if (minutes !== undefined)
|
|
57
|
+
badTimeout = JSON.stringify(minutes);
|
|
58
|
+
ctx.provide("approval@1", (caller) => ({
|
|
59
|
+
mode: () => mode,
|
|
60
|
+
setMode(next) {
|
|
61
|
+
if (!MODES.includes(next))
|
|
62
|
+
throw new Error(`mode must be one of ${MODES.join(", ")}`);
|
|
63
|
+
mode = next;
|
|
64
|
+
},
|
|
65
|
+
allowRead: (dir) => allow(caller, "allowRead", readRoots, dir),
|
|
66
|
+
allowWrite: (dir) => allow(caller, "allowWrite", writeRoots, dir),
|
|
67
|
+
addApprover(approver) {
|
|
68
|
+
if (caller.layer === "project")
|
|
69
|
+
throw new Error("approval.addApprover: project plugins cannot answer approvals");
|
|
70
|
+
if (typeof approver !== "function")
|
|
71
|
+
throw new Error("approval.addApprover: approver must be a function");
|
|
72
|
+
approvers.add(approver);
|
|
73
|
+
const remove = () => void approvers.delete(approver);
|
|
74
|
+
caller.onDispose(remove);
|
|
75
|
+
return remove;
|
|
76
|
+
},
|
|
77
|
+
allows: (session, call) => call.tool?.effect === "read" && (sessionChecks.get(session)?.(call) ?? false),
|
|
78
|
+
}));
|
|
79
|
+
},
|
|
80
|
+
async session(ctx) {
|
|
81
|
+
const rules = policy({ cwd: ctx.cwd, readRoots, writeRoots });
|
|
82
|
+
const ui = ctx.service("ui@1");
|
|
83
|
+
if (badMode !== undefined) {
|
|
84
|
+
ui?.notify(`jade/approval: mode must be one of ${MODES.join(", ")}, got ${badMode}; using ask`, "warning");
|
|
85
|
+
badMode = undefined;
|
|
86
|
+
}
|
|
87
|
+
if (badTimeout !== undefined) {
|
|
88
|
+
ui?.notify(`jade/approval: askTimeoutMinutes must be a number of minutes between 0 and ${MAX_ASK_TIMEOUT_MINUTES}, got ${badTimeout}; using 24 hours`, "warning");
|
|
89
|
+
badTimeout = undefined;
|
|
90
|
+
}
|
|
91
|
+
const renderers = ctx.service("renderers@1");
|
|
92
|
+
// auto 模式的审查用当前配置的模型;没有 models@1(模型插件被停用)或者配置里关掉时不做审查
|
|
93
|
+
const models = ctx.service("models@1");
|
|
94
|
+
const reviewing = models !== undefined && ctx.config.review !== false;
|
|
95
|
+
/** 最近一次请求里的消息:auto 模式的审查从中取用户最近的请求 */
|
|
96
|
+
const recent = { messages: [] };
|
|
97
|
+
if (reviewing) {
|
|
98
|
+
ctx.kernel.hook({
|
|
99
|
+
kind: "transform",
|
|
100
|
+
point: "context.build",
|
|
101
|
+
fn: (req) => {
|
|
102
|
+
recent.messages = req.messages;
|
|
103
|
+
return req;
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const review = reviewing ? reviewer({ models: models, cwd: ctx.cwd, writeRoots: () => writeRoots, messages: () => recent.messages }) : undefined;
|
|
108
|
+
/** 本会话里审查过一次、放行了的调用 */
|
|
109
|
+
const reviewedCalls = new Set();
|
|
110
|
+
let warned = false;
|
|
111
|
+
/** 本进程里刚选的"总是允许":并发的关卡拿到的 derived 是各自开始时的快照,可能还没有它 */
|
|
112
|
+
const added = [];
|
|
113
|
+
/** 一次只问一个问题;排在后面的问之前重新判断,前面刚选的"总是允许"可能已经覆盖它 */
|
|
114
|
+
let asking = Promise.resolve();
|
|
115
|
+
/** 日志里记下的"总是允许"规则,每次调用工具前取一次:子 Agent 在工具执行期间经 allows 用它 */
|
|
116
|
+
let logged = [];
|
|
117
|
+
const id = ctx.session.id;
|
|
118
|
+
const check = (call) => rules.decide(call, { mode: mode === "yolo" ? "yolo" : "readonly", rules: [...logged, ...added] }).decision === "allow";
|
|
119
|
+
sessionChecks.set(id, check);
|
|
120
|
+
await ctx.effect(() => () => {
|
|
121
|
+
if (sessionChecks.get(id) === check)
|
|
122
|
+
sessionChecks.delete(id);
|
|
123
|
+
});
|
|
124
|
+
ctx.kernel.hook({
|
|
125
|
+
kind: "transform",
|
|
126
|
+
point: "tool.before",
|
|
127
|
+
fn: (call, hook) => {
|
|
128
|
+
logged = hook.derived[RULES_KEY] ?? [];
|
|
129
|
+
return { ...call, input: rules.absolutePath(call.input) };
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
ctx.kernel.hook({
|
|
133
|
+
kind: "gate",
|
|
134
|
+
point: "tool.gate",
|
|
135
|
+
timeoutMs: askTimeoutMs,
|
|
136
|
+
fn: async (call, hook) => {
|
|
137
|
+
const saved = () => {
|
|
138
|
+
const logged = hook.derived[RULES_KEY] ?? [];
|
|
139
|
+
return [...logged, ...added.filter((r) => !logged.some((l) => JSON.stringify(l) === JSON.stringify(r)))];
|
|
140
|
+
};
|
|
141
|
+
const result = rules.decide(call, { mode, rules: saved() });
|
|
142
|
+
if (result.decision !== "ask")
|
|
143
|
+
return result;
|
|
144
|
+
// auto 模式:规则判断不了、本来要问的调用先让模型审一次。审查只能放行或转给用户,不会替用户拒绝
|
|
145
|
+
let why;
|
|
146
|
+
if (review && mode === "auto") {
|
|
147
|
+
const key = reviewedKey(call);
|
|
148
|
+
if (key !== undefined && reviewedCalls.has(key))
|
|
149
|
+
return { decision: "allow", reason: "This exact call was already approved in this session." };
|
|
150
|
+
const verdict = await review(call, hook.signal);
|
|
151
|
+
// 审查调用不经过 model.responded,用量只能记在这里,界面据此计入会话用量
|
|
152
|
+
if (verdict.usage)
|
|
153
|
+
await hook.emit("reviewed", { toolUseId: call.toolUseId, usage: verdict.usage });
|
|
154
|
+
if (verdict.decision === "allow") {
|
|
155
|
+
if (key !== undefined)
|
|
156
|
+
reviewedCalls.add(key);
|
|
157
|
+
return { decision: "allow", reason: verdict.reason };
|
|
158
|
+
}
|
|
159
|
+
why = verdict.reason;
|
|
160
|
+
}
|
|
161
|
+
if (!ui?.interactive && approvers.size === 0) {
|
|
162
|
+
if (!warned) {
|
|
163
|
+
warned = true;
|
|
164
|
+
ui?.notify(`${call.name} needs approval, but this jade cannot ask. To let it make changes in the working directory, ` +
|
|
165
|
+
`set {"jade/approval": {"mode": "auto"}} in ${ctx.home}/config.json`, "warning");
|
|
166
|
+
}
|
|
167
|
+
return { decision: "deny", reason: `${call.name} needs the user's approval, but nobody can approve it in this non-interactive run. Do not retry it; tell the user what you wanted to do.` };
|
|
168
|
+
}
|
|
169
|
+
const turn = asking.then(async () => {
|
|
170
|
+
const again = rules.decide(call, { mode, rules: saved() });
|
|
171
|
+
if (again.decision !== "ask")
|
|
172
|
+
return again;
|
|
173
|
+
const rule = rules.ruleFor(call);
|
|
174
|
+
const shown = (await preview(renderers, call)) ?? detail(call);
|
|
175
|
+
const answer = await ask(ui, {
|
|
176
|
+
title: `Allow ${call.name}?`,
|
|
177
|
+
// 审查转给用户的:先说为什么
|
|
178
|
+
detail: why ? `${why}\n\n${shown}` : shown,
|
|
179
|
+
options: [
|
|
180
|
+
{ label: "Allow once", value: "once" },
|
|
181
|
+
{ label: `Always allow ${describeRule(rule)} in this session`, value: "always" },
|
|
182
|
+
{ label: "Deny", value: "deny" },
|
|
183
|
+
],
|
|
184
|
+
}, hook.signal);
|
|
185
|
+
if (answer === "always") {
|
|
186
|
+
added.push(rule);
|
|
187
|
+
await hook.record(RULES_KEY, saved());
|
|
188
|
+
return { decision: "allow" };
|
|
189
|
+
}
|
|
190
|
+
if (answer === "once")
|
|
191
|
+
return { decision: "allow" };
|
|
192
|
+
return { decision: "deny", reason: "The user denied this tool call. Do not retry it unchanged: adjust, or ask what to do instead." };
|
|
193
|
+
});
|
|
194
|
+
asking = turn.catch(() => { });
|
|
195
|
+
return turn;
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
/** allowRead、allowWrite:把目录登记进 roots,调用方的作用域关闭时撤销 */
|
|
201
|
+
function allow(caller, name, roots, dir) {
|
|
202
|
+
if (caller.layer === "project")
|
|
203
|
+
throw new Error(`approval.${name}: project plugins cannot widen what runs without asking`);
|
|
204
|
+
if (typeof dir !== "string" || !path.isAbsolute(dir))
|
|
205
|
+
throw new Error(`approval.${name}: dir must be an absolute path`);
|
|
206
|
+
const root = path.resolve(dir);
|
|
207
|
+
roots.push(root);
|
|
208
|
+
const remove = () => {
|
|
209
|
+
const i = roots.indexOf(root);
|
|
210
|
+
if (i !== -1)
|
|
211
|
+
roots.splice(i, 1);
|
|
212
|
+
};
|
|
213
|
+
caller.onDispose(remove);
|
|
214
|
+
return remove;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* 把问题同时交给终端(能提问时)和所有审批渠道,返回先到的回答,然后中止其余的。
|
|
218
|
+
* 终端里取消(undefined)算拒绝;渠道返回 undefined、不认识的值或出错算它不回答。都不回答时返回 undefined(拒绝)
|
|
219
|
+
*/
|
|
220
|
+
async function ask(ui, request, signal) {
|
|
221
|
+
const done = new AbortController();
|
|
222
|
+
const stop = () => done.abort(signal.reason);
|
|
223
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
224
|
+
try {
|
|
225
|
+
return await new Promise((resolve, reject) => {
|
|
226
|
+
const channels = [];
|
|
227
|
+
if (ui?.interactive)
|
|
228
|
+
channels.push(ui.select(request, done.signal).then((a) => (a !== undefined && ANSWERS.includes(a) ? a : "deny")));
|
|
229
|
+
for (const approver of approvers) {
|
|
230
|
+
channels.push(Promise.resolve()
|
|
231
|
+
.then(() => approver(request, done.signal))
|
|
232
|
+
.then((a) => (typeof a === "string" && ANSWERS.includes(a) ? a : NONE), () => NONE));
|
|
233
|
+
}
|
|
234
|
+
let pending = channels.length;
|
|
235
|
+
if (pending === 0)
|
|
236
|
+
return resolve(undefined);
|
|
237
|
+
for (const c of channels) {
|
|
238
|
+
c.then((a) => {
|
|
239
|
+
if (a !== NONE)
|
|
240
|
+
resolve(a);
|
|
241
|
+
else if (--pending === 0)
|
|
242
|
+
resolve(undefined);
|
|
243
|
+
}, reject);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
finally {
|
|
248
|
+
signal.removeEventListener("abort", stop);
|
|
249
|
+
done.abort(new Error("answered"));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
const NONE = Symbol("no answer");
|
|
253
|
+
/**
|
|
254
|
+
* 工具自己登记的审批预览(例如文件修改的 diff)。没有登记、返回的不是文字、或者出错时返回 undefined,
|
|
255
|
+
* 用下面的 detail:预览是别的插件的代码,它坏了不能让审批卡住或失败
|
|
256
|
+
*/
|
|
257
|
+
async function preview(renderers, call) {
|
|
258
|
+
let timer;
|
|
259
|
+
try {
|
|
260
|
+
// 预览可能读文件、算 diff;一直不返回时也要能问用户
|
|
261
|
+
const late = new Promise((resolve) => {
|
|
262
|
+
timer = setTimeout(() => resolve(undefined), PREVIEW_TIMEOUT_MS);
|
|
263
|
+
});
|
|
264
|
+
const text = await Promise.race([Promise.resolve(renderers?.forTool(call.name)?.renderer.preview?.(call.input)), late]);
|
|
265
|
+
return typeof text === "string" ? text : undefined;
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
finally {
|
|
271
|
+
clearTimeout(timer);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** 给用户看的调用内容:命令、路径和要写的内容,太长的截断 */
|
|
275
|
+
function detail(call) {
|
|
276
|
+
const input = call.input;
|
|
277
|
+
let text;
|
|
278
|
+
if (typeof input?.command === "string")
|
|
279
|
+
text = input.command;
|
|
280
|
+
else if (typeof input?.path === "string" && typeof input.content === "string")
|
|
281
|
+
text = `${input.path}\n\n${input.content}`;
|
|
282
|
+
else if (typeof input?.path === "string" && typeof input.old_string === "string")
|
|
283
|
+
text = `${input.path}\n\n- ${input.old_string}\n+ ${String(input.new_string)}`;
|
|
284
|
+
else
|
|
285
|
+
text = JSON.stringify(input, null, 2);
|
|
286
|
+
return text.length > MAX_DETAIL_CHARS ? `${text.slice(0, MAX_DETAIL_CHARS)}\n… (${text.length - MAX_DETAIL_CHARS} more characters)` : text;
|
|
287
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/approval",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.js",
|
|
6
|
+
"provides": [
|
|
7
|
+
"approval@1"
|
|
8
|
+
],
|
|
9
|
+
"optional": [
|
|
10
|
+
"ui@1",
|
|
11
|
+
"renderers@1",
|
|
12
|
+
"models@1"
|
|
13
|
+
],
|
|
14
|
+
"config": {
|
|
15
|
+
"mode": {
|
|
16
|
+
"default": "ask",
|
|
17
|
+
"description": "ask: ask before changes; auto: changes inside the working directory and harmless commands go through; plan: change nothing, present a plan; readonly: change nothing; yolo: never ask"
|
|
18
|
+
},
|
|
19
|
+
"askTimeoutMinutes": {
|
|
20
|
+
"default": 1440,
|
|
21
|
+
"description": "how long to wait for an answer to an approval question before denying the call (at most 10080, one week)"
|
|
22
|
+
},
|
|
23
|
+
"review": {
|
|
24
|
+
"default": true,
|
|
25
|
+
"description": "in auto mode, let the model review the calls the rules cannot decide (it can only allow or pass them to you); false turns the review off"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|