@uncarved/jade 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +161 -150
- package/bin/jade.js +14 -25
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +160 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +311 -0
- package/plugins/approval/plugin.json +22 -0
- package/{src/plugins → plugins/approval}/policy.ts +45 -104
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +80 -39
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +89 -46
- package/{src/tools → plugins/fs}/grep.ts +36 -8
- package/plugins/fs/index.ts +37 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +99 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +213 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +160 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +111 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +258 -0
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +84 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +168 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +343 -0
- package/plugins/todo/index.ts +93 -0
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +619 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +153 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +79 -100
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
- package/plugins/tui/vendor.ts +16 -0
- package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
- package/plugins/undo/index.ts +143 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +64 -31
- package/plugins-dist/approval/index.js +287 -0
- package/plugins-dist/approval/plugin.json +28 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
- package/plugins-dist/fs/index.js +39 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +87 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +181 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +172 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +85 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +231 -0
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +58 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +152 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +284 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +609 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +153 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
- package/plugins-dist/tui/vendor.js +13822 -0
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
- package/plugins-dist/undo/index.js +143 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +56 -29
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +156 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/tools/todo.ts +0 -67
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// jade/scratch:每个会话一个临时目录,放不属于项目的临时文件(试跑的脚本、中间结果),免得弄脏工作目录。
|
|
2
|
+
// 目录在系统临时目录下、按会话 id 命名,恢复会话时还是同一个;不主动删除,由系统清理临时目录。
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { mkdir } from "node:fs/promises";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { definePlugin } from "../../dist/api.js";
|
|
8
|
+
/** 会话 id 对应的临时目录 */
|
|
9
|
+
export const scratchDir = (session) => path.join(os.tmpdir(), "jade-scratch", session);
|
|
10
|
+
export default definePlugin({
|
|
11
|
+
async session(ctx) {
|
|
12
|
+
// 恢复时的 id 来自命令行,还没经过校验;只用单级、不含路径分隔符的名字,免得目录落到 jade-scratch 外面
|
|
13
|
+
if (!/^[A-Za-z0-9_-][A-Za-z0-9._-]*$/.test(ctx.session.id))
|
|
14
|
+
return;
|
|
15
|
+
const created = scratchDir(ctx.session.id);
|
|
16
|
+
await mkdir(created, { recursive: true });
|
|
17
|
+
// 提示词和审批都用真实路径:Windows 上 os.tmpdir() 可能是 8.3 短路径
|
|
18
|
+
const dir = realpathSync.native(created);
|
|
19
|
+
// 在里面改文件和在工作目录里一样对待;会话关闭时撤销
|
|
20
|
+
ctx.service("approval@1")?.allowWrite(dir);
|
|
21
|
+
ctx.service("prompts@1")?.add({
|
|
22
|
+
text: `- Scratch directory for this session: ${dir}\n` +
|
|
23
|
+
" Put temporary files there (throwaway scripts, intermediate output, files that do not belong in the project) instead of the working directory or /tmp.",
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// jade/screenshot:截图工具(见 tool.ts)。本机没有能无头截图的浏览器时不注册这个工具。
|
|
2
|
+
// 模型能不能看图片由 jade/models 的 models@1 给出(JADE_VISION):不能看时不截图。
|
|
3
|
+
// 访问网络的 URL 由 jade/approval 的关卡决定要不要问用户(effect 是 read,路径之外的 URL 会问)。
|
|
4
|
+
import { definePlugin } from "../../dist/api.js";
|
|
5
|
+
import { findBrowser, screenshotTool } from "./tool.js";
|
|
6
|
+
/** 提示词里的一段:有截图工具时才加 */
|
|
7
|
+
const NOTE = "- When the work is visual (a page, a drawing, styles), take a screenshot of the result and look at it instead of guessing from the source.";
|
|
8
|
+
export default definePlugin({
|
|
9
|
+
process(ctx) {
|
|
10
|
+
const renderers = ctx.service("renderers@1");
|
|
11
|
+
// 显示方式和会话无关,登记一次留到进程结束
|
|
12
|
+
renderers?.tool({
|
|
13
|
+
tool: "screenshot",
|
|
14
|
+
summary: (input) => String(input?.url ?? input?.path ?? ""),
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
session(ctx) {
|
|
18
|
+
const browser = findBrowser(process.env);
|
|
19
|
+
if (!browser)
|
|
20
|
+
return;
|
|
21
|
+
const models = ctx.service("models@1");
|
|
22
|
+
const tool = screenshotTool({
|
|
23
|
+
cwd: ctx.cwd,
|
|
24
|
+
browser,
|
|
25
|
+
// 换了模型(/model)之后也按新的配置判断
|
|
26
|
+
available: () => models?.current()?.vision !== false,
|
|
27
|
+
});
|
|
28
|
+
if (!tool)
|
|
29
|
+
return;
|
|
30
|
+
ctx.kernel.tool(tool);
|
|
31
|
+
const remove = ctx.service("prompts@1")?.add({ text: NOTE, stable: false });
|
|
32
|
+
if (remove)
|
|
33
|
+
ctx.effect(() => () => remove());
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// 跨运行时的进程和可执行文件查找:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
|
|
2
|
+
// 和 jade/shell 里的 sys.ts 是同一份:插件之间不共享代码(见 docs/design/jade.md 3.5)。
|
|
3
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
4
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
/**
|
|
7
|
+
* 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
|
|
8
|
+
* 调用方用 try/catch 判断"没装",和 Bun.spawn 同步抛错的用法一致
|
|
9
|
+
*/
|
|
10
|
+
export function spawn(cmd, opts = {}) {
|
|
11
|
+
const child = nodeSpawn(cmd[0], cmd.slice(1), {
|
|
12
|
+
stdio: ["ignore", opts.stdout ?? "pipe", opts.stderr ?? "pipe"],
|
|
13
|
+
// Windows 上不弹出控制台窗口
|
|
14
|
+
windowsHide: true,
|
|
15
|
+
});
|
|
16
|
+
const exited = new Promise((resolve) => child.once("exit", (code) => resolve(code)));
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
child.once("error", reject);
|
|
19
|
+
child.once("spawn", () => {
|
|
20
|
+
child.off("error", reject);
|
|
21
|
+
// 启动之后的错误(例如 kill 一个已经退出的进程)不应该变成未处理的异常
|
|
22
|
+
child.on("error", () => { });
|
|
23
|
+
resolve({ pid: child.pid, exited, kill: () => void child.kill() });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/** which 的结果,按 PATH 和 PATHEXT 记;找不到的过一会儿再查 */
|
|
28
|
+
const found = new Map();
|
|
29
|
+
const MISS_TTL_MS = 30_000;
|
|
30
|
+
/** 在 PATH 里找可执行文件,找不到返回 undefined。Windows 上按 PATHEXT 补扩展名;带路径分隔符时只检查那个文件 */
|
|
31
|
+
export function which(bin) {
|
|
32
|
+
if (bin.includes("/") || (process.platform === "win32" && bin.includes("\\")))
|
|
33
|
+
return lookup(bin);
|
|
34
|
+
const key = `${bin}\0${process.env.PATH ?? process.env.Path ?? ""}\0${process.env.PATHEXT ?? ""}`;
|
|
35
|
+
const hit = found.get(key);
|
|
36
|
+
if (hit && (hit.file !== undefined || Date.now() - hit.at < MISS_TTL_MS))
|
|
37
|
+
return hit.file;
|
|
38
|
+
const file = lookup(bin);
|
|
39
|
+
found.set(key, { file, at: Date.now() });
|
|
40
|
+
return file;
|
|
41
|
+
}
|
|
42
|
+
function lookup(bin) {
|
|
43
|
+
const win = process.platform === "win32";
|
|
44
|
+
const exts = win ? ["", ...(process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean)] : [""];
|
|
45
|
+
const ok = (file) => {
|
|
46
|
+
try {
|
|
47
|
+
if (!statSync(file).isFile())
|
|
48
|
+
return false;
|
|
49
|
+
if (!win)
|
|
50
|
+
accessSync(file, constants.X_OK);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const tryAll = (base) => {
|
|
58
|
+
for (const ext of exts) {
|
|
59
|
+
// Windows 上没有扩展名的文件不能直接执行
|
|
60
|
+
if (win && ext === "" && !path.extname(base))
|
|
61
|
+
continue;
|
|
62
|
+
if (ok(base + ext))
|
|
63
|
+
return base + ext;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
};
|
|
67
|
+
if (bin.includes("/") || (win && bin.includes("\\")))
|
|
68
|
+
return tryAll(path.resolve(bin));
|
|
69
|
+
const dirs = (process.env.PATH ?? process.env.Path ?? "").split(path.delimiter).filter(Boolean);
|
|
70
|
+
for (const dir of dirs) {
|
|
71
|
+
const hit = tryAll(path.join(dir.replace(/^"(.*)"$/, "$1"), bin));
|
|
72
|
+
if (hit)
|
|
73
|
+
return hit;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// 截图工具:用本机的 Chrome / Edge / Chromium 无头模式渲染网页或本地文件,把截图交给模型看。
|
|
2
2
|
//
|
|
3
3
|
// 模型写网页、SVG、样式时看不到效果,只能读源码猜,常常越改越乱,或者反复打开给用户看却说不出结果。
|
|
4
|
-
//
|
|
4
|
+
// 有了截图它能自己检查。模型不能看图片时(JADE_VISION)不给截图,说明原因。
|
|
5
5
|
//
|
|
6
|
-
// effect "read":本地文件按路径、URL 按主机由
|
|
6
|
+
// effect "read":本地文件按路径、URL 按主机由 jade/approval 判断要不要问(URL 本身就能把数据带出去)。
|
|
7
7
|
// 允许 localhost:开发服务器是最常见的用途;访问网络的 URL 会先问用户。
|
|
8
8
|
// 每次用新的临时用户目录,不碰用户自己的浏览器配置和登录状态。
|
|
9
|
+
//
|
|
10
|
+
// 从旧 jade 的 tools/screenshot.ts 移植。
|
|
9
11
|
import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
|
|
10
12
|
import os from "node:os";
|
|
11
13
|
import path from "node:path";
|
|
12
14
|
import { pathToFileURL } from "node:url";
|
|
13
|
-
import { spawn as spawnProc, which } from "
|
|
15
|
+
import { spawn as spawnProc, which } from "./sys.js";
|
|
14
16
|
const DEFAULT_WIDTH = 1280;
|
|
15
17
|
const DEFAULT_HEIGHT = 800;
|
|
16
18
|
const MAX_SIDE = 4000;
|
|
@@ -159,4 +161,3 @@ export function screenshotTool(opts) {
|
|
|
159
161
|
},
|
|
160
162
|
};
|
|
161
163
|
}
|
|
162
|
-
//# sourceMappingURL=screenshot.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// jade/sessions:/clear、/resume、/retry,以及 /resume 用的会话索引。
|
|
2
|
+
// 索引是 $JADE_HOME/state/sessions.jsonl,每行 { id, cwd, title, at }:会话在本进程里第一次收到消息时追加一行。
|
|
3
|
+
// 读的时候按 id 合并:标题取最早的一行,时间取最晚的一行;目录按 cwdKey 比较。
|
|
4
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { definePlugin } from "../../dist/api.js";
|
|
7
|
+
const TITLE_CHARS = 80;
|
|
8
|
+
/** 比较目录用的键:绝对路径、去掉末尾的分隔符;Windows 上不分大小写 */
|
|
9
|
+
export function cwdKey(cwd) {
|
|
10
|
+
const p = path.resolve(cwd);
|
|
11
|
+
return process.platform === "win32" ? p.toLowerCase() : p;
|
|
12
|
+
}
|
|
13
|
+
/** 索引里的全部会话按目录分组,键是 cwdKey;每组最近用过的在前 */
|
|
14
|
+
export async function listAllSessions(file) {
|
|
15
|
+
let text = "";
|
|
16
|
+
try {
|
|
17
|
+
text = await readFile(file, "utf8");
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return new Map();
|
|
21
|
+
}
|
|
22
|
+
const byId = new Map();
|
|
23
|
+
for (const line of text.split("\n")) {
|
|
24
|
+
if (!line.trim())
|
|
25
|
+
continue;
|
|
26
|
+
let e;
|
|
27
|
+
try {
|
|
28
|
+
e = JSON.parse(line);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
continue; // 写到一半的行
|
|
32
|
+
}
|
|
33
|
+
if (typeof e?.id !== "string" || typeof e.cwd !== "string" || typeof e.at !== "string")
|
|
34
|
+
continue;
|
|
35
|
+
const seen = byId.get(e.id);
|
|
36
|
+
byId.set(e.id, seen ? { ...seen, at: e.at > seen.at ? e.at : seen.at } : e);
|
|
37
|
+
}
|
|
38
|
+
const byCwd = new Map();
|
|
39
|
+
for (const s of byId.values()) {
|
|
40
|
+
const key = cwdKey(s.cwd);
|
|
41
|
+
const group = byCwd.get(key);
|
|
42
|
+
if (group)
|
|
43
|
+
group.push(s);
|
|
44
|
+
else
|
|
45
|
+
byCwd.set(key, [s]);
|
|
46
|
+
}
|
|
47
|
+
for (const group of byCwd.values())
|
|
48
|
+
group.sort((a, b) => b.at.localeCompare(a.at));
|
|
49
|
+
return byCwd;
|
|
50
|
+
}
|
|
51
|
+
/** 索引里 cwd 下的会话,最近用过的在前 */
|
|
52
|
+
export async function listSessions(file, cwd) {
|
|
53
|
+
return (await listAllSessions(file)).get(cwdKey(cwd)) ?? [];
|
|
54
|
+
}
|
|
55
|
+
/** 多久以前,例如 "5m ago" */
|
|
56
|
+
export function ago(iso, now = Date.now()) {
|
|
57
|
+
const s = Math.max(0, Math.round((now - Date.parse(iso)) / 1000));
|
|
58
|
+
if (s < 60)
|
|
59
|
+
return "just now";
|
|
60
|
+
if (s < 3600)
|
|
61
|
+
return `${Math.floor(s / 60)}m ago`;
|
|
62
|
+
if (s < 86400)
|
|
63
|
+
return `${Math.floor(s / 3600)}h ago`;
|
|
64
|
+
return `${Math.floor(s / 86400)}d ago`;
|
|
65
|
+
}
|
|
66
|
+
function titleOf(input) {
|
|
67
|
+
if (input.kind !== "message")
|
|
68
|
+
return undefined;
|
|
69
|
+
const text = input.content.flatMap((b) => (b.kind === "text" && b.origin.by === "user" ? [b.text] : [])).join(" ").replace(/\s+/g, " ").trim();
|
|
70
|
+
if (!text)
|
|
71
|
+
return undefined;
|
|
72
|
+
return text.length > TITLE_CHARS ? `${text.slice(0, TITLE_CHARS)}…` : text;
|
|
73
|
+
}
|
|
74
|
+
export default definePlugin({
|
|
75
|
+
process(ctx) {
|
|
76
|
+
const file = path.join(ctx.home, "state", "sessions.jsonl");
|
|
77
|
+
ctx.provide("sessions@1", { list: (cwd) => listSessions(file, cwd) });
|
|
78
|
+
const commands = ctx.require("commands@1");
|
|
79
|
+
commands.register({
|
|
80
|
+
name: "clear",
|
|
81
|
+
description: "start a new session (the current one stays resumable)",
|
|
82
|
+
async run(_args, c) {
|
|
83
|
+
const previous = c.sessions.current;
|
|
84
|
+
await c.sessions.open();
|
|
85
|
+
return previous && previous.state.messages.length > 0 ? `Started a new session. Resume the previous one with /resume or: jade --resume ${previous.id}` : "Started a new session.";
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
commands.register({
|
|
89
|
+
name: "resume",
|
|
90
|
+
args: "[session id]",
|
|
91
|
+
description: "continue an earlier session in this directory",
|
|
92
|
+
async run(args, c) {
|
|
93
|
+
let id = args.trim() || undefined;
|
|
94
|
+
if (!id) {
|
|
95
|
+
const all = (await listSessions(file, ctx.cwd)).filter((s) => s.id !== c.sessions.current?.id).slice(0, 50);
|
|
96
|
+
if (all.length === 0)
|
|
97
|
+
return "No other sessions in this directory.";
|
|
98
|
+
id = await c.ui.select({ title: "Resume which session?", options: all.map((s) => ({ label: s.title || "(untitled)", value: s.id, hint: `${ago(s.at)} · ${s.id}` })) }, c.signal);
|
|
99
|
+
if (!id)
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
// 前端在会话换掉之后重新显示它的对话
|
|
103
|
+
await c.sessions.open({ resume: id });
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
commands.register({
|
|
107
|
+
name: "retry",
|
|
108
|
+
description: "ask the model again after a failed request",
|
|
109
|
+
async run(_args, c) {
|
|
110
|
+
const s = c.sessions.current;
|
|
111
|
+
if (!s || s.state.messages.at(-1)?.role !== "user")
|
|
112
|
+
return "Nothing to retry: the last request did not fail before the model answered.";
|
|
113
|
+
await s.send({ kind: "retry" });
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
session(ctx) {
|
|
118
|
+
const file = path.join(ctx.home, "state", "sessions.jsonl");
|
|
119
|
+
let indexed = false;
|
|
120
|
+
ctx.kernel.hook({
|
|
121
|
+
kind: "observe",
|
|
122
|
+
point: "event",
|
|
123
|
+
fn: async (e) => {
|
|
124
|
+
if (indexed || e.type !== "input.received")
|
|
125
|
+
return;
|
|
126
|
+
const title = titleOf(e.data);
|
|
127
|
+
if (title === undefined)
|
|
128
|
+
return;
|
|
129
|
+
indexed = true;
|
|
130
|
+
const entry = { id: ctx.session.id, cwd: path.resolve(ctx.cwd), title, at: new Date().toISOString() };
|
|
131
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
132
|
+
await appendFile(file, `${JSON.stringify(entry)}\n`);
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// jade/shell:bash 工具,以及后台命令的 bash_output、kill_shell;shell@1 给其他插件执行命令。
|
|
2
|
+
import { definePlugin } from "../../dist/api.js";
|
|
3
|
+
import { shellRenderers } from "./renderers.js";
|
|
4
|
+
import { shellService } from "./service.js";
|
|
5
|
+
import { shellTools } from "./shell.js";
|
|
6
|
+
export default definePlugin({
|
|
7
|
+
process(ctx) {
|
|
8
|
+
// 显示方式和会话无关,登记一次留到进程结束;没有 renderers@1(例如 print)时用前端的默认显示
|
|
9
|
+
const renderers = ctx.service("renderers@1");
|
|
10
|
+
if (renderers)
|
|
11
|
+
for (const r of shellRenderers)
|
|
12
|
+
renderers.tool(r);
|
|
13
|
+
// shell@1:找 shell 和杀进程树只有一份(见 service.ts)
|
|
14
|
+
ctx.provide("shell@1", shellService(typeof ctx.config.shell === "string" ? { shell: ctx.config.shell } : {}));
|
|
15
|
+
},
|
|
16
|
+
async session(ctx) {
|
|
17
|
+
const shell = typeof ctx.config.shell === "string" ? ctx.config.shell : undefined;
|
|
18
|
+
const { tools, executable, unavailable, shutdown } = shellTools({ cwd: ctx.cwd, ...(shell ? { shell } : {}) });
|
|
19
|
+
if (unavailable)
|
|
20
|
+
ctx.service("ui@1")?.notify(unavailable, "warning");
|
|
21
|
+
for (const tool of tools)
|
|
22
|
+
ctx.kernel.tool(tool);
|
|
23
|
+
if (executable) {
|
|
24
|
+
const lines = [`- Shell for the bash tool: ${executable} (POSIX syntax, also on Windows)`];
|
|
25
|
+
// 模型常用 xdg-open、open 打开文件,Git Bash 里没有;start 是 Git 自带的 /usr/bin/start
|
|
26
|
+
if (process.platform === "win32")
|
|
27
|
+
lines.push('- To open a file or URL for the user, run: start "" <path-or-url> (xdg-open and open do not exist)');
|
|
28
|
+
ctx.service("prompts@1")?.add({ text: lines.join("\n") });
|
|
29
|
+
}
|
|
30
|
+
// 会话关闭(换会话、退出)时杀掉还在运行的后台命令
|
|
31
|
+
await ctx.effect(() => shutdown);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/shell",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.js",
|
|
6
|
+
"provides": [
|
|
7
|
+
"shell@1"
|
|
8
|
+
],
|
|
9
|
+
"optional": [
|
|
10
|
+
"ui@1",
|
|
11
|
+
"prompts@1",
|
|
12
|
+
"renderers@1"
|
|
13
|
+
],
|
|
14
|
+
"config": {
|
|
15
|
+
"shell": {
|
|
16
|
+
"description": "the shell the bash tool and shell@1 run; default $JADE_SHELL, else bash (Git Bash on Windows)"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// bash、bash_output、kill_shell 在对话和审批里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植。
|
|
2
|
+
//
|
|
3
|
+
// 运行中的输出不登记 progress:bash 推送的是 { kind, stream, text },前端对 { text } 形式的进度默认逐行显示,
|
|
4
|
+
// 正是想要的;自己写 progress 反而只能把一次推送(可能是好几行、半行)显示成一行。
|
|
5
|
+
// 截断和颜色从旧 jade 的 ui/render.ts、ui/screen.ts 复制:插件之间不共享代码,fs 插件也有一份
|
|
6
|
+
const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
7
|
+
// 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
|
|
8
|
+
const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
9
|
+
const dim = (s) => (colors ? `\x1b[2m${s.replaceAll("\x1b[22m", "\x1b[22m\x1b[2m")}\x1b[22m` : s);
|
|
10
|
+
const args = (input) => (input !== null && typeof input === "object" ? input : {});
|
|
11
|
+
const command = (input) => String(args(input).command ?? "");
|
|
12
|
+
/** 摘要最多这么多个字符 */
|
|
13
|
+
const MAX_SUMMARY = 120;
|
|
14
|
+
/** 预览里的多行文字:每行前面加上标记,最多 max 行 */
|
|
15
|
+
function marked(s, mark, max = 30) {
|
|
16
|
+
const all = s.split("\n");
|
|
17
|
+
const shown = all.slice(0, max).map((l) => `${mark} ${l}`);
|
|
18
|
+
if (all.length > max)
|
|
19
|
+
shown.push(dim(` … ${all.length - max} more lines`));
|
|
20
|
+
return shown.join("\n");
|
|
21
|
+
}
|
|
22
|
+
export const shellRenderers = [
|
|
23
|
+
{
|
|
24
|
+
tool: "bash",
|
|
25
|
+
summary: (input) => clip(command(input).split("\n")[0], MAX_SUMMARY),
|
|
26
|
+
// 摘要省略了内容时(多行或很长的命令),展开后先显示完整的命令
|
|
27
|
+
details: (input) => {
|
|
28
|
+
const lines = command(input).split("\n");
|
|
29
|
+
if (lines.length === 1 && lines[0].length <= MAX_SUMMARY)
|
|
30
|
+
return undefined;
|
|
31
|
+
const shown = lines.slice(0, 200).map((l, i) => dim(`${i === 0 ? "$" : " "} ${l}`));
|
|
32
|
+
if (lines.length > 200)
|
|
33
|
+
shown.push(dim(`… ${lines.length - 200} more lines`));
|
|
34
|
+
return shown.join("\n");
|
|
35
|
+
},
|
|
36
|
+
preview: (input) => marked(command(input), "$"),
|
|
37
|
+
},
|
|
38
|
+
{ tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
|
|
39
|
+
{ tool: "kill_shell", summary: (input) => String(args(input).id ?? "") },
|
|
40
|
+
];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// shell@1:给其他插件执行命令的入口(例如 jade/checks 跑项目的检查)。
|
|
2
|
+
//
|
|
3
|
+
// 找 shell、补 Git Bash 的 PATH、杀进程树这些只有一份,在 shell.ts 里;这里只把它包成服务。
|
|
4
|
+
// 和 bash 工具不同,这里的命令不经过模型和审批:调用方(插件)自己决定要不要问用户。
|
|
5
|
+
// 没有 shell 时 executable 是 undefined,run 会抛错;调用方据此说明"在这台机器上做不了"。
|
|
6
|
+
import { capture, findShell, shellEnv } from "./shell.js";
|
|
7
|
+
import { which } from "./sys.js";
|
|
8
|
+
/** 默认的 shell:JADE_SHELL,否则 bash(Windows 上是 Git Bash) */
|
|
9
|
+
export const shellName = (configured) => (typeof configured === "string" && configured.trim() ? configured : (process.env.JADE_SHELL ?? "bash"));
|
|
10
|
+
export function shellService(opts = {}) {
|
|
11
|
+
const name = shellName(opts.shell);
|
|
12
|
+
const executable = findShell(name);
|
|
13
|
+
if (!executable) {
|
|
14
|
+
const hint = process.platform === "win32" ? "install Git for Windows, or set JADE_SHELL to the path of a bash executable" : "set JADE_SHELL to the path of a shell";
|
|
15
|
+
const unavailable = `${name} was not found; ${hint}`;
|
|
16
|
+
return {
|
|
17
|
+
executable: undefined,
|
|
18
|
+
unavailable,
|
|
19
|
+
run: () => Promise.reject(new Error(unavailable)),
|
|
20
|
+
which,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const env = shellEnv(executable);
|
|
24
|
+
return {
|
|
25
|
+
executable,
|
|
26
|
+
run: (command, o) => capture(executable, env, command, o),
|
|
27
|
+
which,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// 用 bash_output 读取它的新输出,kill_shell 停止它。后台进程只属于本进程,宿主退出时调用 shutdown 全部杀掉。
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
import { runSync, spawn as spawnProc, which } from "
|
|
7
|
+
import { runSync, spawn as spawnProc, which } from "./sys.js";
|
|
8
8
|
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
9
9
|
const MAX_TIMEOUT_MS = 600_000;
|
|
10
10
|
const MAX_OUTPUT_CHARS = 30_000;
|
|
@@ -164,26 +164,7 @@ export function shellTools(opts) {
|
|
|
164
164
|
return { content: `${id} stopped (${status(bg)})` };
|
|
165
165
|
},
|
|
166
166
|
};
|
|
167
|
-
const run =
|
|
168
|
-
signal?.throwIfAborted();
|
|
169
|
-
const proc = await spawn(command, cwd);
|
|
170
|
-
let timedOut = false;
|
|
171
|
-
const kill = () => killTree(executable, env, proc.pid);
|
|
172
|
-
const timer = setTimeout(() => {
|
|
173
|
-
timedOut = true;
|
|
174
|
-
kill();
|
|
175
|
-
}, timeoutMs);
|
|
176
|
-
signal?.addEventListener("abort", kill, { once: true });
|
|
177
|
-
try {
|
|
178
|
-
const [stdout, stderr, code] = await Promise.all([collect(proc.stdout, () => { }), collect(proc.stderr, () => { }), proc.exited]);
|
|
179
|
-
signal?.throwIfAborted();
|
|
180
|
-
return { code: timedOut ? null : code, output: [stdout, stderr].filter(Boolean).join("\n"), timedOut };
|
|
181
|
-
}
|
|
182
|
-
finally {
|
|
183
|
-
clearTimeout(timer);
|
|
184
|
-
signal?.removeEventListener("abort", kill);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
167
|
+
const run = (command, opts) => capture(executable, env, command, opts);
|
|
187
168
|
return {
|
|
188
169
|
tools: [bash, bashOutput, killShell],
|
|
189
170
|
executable,
|
|
@@ -195,6 +176,35 @@ export function shellTools(opts) {
|
|
|
195
176
|
},
|
|
196
177
|
};
|
|
197
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* 执行一条命令并把输出收下来(不经过模型、不推进度);超时或中止时连同子进程一起杀掉。
|
|
181
|
+
* 后台命令和别的插件(`shell@1`,例如 jade/checks)都用它
|
|
182
|
+
*/
|
|
183
|
+
export async function capture(executable, env, command, opts) {
|
|
184
|
+
opts.signal?.throwIfAborted();
|
|
185
|
+
const proc = await spawnProc([executable, "-c", command], {
|
|
186
|
+
cwd: opts.cwd,
|
|
187
|
+
env,
|
|
188
|
+
// 自成进程组,超时/中断时能连同子进程一起杀掉
|
|
189
|
+
detached: process.platform !== "win32",
|
|
190
|
+
});
|
|
191
|
+
let timedOut = false;
|
|
192
|
+
const kill = () => killTree(executable, env, proc.pid);
|
|
193
|
+
const timer = setTimeout(() => {
|
|
194
|
+
timedOut = true;
|
|
195
|
+
kill();
|
|
196
|
+
}, opts.timeoutMs);
|
|
197
|
+
opts.signal?.addEventListener("abort", kill, { once: true });
|
|
198
|
+
try {
|
|
199
|
+
const [stdout, stderr, code] = await Promise.all([collect(proc.stdout, () => { }), collect(proc.stderr, () => { }), proc.exited]);
|
|
200
|
+
opts.signal?.throwIfAborted();
|
|
201
|
+
return { code: timedOut ? null : code, output: [stdout, stderr].filter(Boolean).join("\n"), timedOut };
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
clearTimeout(timer);
|
|
205
|
+
opts.signal?.removeEventListener("abort", kill);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
198
208
|
/**
|
|
199
209
|
* 找到要执行的 shell 程序,找不到返回 undefined。
|
|
200
210
|
*
|
|
@@ -315,4 +325,3 @@ function clip(s) {
|
|
|
315
325
|
const half = MAX_OUTPUT_CHARS / 2;
|
|
316
326
|
return `${s.slice(0, half)}\n… (${s.length - MAX_OUTPUT_CHARS} characters omitted) …\n${s.slice(-half)}`.trimEnd();
|
|
317
327
|
}
|
|
318
|
-
//# sourceMappingURL=shell.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 跨运行时的进程和可执行文件查找:只用 Node 的标准库,Bun 和 Node ≥22.18 下走同一套代码。
|
|
2
2
|
import { spawn as nodeSpawn, spawnSync as nodeSpawnSync } from "node:child_process";
|
|
3
|
-
import { accessSync, constants,
|
|
3
|
+
import { accessSync, constants, statSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import picomatch from "picomatch";
|
|
6
|
-
/** jade 自己的版本号,src 和 dist 下都从包根目录的 package.json 读 */
|
|
7
|
-
export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
8
5
|
const EMPTY = { async *[Symbol.asyncIterator]() { } };
|
|
9
6
|
/**
|
|
10
7
|
* 启动进程,等到确实启动了才返回。程序不存在(ENOENT)等启动错误会 reject,
|
|
@@ -36,23 +33,10 @@ export function spawn(cmd, opts = {}) {
|
|
|
36
33
|
});
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
/** 运行一条命令,返回 stdout 文本和退出码;启动失败时 reject */
|
|
40
|
-
export async function run(cmd, opts = {}) {
|
|
41
|
-
const proc = await spawn(cmd, { cwd: opts.cwd, stderr: "ignore" });
|
|
42
|
-
const [stdout, code] = await Promise.all([text(proc.stdout), proc.exited]);
|
|
43
|
-
return { code, stdout };
|
|
44
|
-
}
|
|
45
36
|
/** 同步运行,忽略输出和错误;用于退出前的清理 */
|
|
46
37
|
export function runSync(cmd, opts = {}) {
|
|
47
38
|
nodeSpawnSync(cmd[0], cmd.slice(1), { stdio: "ignore", windowsHide: true, env: opts.env });
|
|
48
39
|
}
|
|
49
|
-
export async function text(stream) {
|
|
50
|
-
const decoder = new TextDecoder();
|
|
51
|
-
let out = "";
|
|
52
|
-
for await (const chunk of stream)
|
|
53
|
-
out += decoder.decode(chunk, { stream: true });
|
|
54
|
-
return out + decoder.decode();
|
|
55
|
-
}
|
|
56
40
|
/** which 的结果,按 PATH 和 PATHEXT 记;找不到的过一会儿再查(会话中途装上的工具能用上) */
|
|
57
41
|
const found = new Map();
|
|
58
42
|
const MISS_TTL_MS = 30_000;
|
|
@@ -106,28 +90,3 @@ function lookup(bin) {
|
|
|
106
90
|
}
|
|
107
91
|
return undefined;
|
|
108
92
|
}
|
|
109
|
-
/**
|
|
110
|
-
* 编译 glob,返回匹配函数。路径用正斜杠、相对于搜索根目录。
|
|
111
|
-
* 和原先的 Bun.Glob#match 一致:* 也匹配点开头的文件,反斜杠是转义符而不是分隔符
|
|
112
|
-
*/
|
|
113
|
-
export function globMatcher(pattern) {
|
|
114
|
-
return picomatch(pattern, { dot: true, windows: false });
|
|
115
|
-
}
|
|
116
|
-
/** 找 npm 的 CLI 脚本,用当前的 node 运行它:Windows 上 npm 是 .cmd,不经过 shell 不能直接执行 */
|
|
117
|
-
export function npmCommand() {
|
|
118
|
-
const dirs = [path.dirname(process.execPath)];
|
|
119
|
-
const onPath = which(process.platform === "win32" ? "npm.cmd" : "npm");
|
|
120
|
-
if (onPath)
|
|
121
|
-
dirs.push(path.dirname(onPath));
|
|
122
|
-
for (const dir of dirs) {
|
|
123
|
-
for (const cli of [path.join(dir, "node_modules", "npm", "bin", "npm-cli.js"), path.join(dir, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js")]) {
|
|
124
|
-
if (existsSync(cli))
|
|
125
|
-
return [process.execPath, cli];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// POSIX 上 npm 本身就是可执行的脚本
|
|
129
|
-
if (onPath && process.platform !== "win32")
|
|
130
|
-
return [onPath];
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=sys.js.map
|