@uncarved/jade 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/jade.js +5 -4
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -28
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +156 -1223
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +55 -0
- package/dist/update.js +258 -0
- package/dist/update.js.map +1 -0
- package/package.json +12 -9
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -84
- package/plugins/approval/review.ts +192 -0
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +68 -39
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +112 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +3 -4
- package/{src/tools → plugins/fs}/fs.ts +64 -46
- package/{src/tools → plugins/fs}/grep.ts +4 -3
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/plugins/fs/renderers.ts +138 -0
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +23 -27
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +36 -21
- package/{src → plugins/shell}/sys.ts +19 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +53 -1
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/{src/ui → plugins/tui}/markdown.ts +258 -219
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/plugins/tui/render.ts +67 -0
- package/plugins/tui/screen.ts +268 -0
- package/{src/ui → plugins/tui}/transcript.ts +179 -111
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/plugins/web/web.ts +713 -0
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
- package/plugins-dist/approval/review.js +176 -0
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
- package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/plugins-dist/fs/renderers.js +132 -0
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +22 -19
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
- package/{dist → plugins-dist/shell}/sys.js +20 -44
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/plugins-dist/tui/render.js +61 -0
- package/plugins-dist/tui/screen.js +201 -0
- package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
- package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/plugins-dist/web/web.js +660 -0
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -28
- package/src/install.ts +355 -0
- package/src/main.ts +152 -1263
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -0
- package/LICENSE +0 -21
- package/README.md +0 -198
- package/dist/commands.d.ts +0 -30
- package/dist/commands.js +0 -106
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -104
- package/dist/distro.js +0 -312
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -251
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -22
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -70
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -42
- package/dist/plugins/core.js +0 -190
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -182
- package/dist/plugins/loader.js +0 -253
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -96
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -38
- package/dist/plugins/prompts.js +0 -196
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -9
- package/dist/plugins/repeats.js +0 -90
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -16
- package/dist/plugins/review.js +0 -92
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/provider.d.ts +0 -111
- package/dist/provider.js.map +0 -1
- package/dist/sessions.d.ts +0 -22
- package/dist/sessions.js +0 -53
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -48
- package/dist/sys.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -35
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -35
- package/dist/tools/task.js +0 -89
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -23
- package/dist/tools/web.js +0 -426
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -378
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -33
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -17
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -15
- package/dist/ui/render.js +0 -94
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -98
- package/dist/ui/screen.js +0 -108
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -33
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -45
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -120
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -400
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -239
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -31
- package/src/plugins/core.ts +0 -217
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -386
- package/src/plugins/prompts.ts +0 -234
- package/src/plugins/repeats.ts +0 -96
- package/src/plugins/review.ts +0 -109
- package/src/sessions.ts +0 -61
- package/src/tools/task.ts +0 -109
- package/src/tools/web.ts +0 -451
- package/src/ui/configure.ts +0 -408
- package/src/ui/render.ts +0 -83
- package/src/ui/screen.ts +0 -169
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
|
@@ -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,21 +8,35 @@
|
|
|
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
|
-
|
|
19
|
+
/** 老版本把整个 ChecksState 记在这一个 key 下、每次检查整份重记;恢复老会话时还要读它 */
|
|
19
20
|
export const CHECKS_KEY = "jade/checks";
|
|
21
|
+
/** 每份报告单独一个 key:每次检查日志里只多记这一份,不随会话变长而整份重记 */
|
|
22
|
+
const RESULT_PREFIX = `${CHECKS_KEY}/result/`;
|
|
23
|
+
const OTHERS_KEY = `${CHECKS_KEY}/others`;
|
|
24
|
+
function stateOf(derived) {
|
|
25
|
+
const legacy = derived[CHECKS_KEY];
|
|
26
|
+
const results = { ...legacy?.results };
|
|
27
|
+
for (const [k, v] of Object.entries(derived))
|
|
28
|
+
if (k.startsWith(RESULT_PREFIX))
|
|
29
|
+
results[k.slice(RESULT_PREFIX.length)] = v;
|
|
30
|
+
return { results, others: derived[OTHERS_KEY] ?? legacy?.others ?? {} };
|
|
31
|
+
}
|
|
20
32
|
export const WRITE_TOOLS = new Set(["write_file", "edit_file", "multi_edit"]);
|
|
21
33
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
22
34
|
/** 附给模型的文字上限 */
|
|
23
35
|
const MAX_REPORT_CHARS = 6000;
|
|
24
36
|
/** 每个检查最多列出的问题数 */
|
|
25
37
|
const MAX_PROBLEMS = 30;
|
|
38
|
+
/** 第一次运行时列出的其他文件里的问题条数 */
|
|
39
|
+
const FIRST_RUN_OTHERS = 10;
|
|
26
40
|
const HEADER = "[Checks jade ran after your edits; this is tool output, not a message from the user]";
|
|
27
41
|
const TS_EXT = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
28
42
|
const slash = (p) => p.split(path.sep).join("/");
|
|
@@ -83,7 +97,7 @@ export function parseProblems(output, cwd) {
|
|
|
83
97
|
}
|
|
84
98
|
export function checks(opts) {
|
|
85
99
|
const id = opts.id ?? "jade/checks";
|
|
86
|
-
const which = opts.which ?? ((
|
|
100
|
+
const which = opts.which ?? (() => null);
|
|
87
101
|
const runtime = opts.runtime ?? process.execPath;
|
|
88
102
|
/** 本会话里不再运行的检查:用户拒绝了,或者输出认不出来 */
|
|
89
103
|
const disabled = new Set();
|
|
@@ -244,7 +258,11 @@ export function checks(opts) {
|
|
|
244
258
|
lines.push(...elsewhere.slice(0, 10).map((p) => p.text));
|
|
245
259
|
}
|
|
246
260
|
else if (before === undefined && elsewhere.length > 0) {
|
|
247
|
-
|
|
261
|
+
// 本会话第一次运行,没有基线:列出几条让模型自己判断,改了函数签名弄坏的调用方也在这里
|
|
262
|
+
lines.push(`${check.name}: also ${elsewhere.length} problem${elsewhere.length > 1 ? "s" : ""} in other files. This is the first check in this session, so jade cannot tell which predate your edits; check whether your changes caused any of these:`);
|
|
263
|
+
lines.push(...elsewhere.slice(0, FIRST_RUN_OTHERS).map((p) => p.text));
|
|
264
|
+
if (elsewhere.length > FIRST_RUN_OTHERS)
|
|
265
|
+
lines.push(`… ${elsewhere.length - FIRST_RUN_OTHERS} more`);
|
|
248
266
|
}
|
|
249
267
|
parts.push(lines.join("\n"));
|
|
250
268
|
summary.push({ name: check.name, problems: mine.length, others: before !== undefined && elsewhere.length > before ? elsewhere.length - before : undefined });
|
|
@@ -299,37 +317,50 @@ export function checks(opts) {
|
|
|
299
317
|
async resolve(files) {
|
|
300
318
|
return [...(await plan(files)).values()].map((e) => e.check);
|
|
301
319
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
return inject(messages, state.results);
|
|
328
|
-
},
|
|
329
|
-
},
|
|
330
|
-
],
|
|
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
|
+
},
|
|
331
343
|
},
|
|
332
344
|
};
|
|
333
345
|
return self;
|
|
334
346
|
}
|
|
335
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// 仓库目录、确认记录、显示用的小工具。插件之间不共享代码(只能共享类型),jade/mcp、jade/skills 各有一份。
|
|
2
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
export function realPath(p) {
|
|
6
|
+
try {
|
|
7
|
+
return realpathSync.native(p);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return path.resolve(p);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
|
|
14
|
+
export function repoRoot(cwd) {
|
|
15
|
+
let d = path.resolve(cwd);
|
|
16
|
+
for (;;) {
|
|
17
|
+
if (existsSync(path.join(d, ".git")))
|
|
18
|
+
return d;
|
|
19
|
+
const parent = path.dirname(d);
|
|
20
|
+
if (parent === d)
|
|
21
|
+
return path.resolve(cwd);
|
|
22
|
+
d = parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** 工作目录里的显示成相对路径,外面的显示绝对路径 */
|
|
26
|
+
export function display(cwd, full) {
|
|
27
|
+
const rel = path.relative(cwd, full);
|
|
28
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
29
|
+
return shown.split(path.sep).join("/");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 用户确认过的东西(检查命令),每行一条 { hash, path, at }。
|
|
33
|
+
* 和旧 jade 的 $JADE_HOME/trust.jsonl 同一个文件、同一种格式,旧 jade 里确认过的不用再确认
|
|
34
|
+
*/
|
|
35
|
+
export class TrustFile {
|
|
36
|
+
file;
|
|
37
|
+
#known = new Set();
|
|
38
|
+
constructor(file) {
|
|
39
|
+
this.file = file;
|
|
40
|
+
}
|
|
41
|
+
async has(hash) {
|
|
42
|
+
if (this.#known.has(hash))
|
|
43
|
+
return true;
|
|
44
|
+
let text = "";
|
|
45
|
+
try {
|
|
46
|
+
text = await readFile(this.file, "utf8");
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
for (const line of text.split("\n")) {
|
|
52
|
+
try {
|
|
53
|
+
if (JSON.parse(line).hash === hash) {
|
|
54
|
+
this.#known.add(hash);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// 写到一半的行
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
async add(hash, where) {
|
|
65
|
+
await mkdir(path.dirname(this.file), { recursive: true });
|
|
66
|
+
await appendFile(this.file, `${JSON.stringify({ hash, path: where, at: new Date().toISOString() })}\n`);
|
|
67
|
+
this.#known.add(hash);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
71
|
+
// 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
|
|
72
|
+
const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
73
|
+
const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
|
|
74
|
+
export const dim = paint("2", "22");
|
|
75
|
+
export const yellow = paint("33", "39");
|
|
76
|
+
export const bold = paint("1", "22");
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// jade/commands:斜杠命令的注册表。只登记,不执行:前端解析输入、带着自己的上下文调用 run。
|
|
2
|
+
// 每个调用方一个实例,调用方关闭(停用、被隔离、换会话时的会话作用域)时它注册的命令自动撤销。
|
|
3
|
+
import { definePlugin } from "../../dist/api.js";
|
|
4
|
+
const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
5
|
+
const registry = new Map();
|
|
6
|
+
export default definePlugin({
|
|
7
|
+
process(ctx) {
|
|
8
|
+
ctx.provide("commands@1", (caller) => ({
|
|
9
|
+
register(command) {
|
|
10
|
+
if (typeof command?.name !== "string" || !NAME.test(command.name))
|
|
11
|
+
throw new Error(`invalid command name ${JSON.stringify(command?.name)}`);
|
|
12
|
+
if (typeof command.run !== "function")
|
|
13
|
+
throw new Error(`command /${command.name} has no run function`);
|
|
14
|
+
const key = command.name.toLowerCase();
|
|
15
|
+
const taken = registry.get(key);
|
|
16
|
+
if (taken)
|
|
17
|
+
throw new Error(`command /${command.name} is already registered by ${taken.plugin}`);
|
|
18
|
+
const entry = { command, plugin: caller.plugin };
|
|
19
|
+
registry.set(key, entry);
|
|
20
|
+
const revoke = () => {
|
|
21
|
+
if (registry.get(key) === entry)
|
|
22
|
+
registry.delete(key);
|
|
23
|
+
};
|
|
24
|
+
caller.onDispose(revoke);
|
|
25
|
+
return revoke;
|
|
26
|
+
},
|
|
27
|
+
get: (name) => registry.get(name.toLowerCase()),
|
|
28
|
+
list: () => [...registry.values()]
|
|
29
|
+
.map(({ command: c, plugin }) => ({ name: c.name, ...(c.args ? { args: c.args } : {}), ...(c.description ? { description: c.description } : {}), ...(c.instant ? { instant: true } : {}), plugin }))
|
|
30
|
+
.sort((a, b) => a.name.localeCompare(b.name)),
|
|
31
|
+
}));
|
|
32
|
+
},
|
|
33
|
+
});
|