@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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// jade/checks:模型改了文件之后,下一次请求模型之前对改过的文件跑项目的检查(类型检查、lint),
|
|
2
|
+
// 把发现的问题附在这批修改的最后一个结果后面(见 checks.ts);/checks 查看、开关;对话里显示检查的结果。
|
|
3
|
+
//
|
|
4
|
+
// 检查在本轮之内、下一次请求模型之前(context.project)运行,不放到 session.afterTurn:模型要在同一轮里看到
|
|
5
|
+
// 自己刚引入的错误并改掉;轮次结束后才检查就得再发起一轮(session.send),等于替用户多说一句话。
|
|
6
|
+
//
|
|
7
|
+
// 检查会执行仓库里的代码(node_modules 里的 tsc、.jade/checks.json 里的命令),每条命令第一次运行前请用户确认,
|
|
8
|
+
// 记在 $JADE_HOME/trust.jsonl(和旧 jade 同一个文件、同一种记录,旧 jade 里确认过的不用再确认)。
|
|
9
|
+
// yolo 模式不问;不能提问时不运行没确认过的命令。
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { definePlugin } from "../../dist/api.js";
|
|
13
|
+
import { changedFiles, checks } from "./checks.js";
|
|
14
|
+
import { bold, dim, display, realPath, repoRoot, TrustFile, yellow } from "./project.js";
|
|
15
|
+
/** 确认记录:同一个目录里的同一条命令只问一次。和旧 jade 的算法相同 */
|
|
16
|
+
const checkHash = (c) => createHash("sha256").update(`jade-check\0${c.cwd}\0${c.command}`).digest("hex");
|
|
17
|
+
/** 展开后最多显示的行数 */
|
|
18
|
+
const MAX_DETAIL_LINES = 40;
|
|
19
|
+
/** 会话 id → 这个会话的检查(/checks 用) */
|
|
20
|
+
const bySession = new Map();
|
|
21
|
+
/** process() 里准备好、session() 里调用:用进程级的确认记录和"一次只问一个问题" */
|
|
22
|
+
let sessionSetup;
|
|
23
|
+
export const checksRenderers = [
|
|
24
|
+
{
|
|
25
|
+
event: "checked",
|
|
26
|
+
render: (data) => {
|
|
27
|
+
const d = data;
|
|
28
|
+
const bad = d.summary.filter((s) => s.problems > 0 || s.others || s.failed);
|
|
29
|
+
const lines = d.report ? d.report.split("\n").slice(1) : [];
|
|
30
|
+
const details = lines.length
|
|
31
|
+
? [...lines.slice(0, MAX_DETAIL_LINES), ...(lines.length > MAX_DETAIL_LINES ? [dim(`… ${lines.length - MAX_DETAIL_LINES} more lines`)] : [])].join("\n")
|
|
32
|
+
: undefined;
|
|
33
|
+
const withDetails = (line) => (details ? { line, details } : { line });
|
|
34
|
+
if (bad.length === 0)
|
|
35
|
+
return withDetails(dim(`✓ checks passed: ${d.summary.map((s) => s.name).join(", ")}`));
|
|
36
|
+
const what = bad.map((s) => s.failed
|
|
37
|
+
? `${s.name} ${s.failed}`
|
|
38
|
+
: `${s.name}: ${[s.problems > 0 ? `${s.problems} problem${s.problems > 1 ? "s" : ""} in changed files` : "", s.others ? `${s.others} new elsewhere` : ""]
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.join(", ")}`);
|
|
41
|
+
return withDetails(yellow(`⚠ checks: ${what.join("; ")}`));
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
export default definePlugin({
|
|
46
|
+
process(ctx) {
|
|
47
|
+
const off = ctx.config.enabled === false || process.env.JADE_CHECKS === "off";
|
|
48
|
+
const trust = new TrustFile(path.join(ctx.home, "trust.jsonl"));
|
|
49
|
+
const renderers = ctx.service("renderers@1");
|
|
50
|
+
if (renderers)
|
|
51
|
+
for (const r of checksRenderers)
|
|
52
|
+
renderers.event(r);
|
|
53
|
+
ctx.service("commands@1")?.register({
|
|
54
|
+
name: "checks",
|
|
55
|
+
args: "[on|off]",
|
|
56
|
+
description: "checks jade runs after the agent edits files (type checker, linter)",
|
|
57
|
+
instant: true,
|
|
58
|
+
async run(args, c) {
|
|
59
|
+
const session = c.sessions.current;
|
|
60
|
+
const checks = session && bySession.get(session.id);
|
|
61
|
+
if (!checks) {
|
|
62
|
+
if (off)
|
|
63
|
+
return dim(`Edit-time checks are turned off${process.env.JADE_CHECKS === "off" ? " by JADE_CHECKS=off" : ` ({"jade/checks": {"enabled": false}} in ${path.join(ctx.home, "config.json")})`}.`);
|
|
64
|
+
return dim(unavailable ?? "Edit-time checks are not available in this session.");
|
|
65
|
+
}
|
|
66
|
+
const arg = args.trim();
|
|
67
|
+
if (arg === "on" || arg === "off") {
|
|
68
|
+
checks.enabled = arg === "on";
|
|
69
|
+
if (arg === "on")
|
|
70
|
+
checks.reset();
|
|
71
|
+
return `checks: ${arg}`;
|
|
72
|
+
}
|
|
73
|
+
if (arg)
|
|
74
|
+
return yellow("usage: /checks [on|off]");
|
|
75
|
+
const files = changedFiles(session.state.messages, realPath(ctx.cwd));
|
|
76
|
+
const found = await checks.resolve(files);
|
|
77
|
+
const lines = [`Edit-time checks are ${checks.enabled ? "on" : "off"} in this session.`];
|
|
78
|
+
if (found.length > 0) {
|
|
79
|
+
lines.push("For the files changed in this session:");
|
|
80
|
+
for (const check of found) {
|
|
81
|
+
const pending = (await trust.has(checkHash(check))) ? "" : ", not confirmed yet";
|
|
82
|
+
lines.push(` ${bold(check.name)} ${dim(`in ${display(ctx.cwd, check.cwd) || "."}${pending}`)}\n ${dim(check.command)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
lines.push(dim(files.length ? "No checks apply to the files changed in this session." : "No files changed in this session yet."));
|
|
87
|
+
lines.push(dim("Detected per file: TypeScript (nearest tsconfig.json + the project's typescript), Python (ruff), Go (go vet).\n" +
|
|
88
|
+
`Add your own in .jade/checks.json or ${path.join(ctx.home, "checks.json")}; JADE_CHECKS=off turns them off.`));
|
|
89
|
+
return lines.join("\n");
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
/** 找不到 shell 时的说明,/checks 显示 */
|
|
93
|
+
let unavailable;
|
|
94
|
+
/** 一次只问一个问题 */
|
|
95
|
+
let asking = Promise.resolve();
|
|
96
|
+
sessionSetup = async (s) => {
|
|
97
|
+
if (off)
|
|
98
|
+
return;
|
|
99
|
+
// 找 shell、杀进程树都在 jade/shell 里(shell@1),这里不再复制一份
|
|
100
|
+
const shell = s.require("shell@1");
|
|
101
|
+
if (!shell.executable) {
|
|
102
|
+
unavailable = `edit-time checks are off: ${shell.unavailable ?? "no shell was found"}`;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const ui = s.service("ui@1");
|
|
106
|
+
const approve = async (check, signal) => {
|
|
107
|
+
const hash = checkHash(check);
|
|
108
|
+
if (await trust.has(hash))
|
|
109
|
+
return true;
|
|
110
|
+
if (s.service("approval@1")?.mode() === "yolo")
|
|
111
|
+
return true;
|
|
112
|
+
if (!ui?.interactive)
|
|
113
|
+
return false;
|
|
114
|
+
const turn = asking.then(async () => {
|
|
115
|
+
if (await trust.has(hash))
|
|
116
|
+
return true;
|
|
117
|
+
signal.throwIfAborted();
|
|
118
|
+
const answer = await ui.select({
|
|
119
|
+
title: `Run ${check.name} after the agent edits files, and show it the problems found?`,
|
|
120
|
+
detail: `${check.command}\nin ${display(s.cwd, check.cwd) || "."}${check.source === "config" ? " (from checks.json)" : " (detected)"}`,
|
|
121
|
+
options: [
|
|
122
|
+
{ label: "Yes, in this project from now on", value: "yes" },
|
|
123
|
+
{ label: "No, not in this session", value: "no" },
|
|
124
|
+
],
|
|
125
|
+
}, signal);
|
|
126
|
+
if (answer === "yes") {
|
|
127
|
+
await trust.add(hash, check.cwd);
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
ui.notify(`${check.name} will not run in this session; /checks on to ask again`);
|
|
131
|
+
return false;
|
|
132
|
+
});
|
|
133
|
+
asking = turn.catch(() => { });
|
|
134
|
+
return turn;
|
|
135
|
+
};
|
|
136
|
+
const cwd = realPath(s.cwd);
|
|
137
|
+
const c = checks({ cwd, root: realPath(repoRoot(cwd)), home: s.home, run: shell.run, which: (bin) => shell.which(bin) ?? null, approve });
|
|
138
|
+
const id = s.session.id;
|
|
139
|
+
bySession.set(id, c);
|
|
140
|
+
await s.effect(() => () => {
|
|
141
|
+
if (bySession.get(id) === c)
|
|
142
|
+
bySession.delete(id);
|
|
143
|
+
});
|
|
144
|
+
s.kernel.hook(c.hook);
|
|
145
|
+
};
|
|
146
|
+
},
|
|
147
|
+
async session(ctx) {
|
|
148
|
+
await sessionSetup?.(ctx);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/checks",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.js",
|
|
6
|
+
"requires": [
|
|
7
|
+
"shell@1"
|
|
8
|
+
],
|
|
9
|
+
"optional": [
|
|
10
|
+
"ui@1",
|
|
11
|
+
"approval@1",
|
|
12
|
+
"renderers@1",
|
|
13
|
+
"commands@1"
|
|
14
|
+
],
|
|
15
|
+
"config": {
|
|
16
|
+
"enabled": {
|
|
17
|
+
"default": true,
|
|
18
|
+
"description": "run the project's checks after the agent edits files; JADE_CHECKS=off turns them off too"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|