@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
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 审批规则:按模式、工具的 effect、路径和"总是允许"的规则决定一次工具调用是放行、拒绝还是问用户。
|
|
2
|
+
// 纯判断,不碰界面和日志;那些在 index.ts。
|
|
2
3
|
//
|
|
3
4
|
// 带 url 参数的只读工具(web_fetch)也要问:网页里的提示注入可以让模型把读到的内容拼进 URL 发出去。
|
|
4
|
-
//
|
|
5
|
-
// 模式和"总是允许"的规则由宿主用 Runtime.record 写进日志(derived),关卡从 ctx.derived 读取:
|
|
6
|
-
// 决定只依赖日志里的东西和调用本身,恢复会话后设置仍然有效。
|
|
7
5
|
import { realpathSync, statSync } from "node:fs";
|
|
8
6
|
import path from "node:path";
|
|
9
7
|
import { validate } from "./schema.js";
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 权限模式。ask:改东西先问;auto:工作目录里的改动和只建目录、碰文件的命令不问;
|
|
10
|
+
* plan:不改任何东西,拒绝时告诉模型先给出计划;readonly:不改任何东西(子 Agent 用);yolo:什么都不问
|
|
11
|
+
*/
|
|
12
|
+
export const MODES = ["ask", "auto", "plan", "readonly", "yolo"];
|
|
14
13
|
/** 显示用 */
|
|
15
14
|
export function describeRule(r) {
|
|
16
15
|
if (r.command !== undefined)
|
|
@@ -23,8 +22,6 @@ export function describeRule(r) {
|
|
|
23
22
|
return `${r.tool} from ${r.host}`;
|
|
24
23
|
return r.tool;
|
|
25
24
|
}
|
|
26
|
-
/** 审查要调用模型,内核默认 30 秒的 hook 时限不够(超时按拒绝处理);审查自己会更早放弃并改为问用户 */
|
|
27
|
-
const REVIEW_HOOK_TIMEOUT_MS = 120_000;
|
|
28
25
|
/** 白名单命令里会写文件或执行其他程序的参数 */
|
|
29
26
|
const UNSAFE_ARGS = [/\s--(output|pre|pre-glob|ext-diff|textconv|open-files-in-pager)(=|\s|$)/];
|
|
30
27
|
/** 不管参数是什么都只读的命令(路径另外检查) */
|
|
@@ -378,16 +375,36 @@ function real(p) {
|
|
|
378
375
|
}
|
|
379
376
|
}
|
|
380
377
|
export function policy(opts) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
378
|
+
/**
|
|
379
|
+
* 作为范围的目录(工作目录、登记的目录、规则里的目录)的真实路径,本会话内记住:复合命令的每个参数都要和它们比,
|
|
380
|
+
* 每次都 realpathSync 是一串同步 IO。只记已经存在的;要判断的路径本身每次都重新解析,符号链接可能随时被换掉
|
|
381
|
+
*/
|
|
382
|
+
const bases = new Map();
|
|
383
|
+
const realBase = (dir) => {
|
|
384
|
+
let r = bases.get(dir);
|
|
385
|
+
if (r !== undefined)
|
|
386
|
+
return r;
|
|
387
|
+
try {
|
|
388
|
+
r = realpathSync(dir);
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
return real(dir);
|
|
392
|
+
}
|
|
393
|
+
bases.set(dir, r);
|
|
394
|
+
return r;
|
|
395
|
+
};
|
|
396
|
+
/** 真实路径 target 在真实路径 base 里 */
|
|
397
|
+
const contains = (base, target) => {
|
|
398
|
+
const rel = path.relative(base, target);
|
|
387
399
|
// 只有 ".." 这一段才表示上级目录,名为 "..foo" 的目录仍在里面
|
|
388
400
|
return rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
389
401
|
};
|
|
390
|
-
|
|
402
|
+
/** p 在 base 目录里。按真实路径比较:目录里指向外面的符号链接也算外面 */
|
|
403
|
+
const within = (base, p) => contains(realBase(base), real(path.resolve(opts.cwd, p)));
|
|
404
|
+
const inside = (p) => {
|
|
405
|
+
const target = real(path.resolve(opts.cwd, p));
|
|
406
|
+
return contains(realBase(opts.cwd), target) || (opts.writeRoots ?? []).some((r) => contains(realBase(r), target));
|
|
407
|
+
};
|
|
391
408
|
/** glob 的 pattern 是绝对路径或含 ".." 段时,匹配范围会超出 path */
|
|
392
409
|
const globEscapes = (pattern) => path.isAbsolute(pattern) || pattern.split(/[\\/]/).includes("..");
|
|
393
410
|
/** 以 "." 或 "[" 开头的通配段可能匹配到 ".."(取决于 bash 版本和选项),按越界处理 */
|
|
@@ -440,30 +457,13 @@ export function policy(opts) {
|
|
|
440
457
|
}
|
|
441
458
|
return outside ? "outside" : "inside";
|
|
442
459
|
};
|
|
443
|
-
/**
|
|
444
|
-
* auto 模式下审查放行过的"工具 + 主机",本会话里之后访问同一个主机不再审。
|
|
445
|
-
* URL 带出数据要对方主机由攻击者控制,审查已经认可了这个主机,再逐个 URL 审收益很小、每次却要多等一次模型。
|
|
446
|
-
* 只在内存里:恢复会话后重新审一次;每个决定照样记在 tool.decided 里(I-5)
|
|
447
|
-
*/
|
|
448
|
-
const reviewedSites = new Set();
|
|
449
|
-
const reviewedSite = (call) => {
|
|
450
|
-
const url = call.input?.url;
|
|
451
|
-
const host = call.tool.effect === "read" && typeof url === "string" ? hostOf(url) : undefined;
|
|
452
|
-
return host ? `${call.name} ${host}` : undefined;
|
|
453
|
-
};
|
|
454
460
|
/** 把 classifyBash 的结果变成决定 */
|
|
455
461
|
const bashGate = (r) => r === undefined ? undefined : { decision: r === "outside" ? "ask" : "allow" };
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (legacy === "auto-edit")
|
|
462
|
-
stored.mode = "auto";
|
|
463
|
-
else if (legacy === "readonly" && derived[POLICY_KEY] !== undefined)
|
|
464
|
-
stored.mode = "plan";
|
|
465
|
-
const pending = opts.pendingMode?.();
|
|
466
|
-
return pending ? { ...stored, mode: pending } : stored;
|
|
462
|
+
return {
|
|
463
|
+
absolutePath(input) {
|
|
464
|
+
if (!input || typeof input !== "object" || typeof input.path !== "string")
|
|
465
|
+
return input;
|
|
466
|
+
return { ...input, path: path.resolve(opts.cwd, input.path) };
|
|
467
467
|
},
|
|
468
468
|
ruleFor(call) {
|
|
469
469
|
if (call.name === "bash")
|
|
@@ -511,7 +511,7 @@ export function policy(opts) {
|
|
|
511
511
|
return network && hostOf(input.url) === r.host;
|
|
512
512
|
return !outside;
|
|
513
513
|
};
|
|
514
|
-
const allRules =
|
|
514
|
+
const allRules = rules;
|
|
515
515
|
const ruled = allRules.some(covers);
|
|
516
516
|
/** 复合命令里的一条简单命令被 bash 规则覆盖 */
|
|
517
517
|
const ruledWords = (words) => allRules.some((r) => r.tool === "bash" &&
|
|
@@ -534,7 +534,7 @@ export function policy(opts) {
|
|
|
534
534
|
return {
|
|
535
535
|
decision: "deny",
|
|
536
536
|
reason: mode === "plan"
|
|
537
|
-
? `The session is in plan mode, so ${call.name} is not allowed yet. Finish investigating, then present your plan
|
|
537
|
+
? `The session is in plan mode, so ${call.name} is not allowed yet. Finish investigating, then present your plan for the user to approve as the plan mode instructions describe (with propose_plan when you have it).`
|
|
538
538
|
: `The session is in read-only mode, so ${call.name} is not allowed. Describe the change instead of making it.`,
|
|
539
539
|
};
|
|
540
540
|
}
|
|
@@ -546,49 +546,5 @@ export function policy(opts) {
|
|
|
546
546
|
const gate = isBash ? bashGate(classifyBash(command, { edits: mode === "auto", ruled: ruledWords })) : undefined;
|
|
547
547
|
return gate ?? { decision: "ask" };
|
|
548
548
|
},
|
|
549
|
-
plugin: {
|
|
550
|
-
id,
|
|
551
|
-
version: "0.3.0",
|
|
552
|
-
kernel: "^0.1",
|
|
553
|
-
// log:emit:auto 模式的审查把用掉的 token 记进日志
|
|
554
|
-
needs: ["transform:tool.before", "gate:tool.gate", "log:emit"],
|
|
555
|
-
hooks: [
|
|
556
|
-
{
|
|
557
|
-
kind: "transform",
|
|
558
|
-
point: "tool.before",
|
|
559
|
-
// 让日志里的 tool.decided 记录的是确定的绝对路径,关卡也按它判断
|
|
560
|
-
fn: (call) => {
|
|
561
|
-
const input = call.input;
|
|
562
|
-
if (!input || typeof input !== "object" || typeof input.path !== "string")
|
|
563
|
-
return;
|
|
564
|
-
return { ...call, input: { ...input, path: path.resolve(opts.cwd, input.path) } };
|
|
565
|
-
},
|
|
566
|
-
},
|
|
567
|
-
{
|
|
568
|
-
kind: "gate",
|
|
569
|
-
point: "tool.gate",
|
|
570
|
-
timeoutMs: REVIEW_HOOK_TIMEOUT_MS,
|
|
571
|
-
fn: async (call, ctx) => {
|
|
572
|
-
const settings = self.settings(ctx.derived);
|
|
573
|
-
const result = self.decide(call, settings);
|
|
574
|
-
// 决定记在 tool.decided 里(I-5),重建时不会再审一遍
|
|
575
|
-
if (settings.mode !== "auto" || result.decision !== "ask" || !opts.review)
|
|
576
|
-
return result;
|
|
577
|
-
const site = reviewedSite(call);
|
|
578
|
-
if (site && reviewedSites.has(site))
|
|
579
|
-
return { decision: "allow", reason: `${hostOf(String(call.input.url))} was already approved in this session` };
|
|
580
|
-
const { usage, ...verdict } = await opts.review(call, ctx.signal);
|
|
581
|
-
// 审查调用不经过 model.responded,用量只能记在这里(和压缩一样),界面据此计入会话用量
|
|
582
|
-
if (usage)
|
|
583
|
-
await ctx.emit("reviewed", { toolUseId: call.toolUseId, usage });
|
|
584
|
-
if (site && verdict.decision === "allow")
|
|
585
|
-
reviewedSites.add(site);
|
|
586
|
-
return verdict;
|
|
587
|
-
},
|
|
588
|
-
},
|
|
589
|
-
],
|
|
590
|
-
},
|
|
591
549
|
};
|
|
592
|
-
return self;
|
|
593
550
|
}
|
|
594
|
-
//# sourceMappingURL=policy.js.map
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// auto 模式的审查:规则判断不了、本来要问用户的工具调用,先让模型按用户的请求判断有没有风险。
|
|
2
2
|
// 只会放行或者转给用户,不会替用户拒绝;审查出错、超时、回答看不懂时都转给用户。
|
|
3
3
|
// 审查的结论作为关卡决定记在 tool.decided 里(I-5),恢复会话、重建时不会再审一遍。
|
|
4
|
+
//
|
|
5
|
+
// 从旧 jade 的 plugins/review.ts 移植:模型从 models@1 取(不再由宿主传入),会话消息由 approval 的
|
|
6
|
+
// context.build hook 抄一份。
|
|
4
7
|
import { readFile } from "node:fs/promises";
|
|
5
8
|
import path from "node:path";
|
|
6
9
|
const SYSTEM = "You review actions that an AI coding agent wants to take on the user's computer, so the user does not have to approve each one by hand. " +
|
|
7
10
|
"Decide whether the action can run without asking the user.\n\n" +
|
|
8
11
|
"Answer allow when the action is a reasonable step toward what the user asked for and its effects are limited and recoverable, for example: " +
|
|
9
|
-
"reading files or system information that is not secret; creating or changing files inside the working directory or the
|
|
10
|
-
"running the project's builds, tests, linters, formatters, scripts or small inline scripts that only read data or write inside
|
|
12
|
+
"reading files or system information that is not secret; creating or changing files inside the working directory or the other writable directories listed; " +
|
|
13
|
+
"running the project's builds, tests, linters, formatters, scripts or small inline scripts that only read data or write inside those directories; " +
|
|
11
14
|
"installing the dependencies the project already declares; network requests that only fetch public data and do not send local files, code or secrets.\n\n" +
|
|
12
15
|
"Answer ask when the action could: delete or overwrite data that cannot easily be restored (rm -rf outside build output, git reset --hard, git clean, git push --force, dropping databases); " +
|
|
13
16
|
"change things outside the working directory or global/system state (global installs, system settings, services, scheduled tasks, registry, permissions, shell profiles); " +
|
|
@@ -85,15 +88,21 @@ export function parseVerdict(text) {
|
|
|
85
88
|
}
|
|
86
89
|
return undefined;
|
|
87
90
|
}
|
|
91
|
+
/** 经过膜的调用出错时包着插件的名字和调用点;用户要看的是原因 */
|
|
92
|
+
function reasonOf(err) {
|
|
93
|
+
const e = err instanceof Error && err.name === "PluginError" && err.cause instanceof Error ? err.cause : err;
|
|
94
|
+
return clip(e instanceof Error ? e.message : String(e), 200);
|
|
95
|
+
}
|
|
88
96
|
export function reviewer(opts) {
|
|
89
97
|
return async (call, signal) => {
|
|
90
98
|
const messages = opts.messages();
|
|
91
99
|
const { user, agent } = context(messages);
|
|
92
100
|
const command = call.input?.command;
|
|
93
101
|
const files = typeof command === "string" ? await agentFiles(messages, opts.cwd, command) : [];
|
|
102
|
+
const origin = { by: "plugin", id: "jade/approval" };
|
|
94
103
|
const prompt = [
|
|
95
104
|
`Working directory: ${opts.cwd}`,
|
|
96
|
-
...(opts.
|
|
105
|
+
...(opts.writeRoots?.() ?? []).map((d) => `Also writable like the working directory: ${d}`),
|
|
97
106
|
`Platform: ${process.platform}`,
|
|
98
107
|
"",
|
|
99
108
|
"<user-requests>",
|
|
@@ -110,12 +119,37 @@ export function reviewer(opts) {
|
|
|
110
119
|
`input: ${clip(JSON.stringify(call.input, null, 2), 6000)}`,
|
|
111
120
|
"</action>",
|
|
112
121
|
].join("\n");
|
|
122
|
+
const request = {
|
|
123
|
+
system: [{ text: SYSTEM, stability: "stable", origin, trust: "trusted" }],
|
|
124
|
+
messages: [{ role: "user", content: [{ kind: "text", text: prompt, origin, trust: "untrusted" }] }],
|
|
125
|
+
tools: [],
|
|
126
|
+
};
|
|
127
|
+
const totalMs = opts.timeoutMs ?? 60_000;
|
|
128
|
+
// 不用 AbortSignal.timeout:它的定时器不让进程保持运行,没有别的事在跑时(例如测试里)就永远等不到它
|
|
129
|
+
const expired = new AbortController();
|
|
130
|
+
const deadline = setTimeout(() => expired.abort(new Error("timed out")), totalMs);
|
|
131
|
+
const total = AbortSignal.any([signal, expired.signal]);
|
|
132
|
+
// 共享的模型服务有时让请求排很久的队才开始处理(实测同一个请求 3 秒到 90 多秒),一旦开始几秒内就答完。
|
|
133
|
+
// 所以第一次请求 startTimeoutMs 内还没有任何输出就放弃,重发一次;重发的那次只受总时限约束
|
|
134
|
+
let started = false;
|
|
135
|
+
let retried = false;
|
|
136
|
+
const waiting = new AbortController();
|
|
137
|
+
const timer = setTimeout(() => waiting.abort(), opts.startTimeoutMs ?? 20_000);
|
|
138
|
+
const onDelta = () => {
|
|
139
|
+
started = true;
|
|
140
|
+
clearTimeout(timer);
|
|
141
|
+
};
|
|
113
142
|
try {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
let res;
|
|
144
|
+
try {
|
|
145
|
+
res = await opts.models.complete(request, { signal: AbortSignal.any([total, waiting.signal]), onDelta });
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
if (!waiting.signal.aborted || total.aborted)
|
|
149
|
+
throw err;
|
|
150
|
+
retried = true;
|
|
151
|
+
res = await opts.models.complete(request, { signal: total, onDelta });
|
|
152
|
+
}
|
|
119
153
|
const text = res.content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
|
|
120
154
|
return { ...(parseVerdict(text) ?? { decision: "ask", reason: "The automatic review gave no clear answer." }), usage: res.usage };
|
|
121
155
|
}
|
|
@@ -123,8 +157,20 @@ export function reviewer(opts) {
|
|
|
123
157
|
// 用户中断:照样交回去,关卡的结果不会再被用到
|
|
124
158
|
if (signal.aborted)
|
|
125
159
|
throw err;
|
|
126
|
-
|
|
160
|
+
if (total.aborted) {
|
|
161
|
+
const s = Math.round(totalMs / 1000);
|
|
162
|
+
return {
|
|
163
|
+
decision: "ask",
|
|
164
|
+
reason: started
|
|
165
|
+
? `The automatic review timed out: the model service started answering but did not finish within ${s}s.`
|
|
166
|
+
: `The automatic review timed out: the model service did not start answering within ${s}s${retried ? ", also after a retry" : ""}.`,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return { decision: "ask", reason: `The automatic review failed: ${reasonOf(err)}` };
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
clearTimeout(deadline);
|
|
127
174
|
}
|
|
128
175
|
};
|
|
129
176
|
}
|
|
130
|
-
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// jade/ask:ask_user 工具。模型拿不准、而答案会改变它要做的事时,先问用户再动手。
|
|
2
|
+
//
|
|
3
|
+
// 每个问题给几个选项让用户选,也可以自己输入回答。对话框经 ui@1,不再由宿主私下传入。
|
|
4
|
+
// 前端不能提问(-p、非终端)时不提供这个工具,提示词里也就不会提到它(jade/prompts 按工具是否存在取舍)。
|
|
5
|
+
// 从旧 jade 的 tools/ask.ts 和 main.ts 的 askUser 移植。
|
|
6
|
+
import { definePlugin } from "../../dist/api.js";
|
|
7
|
+
const MAX_QUESTIONS = 4;
|
|
8
|
+
/** 选项的值是序号,"其他" 的值不会和它重复 */
|
|
9
|
+
const OTHER = "other";
|
|
10
|
+
export const DISMISSED = "The user dismissed the questions without answering. Do not ask again: proceed with your best judgment and state your assumptions, or end your turn.";
|
|
11
|
+
/** 回到上一个问题 */
|
|
12
|
+
const BACK = "back";
|
|
13
|
+
/**
|
|
14
|
+
* 用 ui@1 逐个问题让用户选一项,或者选"其他"自己输入。第二个问题起可以回到上一个问题改答案(已经答过的选项标着);
|
|
15
|
+
* 自己输入时取消回到这个问题的选项。选项对话框取消就算没有回答。signal 中止时抛出
|
|
16
|
+
*/
|
|
17
|
+
export function askVia(ui) {
|
|
18
|
+
return async (questions, signal) => {
|
|
19
|
+
if (!ui.interactive)
|
|
20
|
+
return undefined;
|
|
21
|
+
const answers = [];
|
|
22
|
+
let i = 0;
|
|
23
|
+
while (i < questions.length) {
|
|
24
|
+
const q = questions[i];
|
|
25
|
+
const previous = answers[i];
|
|
26
|
+
const typed = previous !== undefined && !q.options.some((o) => o.label === previous) ? previous : undefined;
|
|
27
|
+
const hint = (description, chosen) => {
|
|
28
|
+
const text = [description, chosen ? "your answer" : undefined].filter(Boolean).join(" · ");
|
|
29
|
+
return text ? { hint: text } : {};
|
|
30
|
+
};
|
|
31
|
+
const title = questions.length > 1 ? `${q.question} (${i + 1}/${questions.length})` : q.question;
|
|
32
|
+
const choice = await ui.select({
|
|
33
|
+
title,
|
|
34
|
+
options: [
|
|
35
|
+
...q.options.map((o, k) => ({ label: o.label, value: String(k), ...hint(o.description, o.label === previous) })),
|
|
36
|
+
{ label: "Other (type your answer)", value: OTHER, ...(typed ? { hint: `your answer: ${typed}` } : {}) },
|
|
37
|
+
...(i > 0 ? [{ label: "← Previous question", value: BACK }] : []),
|
|
38
|
+
],
|
|
39
|
+
}, signal);
|
|
40
|
+
signal.throwIfAborted();
|
|
41
|
+
if (choice === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
if (choice === BACK) {
|
|
44
|
+
i--;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const answer = choice === OTHER ? (await ui.input({ title: q.question, ...(typed ? { initial: typed } : {}) }, signal))?.trim() : q.options[Number(choice)]?.label;
|
|
48
|
+
signal.throwIfAborted();
|
|
49
|
+
// 自己输入时取消或什么都没写:回到这个问题重新选
|
|
50
|
+
if (!answer)
|
|
51
|
+
continue;
|
|
52
|
+
answers[i] = answer;
|
|
53
|
+
i++;
|
|
54
|
+
}
|
|
55
|
+
return answers;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export function askUserTool(ask) {
|
|
59
|
+
return {
|
|
60
|
+
name: "ask_user",
|
|
61
|
+
description: "Ask the user one to four questions and wait for the answers. Use it before starting work when the request is ambiguous in a way that changes what you would do " +
|
|
62
|
+
"(scope, approach, a trade-off or preference only the user can decide). Do not ask about things you can find out from the code, docs or tools, " +
|
|
63
|
+
"or that have a sensible default (pick it and say so). Each question offers 2-4 options; the user can also type their own answer. " +
|
|
64
|
+
"Put your recommended option first.",
|
|
65
|
+
inputSchema: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
questions: {
|
|
69
|
+
type: "array",
|
|
70
|
+
items: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
question: { type: "string", description: "The complete question, ending with a question mark" },
|
|
74
|
+
// 模型常给每个问题加一个短标题,名字不定;收下但不用,免得整个调用被拒
|
|
75
|
+
label: { type: "string", description: "Optional short tag; not shown" },
|
|
76
|
+
header: { type: "string", description: "Optional short tag; not shown" },
|
|
77
|
+
options: {
|
|
78
|
+
type: "array",
|
|
79
|
+
items: {
|
|
80
|
+
type: "object",
|
|
81
|
+
properties: {
|
|
82
|
+
label: { type: "string", description: "1-5 words" },
|
|
83
|
+
description: { type: "string", description: "What choosing it means, trade-offs" },
|
|
84
|
+
},
|
|
85
|
+
required: ["label"],
|
|
86
|
+
additionalProperties: false,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ["question", "options"],
|
|
91
|
+
additionalProperties: false,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
required: ["questions"],
|
|
96
|
+
additionalProperties: false,
|
|
97
|
+
},
|
|
98
|
+
// 不碰文件和进程:所有模式(包括 plan)都不用批准
|
|
99
|
+
effect: "read",
|
|
100
|
+
concurrency: "exclusive",
|
|
101
|
+
idempotent: false,
|
|
102
|
+
async execute(input, ctx) {
|
|
103
|
+
const questions = input.questions;
|
|
104
|
+
if (!Array.isArray(questions) || questions.length === 0 || questions.length > MAX_QUESTIONS)
|
|
105
|
+
return { content: `questions must have 1-${MAX_QUESTIONS} items`, isError: true };
|
|
106
|
+
const bad = questions.find((q) => !Array.isArray(q?.options) || q.options.length < 2 || q.options.length > 4);
|
|
107
|
+
if (bad)
|
|
108
|
+
return { content: `each question needs 2-4 options ("${bad.question}" has ${Array.isArray(bad.options) ? bad.options.length : 0})`, isError: true };
|
|
109
|
+
const answers = await ask(questions, ctx.signal);
|
|
110
|
+
if (answers === undefined)
|
|
111
|
+
return { content: DISMISSED };
|
|
112
|
+
return { content: questions.map((q, i) => `Q: ${q.question}\nA: ${answers[i] ?? "(no answer)"}`).join("\n\n") };
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
117
|
+
const args = (input) => (input !== null && typeof input === "object" ? input : {});
|
|
118
|
+
export const askRenderer = {
|
|
119
|
+
tool: "ask_user",
|
|
120
|
+
summary: (input) => {
|
|
121
|
+
const q = args(input).questions;
|
|
122
|
+
return Array.isArray(q) && q.length === 1 ? clip(String(q[0]?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
|
|
123
|
+
},
|
|
124
|
+
// 结果显示用户的回答(旧 jade 每答一题在对话里记一行"问题 → 回答")
|
|
125
|
+
result: ({ text, isError }) => {
|
|
126
|
+
if (isError)
|
|
127
|
+
return undefined;
|
|
128
|
+
if (text === DISMISSED)
|
|
129
|
+
return { line: "dismissed" };
|
|
130
|
+
const pairs = [...text.matchAll(/^Q: (.*)\nA: (.*)$/gm)].map((m) => ({ q: m[1], a: m[2] }));
|
|
131
|
+
if (!pairs.length)
|
|
132
|
+
return undefined;
|
|
133
|
+
return { line: clip(pairs.map((p) => p.a).join(" · "), 200), ...(pairs.length > 1 ? { details: pairs.map((p) => `${p.q} → ${p.a}`).join("\n") } : {}) };
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
export default definePlugin({
|
|
137
|
+
process(ctx) {
|
|
138
|
+
ctx.service("renderers@1")?.tool(askRenderer);
|
|
139
|
+
},
|
|
140
|
+
session(ctx) {
|
|
141
|
+
const ui = ctx.require("ui@1");
|
|
142
|
+
if (ui.interactive)
|
|
143
|
+
ctx.kernel.tool(askUserTool(askVia(ui)));
|
|
144
|
+
},
|
|
145
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// jade/budget:一轮里模型回复的次数达到上限就停下(turn.continue 关卡拒绝,这一轮以 stopped 结束)。
|
|
2
|
+
// 从旧 jade 的 plugins/budget.ts 移植;上限来自配置 maxSteps。
|
|
3
|
+
import { definePlugin } from "../../dist/api.js";
|
|
4
|
+
const DEFAULT_STEPS = 100;
|
|
5
|
+
/** 本轮(最近一条用户输入之后)模型已经回复了几次 */
|
|
6
|
+
export function stepsThisTurn(s) {
|
|
7
|
+
let steps = 0;
|
|
8
|
+
for (let i = s.messages.length - 1; i >= 0; i--) {
|
|
9
|
+
const m = s.messages[i];
|
|
10
|
+
if (m.role === "assistant")
|
|
11
|
+
steps++;
|
|
12
|
+
else if (m.content.some((b) => b.kind !== "tool_result"))
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
return steps;
|
|
16
|
+
}
|
|
17
|
+
export default definePlugin({
|
|
18
|
+
session(ctx) {
|
|
19
|
+
const raw = ctx.config.maxSteps;
|
|
20
|
+
let max = DEFAULT_STEPS;
|
|
21
|
+
if (typeof raw === "number" && Number.isInteger(raw) && raw > 0)
|
|
22
|
+
max = raw;
|
|
23
|
+
else if (raw !== undefined)
|
|
24
|
+
ctx.service("ui@1")?.notify(`jade/budget: maxSteps must be a positive integer, got ${JSON.stringify(raw)}; using ${DEFAULT_STEPS}`, "warning");
|
|
25
|
+
ctx.kernel.hook({
|
|
26
|
+
kind: "gate",
|
|
27
|
+
point: "turn.continue",
|
|
28
|
+
fn: async (s, hook) => {
|
|
29
|
+
if (stepsThisTurn(s) < max)
|
|
30
|
+
return { decision: "abstain" };
|
|
31
|
+
// 告诉用户为什么停下(前端把 <插件 id>/notice 显示成一行)
|
|
32
|
+
await hook.emit("notice", { text: `stopped after ${max} model responses in this turn (config maxSteps); send a message to continue`, level: "warning" });
|
|
33
|
+
return { decision: "deny" };
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/budget",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.js",
|
|
6
|
+
"optional": [
|
|
7
|
+
"ui@1"
|
|
8
|
+
],
|
|
9
|
+
"config": {
|
|
10
|
+
"maxSteps": {
|
|
11
|
+
"default": 100,
|
|
12
|
+
"description": "the most model responses in one turn (after one user message); the turn stops when it is reached"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
// 检查来源:
|
|
9
9
|
// - 自动发现:TypeScript(离文件最近的 tsconfig.json,加上项目里装的 typescript)、Python(PATH 里的 ruff)、Go(go.mod 和 go)
|
|
10
10
|
// - 配置:仓库根目录的 .jade/checks.json 和 $JADE_HOME/checks.json,见 CheckConfigFile
|
|
11
|
-
// 检查会执行仓库里的代码(node_modules 里的 tsc
|
|
11
|
+
// 检查会执行仓库里的代码(node_modules 里的 tsc、配置里的命令),每条命令第一次运行前请用户确认(approve,见 index.ts)。
|
|
12
|
+
// 从旧 jade 的 src/plugins/checks.ts 移植,只是把内核插件换成一个 hook(交给 ctx.kernel.hook)。
|
|
12
13
|
//
|
|
13
14
|
// 只报告改过的文件里的问题;其他文件里的问题只在数量比上一次检查多时报告(例如改了签名,调用方报错)。
|
|
14
15
|
import { createHash } from "node:crypto";
|
|
15
16
|
import { existsSync, realpathSync } from "node:fs";
|
|
16
17
|
import { readFile } from "node:fs/promises";
|
|
17
18
|
import path from "node:path";
|
|
18
|
-
import { which as findExecutable } from "../sys.js";
|
|
19
19
|
/** 老版本把整个 ChecksState 记在这一个 key 下、每次检查整份重记;恢复老会话时还要读它 */
|
|
20
20
|
export const CHECKS_KEY = "jade/checks";
|
|
21
21
|
/** 每份报告单独一个 key:每次检查日志里只多记这一份,不随会话变长而整份重记 */
|
|
@@ -97,7 +97,7 @@ export function parseProblems(output, cwd) {
|
|
|
97
97
|
}
|
|
98
98
|
export function checks(opts) {
|
|
99
99
|
const id = opts.id ?? "jade/checks";
|
|
100
|
-
const which = opts.which ?? ((
|
|
100
|
+
const which = opts.which ?? (() => null);
|
|
101
101
|
const runtime = opts.runtime ?? process.execPath;
|
|
102
102
|
/** 本会话里不再运行的检查:用户拒绝了,或者输出认不出来 */
|
|
103
103
|
const disabled = new Set();
|
|
@@ -317,39 +317,50 @@ export function checks(opts) {
|
|
|
317
317
|
async resolve(files) {
|
|
318
318
|
return [...(await plan(files)).values()].map((e) => e.check);
|
|
319
319
|
},
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
await ctx.emit("checked", { toolUseId: last, files: batch.files, summary, report: text });
|
|
344
|
-
return inject(messages, { ...state.results, [last]: text });
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return inject(messages, state.results);
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
],
|
|
320
|
+
hook: {
|
|
321
|
+
kind: "transform",
|
|
322
|
+
point: "context.project",
|
|
323
|
+
// 检查可能要跑一两分钟,第一次还要等用户确认;出错或超时就跳过,不让这一轮失败
|
|
324
|
+
timeoutMs: 900_000,
|
|
325
|
+
optional: true,
|
|
326
|
+
fn: async (messages, ctx) => {
|
|
327
|
+
const state = stateOf(ctx.derived);
|
|
328
|
+
const batch = self.enabled ? lastBatch(messages) : undefined;
|
|
329
|
+
const last = batch?.ids.at(-1);
|
|
330
|
+
if (batch && last && !(last in state.results)) {
|
|
331
|
+
const { text, summary, others } = await runAll(batch.files, state, ctx);
|
|
332
|
+
if (summary.length > 0 || text) {
|
|
333
|
+
await ctx.record(`${RESULT_PREFIX}${last}`, text);
|
|
334
|
+
// others 是 state.others 加上这次的数,有变化才记
|
|
335
|
+
if (Object.keys(others).some((k) => others[k] !== state.others[k]))
|
|
336
|
+
await ctx.record(OTHERS_KEY, others);
|
|
337
|
+
await ctx.emit("checked", { toolUseId: last, files: batch.files, summary, report: text });
|
|
338
|
+
return inject(messages, { ...state.results, [last]: text });
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return inject(messages, state.results);
|
|
342
|
+
},
|
|
351
343
|
},
|
|
352
344
|
};
|
|
353
345
|
return self;
|
|
354
346
|
}
|
|
355
|
-
|
|
347
|
+
/** 会话里成功改过的文件(/checks 显示用):所有写入调用里结果不是错误的 */
|
|
348
|
+
export function changedFiles(messages, cwd) {
|
|
349
|
+
const ok = new Set(messages.flatMap((m) => (m.role === "user" ? m.content.flatMap((b) => (b.kind === "tool_result" && !b.isError ? [b.toolUseId] : [])) : [])));
|
|
350
|
+
const files = [];
|
|
351
|
+
for (const m of messages) {
|
|
352
|
+
if (m.role !== "assistant")
|
|
353
|
+
continue;
|
|
354
|
+
for (const b of m.content) {
|
|
355
|
+
if (b.kind !== "tool_use" || !WRITE_TOOLS.has(b.name) || !ok.has(b.id))
|
|
356
|
+
continue;
|
|
357
|
+
const p = b.input?.path;
|
|
358
|
+
if (typeof p !== "string")
|
|
359
|
+
continue;
|
|
360
|
+
const full = canonical(path.resolve(cwd, p));
|
|
361
|
+
if (!files.some((f) => sameFile(f, full)))
|
|
362
|
+
files.push(full);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return files;
|
|
366
|
+
}
|