@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,153 @@
|
|
|
1
|
+
// @ 引用文件的补全:输入框里打 @ 时找出光标处正在输入的路径、给候选路径排序。
|
|
2
|
+
// 候选从工作目录来(git 仓库里只看版本控制的,和 glob 一样),发送时附上文件内容由 jade/mentions 负责。
|
|
3
|
+
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { readdir } from "node:fs/promises";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
|
|
8
|
+
/** 候选(文件加目录)最多这么多,再多也只是拖慢补全 */
|
|
9
|
+
const MAX_CANDIDATES = 20_000;
|
|
10
|
+
|
|
11
|
+
/** 光标正在输入的 @ 引用:@ 的下标和已经输入的部分;不在引用里时返回 undefined */
|
|
12
|
+
export function mentionAt(value: string, cursor: number): { start: number; query: string } | undefined {
|
|
13
|
+
const m = /(?:^|\s)@("?[^\s"]*)$/.exec(value.slice(0, cursor));
|
|
14
|
+
if (!m) return undefined;
|
|
15
|
+
return { start: cursor - m[1]!.length - 1, query: m[1]!.replace(/^"/, "") };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 补全后的文本:@ 引用加一个空格,含空白的路径加引号 */
|
|
19
|
+
export const mentionText = (p: string) => (/\s/.test(p) ? `@"${p}"` : `@${p}`);
|
|
20
|
+
|
|
21
|
+
/** 候选路径预先算好的小写形式和文件名(目录去掉末尾的 /),每按一个键都要用,不重复算 */
|
|
22
|
+
interface Prepared {
|
|
23
|
+
lower: string;
|
|
24
|
+
base: string;
|
|
25
|
+
}
|
|
26
|
+
const prepared = new WeakMap<readonly string[], Prepared[]>();
|
|
27
|
+
|
|
28
|
+
function prepare(paths: readonly string[]): Prepared[] {
|
|
29
|
+
let out = prepared.get(paths);
|
|
30
|
+
if (!out) {
|
|
31
|
+
out = paths.map((p) => {
|
|
32
|
+
const lower = p.toLowerCase();
|
|
33
|
+
const trimmed = lower.endsWith("/") ? lower.slice(0, -1) : lower;
|
|
34
|
+
return { lower, base: trimmed.slice(trimmed.lastIndexOf("/") + 1) };
|
|
35
|
+
});
|
|
36
|
+
prepared.set(paths, out);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 上一次排序时命中的全部候选(下标)。query 只是在后面追加了字符时,新的命中一定在这些里面
|
|
43
|
+
* (包含 q 加字符的也包含 q,按顺序出现的同理),只筛它们,不用再扫一遍全部路径
|
|
44
|
+
*/
|
|
45
|
+
let last: { paths: readonly string[]; q: string; hits: number[] } | undefined;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 按 query 给候选路径排序:文件名以 query 开头的最前,其次文件名包含、路径包含,
|
|
49
|
+
* 最后是按顺序出现 query 每个字符的模糊匹配;同一档里短的在前
|
|
50
|
+
*/
|
|
51
|
+
export function rankPaths(paths: string[], query: string, limit: number): string[] {
|
|
52
|
+
const q = query.toLowerCase().replaceAll("\\", "/");
|
|
53
|
+
if (!q) return paths.filter((p) => !p.slice(0, -1).includes("/")).slice(0, limit);
|
|
54
|
+
const info = prepare(paths);
|
|
55
|
+
const from = last && last.paths === paths && q.startsWith(last.q) ? last.hits : undefined;
|
|
56
|
+
const scored: { i: number; score: number }[] = [];
|
|
57
|
+
const check = (i: number) => {
|
|
58
|
+
const { lower, base } = info[i]!;
|
|
59
|
+
let score: number;
|
|
60
|
+
if (lower.startsWith(q)) score = 0;
|
|
61
|
+
else if (base.startsWith(q)) score = 1;
|
|
62
|
+
else if (base.includes(q)) score = 2;
|
|
63
|
+
else if (lower.includes(q)) score = 3;
|
|
64
|
+
else if (subsequence(lower, q)) score = 4;
|
|
65
|
+
else return;
|
|
66
|
+
scored.push({ i, score });
|
|
67
|
+
};
|
|
68
|
+
if (from) for (const i of from) check(i);
|
|
69
|
+
else for (let i = 0; i < paths.length; i++) check(i);
|
|
70
|
+
last = { paths, q, hits: scored.map((s) => s.i) };
|
|
71
|
+
const cmp = (a: { i: number; score: number }, b: { i: number; score: number }) =>
|
|
72
|
+
a.score - b.score || paths[a.i]!.length - paths[b.i]!.length || paths[a.i]!.localeCompare(paths[b.i]!);
|
|
73
|
+
// 只要前 limit 条:命中常有上万条,全部排序(localeCompare 很慢)每按一个键要十几毫秒
|
|
74
|
+
const top: { i: number; score: number }[] = [];
|
|
75
|
+
for (const s of scored) {
|
|
76
|
+
if (top.length === limit && cmp(s, top[limit - 1]!) >= 0) continue;
|
|
77
|
+
let at = top.length;
|
|
78
|
+
while (at > 0 && cmp(s, top[at - 1]!) < 0) at--;
|
|
79
|
+
top.splice(at, 0, s);
|
|
80
|
+
if (top.length > limit) top.pop();
|
|
81
|
+
}
|
|
82
|
+
return top.map((s) => paths[s.i]!);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function subsequence(text: string, q: string): boolean {
|
|
86
|
+
let i = 0;
|
|
87
|
+
for (const ch of text) if (ch === q[i] && ++i === q.length) return true;
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @ 补全的候选:工作目录里的文件(git 仓库里只看版本控制的)和它们所在的目录,目录以 / 结尾。
|
|
93
|
+
* 5 秒还没列完就先给已经找到的(大仓库第一次列得慢,不该让输入框卡住)
|
|
94
|
+
*/
|
|
95
|
+
export async function mentionCandidates(cwd: string, signal: AbortSignal = AbortSignal.timeout(5000)): Promise<string[]> {
|
|
96
|
+
const files: string[] = [];
|
|
97
|
+
const dirs = new Set<string>();
|
|
98
|
+
try {
|
|
99
|
+
for await (const full of await listFiles(cwd, signal)) {
|
|
100
|
+
const rel = display(cwd, full);
|
|
101
|
+
files.push(rel);
|
|
102
|
+
for (let i = rel.lastIndexOf("/"); i > 0; i = rel.lastIndexOf("/", i - 1)) {
|
|
103
|
+
const dir = rel.slice(0, i + 1);
|
|
104
|
+
if (dirs.has(dir)) break;
|
|
105
|
+
dirs.add(dir);
|
|
106
|
+
}
|
|
107
|
+
if (files.length + dirs.size >= MAX_CANDIDATES) break;
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
// 列到一半被中止(超时):用已经找到的
|
|
111
|
+
}
|
|
112
|
+
return [...dirs, ...files];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 以下和 jade/fs 的 listFiles、display 相同:插件之间不共享代码(只能共享类型),所以这里留一份
|
|
116
|
+
|
|
117
|
+
const SKIP_DIRS = new Set([".git", "node_modules"]);
|
|
118
|
+
|
|
119
|
+
/** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
|
|
120
|
+
function display(cwd: string, full: string): string {
|
|
121
|
+
const rel = path.relative(cwd, full);
|
|
122
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
123
|
+
return shown.split(path.sep).join("/");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** git 仓库里的文件(版本控制的和没忽略的新文件);不是仓库、没有 git 时 undefined */
|
|
127
|
+
function gitFiles(root: string): Promise<string[] | undefined> {
|
|
128
|
+
return new Promise((resolve) => {
|
|
129
|
+
execFile("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], { cwd: root, maxBuffer: 256 * 1024 * 1024, windowsHide: true }, (err, out) =>
|
|
130
|
+
// 合并冲突中的文件会出现多次
|
|
131
|
+
resolve(err ? undefined : [...new Set(out.split("\0").filter(Boolean))]),
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async function listFiles(root: string, signal: AbortSignal): Promise<Iterable<string> | AsyncIterable<string>> {
|
|
137
|
+
const tracked = await gitFiles(root);
|
|
138
|
+
if (!tracked) return walk(root, signal);
|
|
139
|
+
return tracked.filter((rel) => !rel.split("/").some((seg) => SKIP_DIRS.has(seg))).map((rel) => path.join(root, rel));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function* walk(dir: string, signal: AbortSignal): AsyncIterable<string> {
|
|
143
|
+
signal.throwIfAborted();
|
|
144
|
+
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
145
|
+
for (const e of entries) {
|
|
146
|
+
const full = path.join(dir, e.name);
|
|
147
|
+
if (e.isDirectory()) {
|
|
148
|
+
if (!SKIP_DIRS.has(e.name)) yield* walk(full, signal);
|
|
149
|
+
} else if (e.isFile()) {
|
|
150
|
+
yield full;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/tui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.ts",
|
|
6
|
+
"provides": ["frontend@1", "ui@1"],
|
|
7
|
+
"requires": ["commands@1", "keys@1", "renderers@1"],
|
|
8
|
+
"optional": ["modes@1", "models@1", "compact@1", "sessions@1"],
|
|
9
|
+
"frontend": { "name": "tui", "default": true }
|
|
10
|
+
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
// 宿主显示用的纯函数:工具调用的默认摘要和预览、折叠的工具结果。不依赖运行时和界面状态。
|
|
2
|
-
//
|
|
2
|
+
// 各个工具自己的显示由插件经 renderers@1 登记。
|
|
3
3
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { display } from "../tools/fs.ts";
|
|
7
6
|
import { dim } from "./screen.ts";
|
|
8
7
|
|
|
8
|
+
/** 显示用的路径:工作目录里的用相对路径,其余用绝对路径;都用正斜杠。和 jade/fs 的 display 相同,插件之间不 import 值,所以这里留一份 */
|
|
9
|
+
function display(cwd: string, full: string): string {
|
|
10
|
+
const rel = path.relative(cwd, full);
|
|
11
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
12
|
+
return shown.split(path.sep).join("/");
|
|
13
|
+
}
|
|
14
|
+
|
|
9
15
|
export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
10
16
|
|
|
11
17
|
/**
|
|
@@ -69,8 +69,8 @@ export interface Screen {
|
|
|
69
69
|
select<T>(title: string, choices: Choice<T>[], opts?: { body?: string; signal?: AbortSignal }): Promise<T | undefined>;
|
|
70
70
|
/** 让用户输入一行;取消时返回 undefined。signal 同 select */
|
|
71
71
|
input(title: string, opts?: { initial?: string; mask?: boolean; placeholder?: string; signal?: AbortSignal }): Promise<string | undefined>;
|
|
72
|
-
/**
|
|
73
|
-
readonly draft?: { text(): string; insert(text: string): void; set(text: string): void };
|
|
72
|
+
/** 输入框里还没提交的文字和灰色提示(插件的 ctx.input 用);只有终端界面有 */
|
|
73
|
+
readonly draft?: { text(): string; insert(text: string): void; set(text: string): void; hint(text: string | undefined): void };
|
|
74
74
|
/** 清空已经显示的对话(开始新会话时) */
|
|
75
75
|
clear(): void;
|
|
76
76
|
close(): Promise<void>;
|
|
@@ -163,7 +163,12 @@ export function safeScreen(screen: Screen): Screen {
|
|
|
163
163
|
input: (title, o) => screen.input(s(title), o && { ...o, initial: opt(o.initial), placeholder: opt(o.placeholder) }),
|
|
164
164
|
// 输入框里的 \r 是换行(旧 Mac 的换行符),不是进度条:先换成 \n,terminalSafe 才不会只留最后一段。
|
|
165
165
|
// 输入框里是要发给模型的纯文字,颜色也去掉
|
|
166
|
-
draft: screen.draft && {
|
|
166
|
+
draft: screen.draft && {
|
|
167
|
+
text: () => screen.draft!.text(),
|
|
168
|
+
insert: (t) => screen.draft!.insert(plain(lf(t))),
|
|
169
|
+
set: (t) => screen.draft!.set(plain(lf(t))),
|
|
170
|
+
hint: (t) => screen.draft!.hint(t === undefined ? undefined : plain(lf(t))),
|
|
171
|
+
},
|
|
167
172
|
clear: () => screen.clear(),
|
|
168
173
|
close: () => screen.close(),
|
|
169
174
|
};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
// 把运行时的通知和日志事件显示成对话:模型的流式输出、工具调用和结果、轮次结束的原因,
|
|
2
2
|
// 以及恢复会话时重新显示历史。顺带统计本会话的 token 用量、更新状态栏的上下文用量。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// 只负责显示和统计,不驱动运行时;前端(frontend.ts)用 lastEnd、turnFailed 决定接下来做什么。
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
8
|
-
import type { TaskProgress } from "../tools/task.ts";
|
|
9
|
-
import { renderTodos, type Todo } from "../tools/todo.ts";
|
|
10
|
-
import type { ToolRenderer } from "../plugins/loader.ts";
|
|
11
|
-
import type { PendingCall } from "uncarved";
|
|
6
|
+
import type { Block, EventDataMap, LogEvent, PendingCall, Runtime, TurnEndReason, Usage } from "uncarved";
|
|
7
|
+
import type { EventRenderer, ToolRenderer } from "../renderers/index.ts";
|
|
12
8
|
import { clip, clipStyled, detailsOf, preview, summarize } from "./render.ts";
|
|
13
9
|
import { bold, cyan, dim, green, red, yellow, type Screen } from "./screen.ts";
|
|
14
10
|
|
|
@@ -17,16 +13,20 @@ export type Notice = Parameters<Parameters<Runtime["subscribe"]>[0]>[0];
|
|
|
17
13
|
export interface TranscriptOptions {
|
|
18
14
|
screen: Screen;
|
|
19
15
|
cwd: string;
|
|
20
|
-
/** 子 Agent
|
|
21
|
-
|
|
16
|
+
/** 子 Agent 的用量在它自己的日志里,从这里读;不给就不统计子 Agent 的用量 */
|
|
17
|
+
readLog?(sessionId: string): Promise<LogEvent[]>;
|
|
22
18
|
/** 模型的上下文窗口(状态栏显示用) */
|
|
23
19
|
contextWindow(): number;
|
|
24
20
|
/** 自动压缩的阈值(状态栏显示用) */
|
|
25
21
|
compactAt?(): number;
|
|
22
|
+
/** 每次回复的输出上限(回复被截断时的提示用);没有时说是服务的默认值 */
|
|
23
|
+
maxTokens?(): number | undefined;
|
|
26
24
|
/** 上一轮失败后能否用 /retry 重新请求 */
|
|
27
25
|
canRetry(): boolean;
|
|
28
26
|
/** 插件为自己的工具注册的显示方式(随会话的插件实例变) */
|
|
29
27
|
renderer?(tool: string): { plugin: string; renderer: ToolRenderer } | undefined;
|
|
28
|
+
/** 插件为自己的事件注册的显示方式,按完整的事件类型 */
|
|
29
|
+
eventRenderer?(type: string): { plugin: string; renderer: EventRenderer } | undefined;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export interface Transcript {
|
|
@@ -56,24 +56,38 @@ export interface Transcript {
|
|
|
56
56
|
/** 工具结果折叠起来的完整内容最多这么多行 */
|
|
57
57
|
const MAX_DETAIL_LINES = 2000;
|
|
58
58
|
|
|
59
|
+
/** 插件事件里的用量:只取数字字段 */
|
|
60
|
+
function usageOf(u: unknown): Usage | undefined {
|
|
61
|
+
if (typeof u !== "object" || u === null) return undefined;
|
|
62
|
+
const out: Usage = {};
|
|
63
|
+
for (const k of ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"] as const) {
|
|
64
|
+
const v = (u as Record<string, unknown>)[k];
|
|
65
|
+
if (typeof v === "number" && Number.isFinite(v)) out[k] = v;
|
|
66
|
+
}
|
|
67
|
+
return Object.keys(out).length ? out : undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
59
70
|
const textOf = (blocks: Block[]) => blocks.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
|
|
60
71
|
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
61
72
|
|
|
62
73
|
export function transcript(opts: TranscriptOptions): Transcript {
|
|
63
|
-
const { screen, cwd
|
|
74
|
+
const { screen, cwd } = opts;
|
|
64
75
|
|
|
65
76
|
const usage: Required<Usage> = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
66
77
|
const addUsage = (u?: Usage) => {
|
|
67
78
|
for (const k of Object.keys(usage) as (keyof Usage)[]) usage[k] += u?.[k] ?? 0;
|
|
68
79
|
if (u) screen.status({ spent: { input: usage.inputTokens, output: usage.outputTokens } });
|
|
69
80
|
};
|
|
70
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* 一个事件带来的用量:模型回复;插件事件 data 里的 usage(压缩时的总结调用、auto 模式的审查这类插件自己发的请求);
|
|
83
|
+
* 子 Agent 的用量在它自己的日志里(读不到时不算,不让一个读失败变成没人处理的 rejection)
|
|
84
|
+
*/
|
|
71
85
|
async function countUsage(e: LogEvent) {
|
|
72
86
|
if (e.type === "model.responded") addUsage((e as LogEvent<"model.responded">).data.usage);
|
|
73
|
-
else if (e.
|
|
87
|
+
else if (e.origin.by === "plugin") addUsage(usageOf((e.data as { usage?: unknown } | null)?.usage));
|
|
74
88
|
else if (e.type === "tool.completed") {
|
|
75
89
|
const child = (e as LogEvent<"tool.completed">).data.child;
|
|
76
|
-
if (child) for (const c of await
|
|
90
|
+
if (child && opts.readLog) for (const c of await opts.readLog(child.sessionId).catch(() => [])) await countUsage(c);
|
|
77
91
|
}
|
|
78
92
|
}
|
|
79
93
|
|
|
@@ -131,15 +145,9 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
131
145
|
const activity = (label: string) => {
|
|
132
146
|
if (!replaying) screen.busy(label);
|
|
133
147
|
};
|
|
134
|
-
/** 结果不用再显示的工具调用 */
|
|
135
|
-
const quiet = new Set<string>();
|
|
136
148
|
let streamed = false;
|
|
137
149
|
/** 正在运行、显示着进度的工具 */
|
|
138
150
|
const running = new Set<string>();
|
|
139
|
-
/** 子 Agent 调用过的工具,结束时放进 task 结果的折叠内容里 */
|
|
140
|
-
const steps = new Map<string, string[]>();
|
|
141
|
-
/** 正在运行的子 Agent 的标签,显示在它的进度行开头 */
|
|
142
|
-
const tasks = new Map<string, string>();
|
|
143
151
|
/** 调用行省略了的参数(例如很长的命令),结果出来后放在折叠内容的最前面 */
|
|
144
152
|
const calls = new Map<string, string>();
|
|
145
153
|
/** renderer 的 before 在执行前记下的东西,结果出来时交给它的 result */
|
|
@@ -210,11 +218,8 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
210
218
|
for (const k of Object.keys(usage) as (keyof Usage)[]) usage[k] = 0;
|
|
211
219
|
reportsCache = undefined;
|
|
212
220
|
toolNames.clear();
|
|
213
|
-
quiet.clear();
|
|
214
221
|
for (const id of running) screen.progress(id, undefined);
|
|
215
222
|
running.clear();
|
|
216
|
-
steps.clear();
|
|
217
|
-
tasks.clear();
|
|
218
223
|
calls.clear();
|
|
219
224
|
befores.clear();
|
|
220
225
|
inputs.clear();
|
|
@@ -263,34 +268,23 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
263
268
|
case "awaiting":
|
|
264
269
|
return;
|
|
265
270
|
case "tool-progress":
|
|
266
|
-
return renderProgress(n.toolUseId, n.update
|
|
271
|
+
return renderProgress(n.toolUseId, n.update);
|
|
267
272
|
case "event":
|
|
268
273
|
return renderEvent(n.event);
|
|
269
274
|
}
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (p.kind === "task-start") {
|
|
280
|
-
tasks.set(toolUseId, p.description);
|
|
281
|
-
return taskLine("starting");
|
|
282
|
-
}
|
|
283
|
-
if (p.kind === "task-model") return taskLine("thinking");
|
|
284
|
-
if (p.kind === "task-tool") {
|
|
285
|
-
// 要用户批准的调用在审批时显示
|
|
286
|
-
if (p.decision === "ask") return;
|
|
287
|
-
const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summary(p.name, p.input)})`;
|
|
288
|
-
steps.set(toolUseId, [...(steps.get(toolUseId) ?? []), step]);
|
|
289
|
-
return taskLine(step);
|
|
277
|
+
/** 工具的进度:有 renderer 的 progress 时由它换成一行;否则 { text } 形式的按输出逐行显示(例如 bash),其他的不显示 */
|
|
278
|
+
function renderProgress(toolUseId: string, update: unknown) {
|
|
279
|
+
const name = toolNames.get(toolUseId) ?? "?";
|
|
280
|
+
if (opts.renderer?.(name)?.renderer.progress) {
|
|
281
|
+
const line = customSync(name, (r) => r.progress?.(update, { toolUseId, summary }));
|
|
282
|
+
if (typeof line === "string" && line) progress(toolUseId, clipStyled(line.split("\n")[0]!, 200));
|
|
283
|
+
return;
|
|
290
284
|
}
|
|
291
|
-
|
|
292
|
-
if (typeof
|
|
293
|
-
for (const l of
|
|
285
|
+
const text = (update as { text?: unknown } | null)?.text;
|
|
286
|
+
if (typeof text !== "string") return;
|
|
287
|
+
for (const l of text.replace(/\n$/, "").split("\n")) progress(toolUseId, dim(` │ ${clip(l, 200)}`), { output: true });
|
|
294
288
|
}
|
|
295
289
|
|
|
296
290
|
function renderEvent(e: LogEvent) {
|
|
@@ -330,15 +324,18 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
330
324
|
if (d.decision === "deny") screen.log(red(`✗ ${head}`) + dim(d.reason ? ` — ${clip(d.reason, 200)}` : ""), { id: d.toolUseId, details: full });
|
|
331
325
|
else {
|
|
332
326
|
activity(`Running ${name}`);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
327
|
+
// 用户批准的调用在审批时已经显示过;重新显示历史时没有审批这一步
|
|
328
|
+
if (d.decidedBy !== "user" || replaying) {
|
|
329
|
+
const own = customSync(name, (r) => r.call?.(d.input));
|
|
330
|
+
if (typeof own === "string" && own) {
|
|
331
|
+
// renderer 给的内容:第一行是调用行(结果接在它后面),其余的行不折叠
|
|
332
|
+
const [first, ...rest] = own.split("\n");
|
|
333
|
+
screen.log(cyan("● ") + first, { id: d.toolUseId, details: full });
|
|
334
|
+
if (rest.length) screen.log(rest.join("\n"));
|
|
335
|
+
} else {
|
|
336
|
+
// auto 模式下审查放行的带着理由
|
|
337
|
+
screen.log(cyan("● ") + head + (d.reason ? dim(` — ${clip(d.reason, 160)}`) : ""), { id: d.toolUseId, details: full });
|
|
338
|
+
}
|
|
342
339
|
}
|
|
343
340
|
}
|
|
344
341
|
return;
|
|
@@ -348,19 +345,17 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
348
345
|
void countUsage(e);
|
|
349
346
|
activity("Working");
|
|
350
347
|
doneProgress(d.toolUseId);
|
|
351
|
-
const sub = steps.get(d.toolUseId) ?? [];
|
|
352
|
-
steps.delete(d.toolUseId);
|
|
353
|
-
tasks.delete(d.toolUseId);
|
|
354
348
|
const call = calls.get(d.toolUseId);
|
|
355
349
|
calls.delete(d.toolUseId);
|
|
356
350
|
const before = befores.get(d.toolUseId);
|
|
357
351
|
befores.delete(d.toolUseId);
|
|
358
352
|
const input = inputs.get(d.toolUseId);
|
|
359
353
|
inputs.delete(d.toolUseId);
|
|
360
|
-
if (quiet.delete(d.toolUseId) && !d.isError) return;
|
|
361
354
|
const text = textOf(d.content).trim();
|
|
362
355
|
const name = toolNames.get(d.toolUseId) ?? "?";
|
|
363
|
-
const mine = customSync(name, (r) => r.result?.({ input, text, isError: d.isError === true, before }));
|
|
356
|
+
const mine = customSync(name, (r) => r.result?.({ toolUseId: d.toolUseId, input, text, isError: d.isError === true, before }));
|
|
357
|
+
// null:renderer 不要显示结果
|
|
358
|
+
if (mine === null) return;
|
|
364
359
|
if (mine && typeof mine.line === "string") {
|
|
365
360
|
const own = typeof mine.details === "string" && mine.details ? [mine.details.replace(/^/gm, " ")] : [];
|
|
366
361
|
const folded = [...(call ? [call] : []), ...own].join("\n") || undefined;
|
|
@@ -371,14 +366,10 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
371
366
|
// 结果接在调用的那一行后面;摘要省略了内容时,把完整结果(和子 Agent 调用过的工具)折叠起来,点击展开
|
|
372
367
|
const shown = d.isError ? 4 : 1;
|
|
373
368
|
const width = d.isError ? 200 : 160;
|
|
374
|
-
const hidden =
|
|
369
|
+
const hidden = lines.length > shown || lines.some((l) => l.length > width);
|
|
375
370
|
const details =
|
|
376
371
|
hidden || call
|
|
377
|
-
? [
|
|
378
|
-
...(call ? [call] : []),
|
|
379
|
-
...(sub.length ? [dim(` sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`))] : []),
|
|
380
|
-
...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : []),
|
|
381
|
-
].join("\n")
|
|
372
|
+
? [...(call ? [call] : []), ...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : [])].join("\n")
|
|
382
373
|
: undefined;
|
|
383
374
|
if (d.isError) screen.amend(d.toolUseId, red(`⎿ ${lines.slice(0, shown).map((l) => clip(l, width)).join("\n ")}`), { details });
|
|
384
375
|
else screen.amend(d.toolUseId, dim(`⎿ ${clip(lines[0] ?? "", width)}${lines.length > 1 ? ` (+${lines.length - 1} lines)` : ""}`), { details });
|
|
@@ -387,7 +378,6 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
387
378
|
case "tool.interrupted": {
|
|
388
379
|
const d = e.data as EventDataMap["tool.interrupted"];
|
|
389
380
|
doneProgress(d.toolUseId);
|
|
390
|
-
tasks.delete(d.toolUseId);
|
|
391
381
|
calls.delete(d.toolUseId);
|
|
392
382
|
befores.delete(d.toolUseId);
|
|
393
383
|
inputs.delete(d.toolUseId);
|
|
@@ -403,48 +393,37 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
403
393
|
if (d.reason === "stopped") screen.log(yellow("[stopped: step budget for this turn used up; send a message to continue]"));
|
|
404
394
|
else if (d.reason === "aborted") screen.log(yellow("[interrupted]"));
|
|
405
395
|
else if (d.reason === "max_tokens") {
|
|
406
|
-
|
|
396
|
+
// 不读 process.env:写在 $JADE_HOME/.env 里的只有 models 插件知道
|
|
397
|
+
const max = opts.maxTokens?.();
|
|
398
|
+
const limit = max ? `${max} tokens` : "the provider's default";
|
|
407
399
|
screen.log(yellow(`[reply cut off at the output limit (${limit}); raise it with /model if this keeps happening]`));
|
|
408
400
|
} else if (d.reason !== "end") screen.log(yellow(`[turn ended: ${d.reason}${d.error ? ` — ${d.error}` : ""}]`));
|
|
409
401
|
if (self.turnFailed && !replaying && opts.canRetry()) screen.log(dim("[send /retry to request again without adding a message]"));
|
|
410
402
|
return;
|
|
411
403
|
}
|
|
412
|
-
case "jade/compact/compacted": {
|
|
413
|
-
const d = e.data as { from: number; upTo: number; before: number };
|
|
414
|
-
void countUsage(e);
|
|
415
|
-
screen.log(dim(`[compacted ${d.upTo - d.from} messages, ~${d.before} tokens before]`));
|
|
416
|
-
return;
|
|
417
|
-
}
|
|
418
|
-
case "jade/checks/checked": {
|
|
419
|
-
const d = e.data as { summary: { name: string; problems: number; others?: number; failed?: string }[]; report: string };
|
|
420
|
-
const bad = d.summary.filter((s) => s.problems > 0 || s.others || s.failed);
|
|
421
|
-
const details = d.report ? detailsOf(d.report.split("\n").slice(1), (s) => s, MAX_DETAIL_LINES) : undefined;
|
|
422
|
-
if (bad.length === 0) {
|
|
423
|
-
screen.log(dim(` ✓ checks passed: ${d.summary.map((s) => s.name).join(", ")}`), { details });
|
|
424
|
-
} else {
|
|
425
|
-
const what = bad.map((s) =>
|
|
426
|
-
s.failed
|
|
427
|
-
? `${s.name} ${s.failed}`
|
|
428
|
-
: `${s.name}: ${[s.problems > 0 ? `${s.problems} problem${s.problems > 1 ? "s" : ""} in changed files` : "", s.others ? `${s.others} new elsewhere` : ""]
|
|
429
|
-
.filter(Boolean)
|
|
430
|
-
.join(", ")}`,
|
|
431
|
-
);
|
|
432
|
-
screen.log(yellow(` ⚠ checks: ${what.join("; ")}`), { details });
|
|
433
|
-
}
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
case "jade/policy/reviewed":
|
|
437
|
-
// 审查的结果显示在工具调用那一行,这里只计用量
|
|
438
|
-
void countUsage(e);
|
|
439
|
-
return;
|
|
440
|
-
case "jade/compact/trimmed": {
|
|
441
|
-
const d = e.data as { saved: number };
|
|
442
|
-
screen.log(dim(`[cleared old tool output, ~${d.saved} tokens]`));
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
404
|
default:
|
|
446
|
-
return
|
|
405
|
+
return renderPluginEvent(e);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* 插件的事件:用量照常统计;插件为它注册了渲染器时由渲染器显示,
|
|
411
|
+
* 否则只有 ctx.emit("notice", { text, level? }) 写入的提示显示成 [插件 id] 文本
|
|
412
|
+
*/
|
|
413
|
+
function renderPluginEvent(e: LogEvent) {
|
|
414
|
+
if (e.origin.by !== "plugin") return;
|
|
415
|
+
void countUsage(e);
|
|
416
|
+
const found = opts.eventRenderer?.(e.type);
|
|
417
|
+
if (!found) return renderPluginNotice(e);
|
|
418
|
+
let shown: ReturnType<EventRenderer["render"]>;
|
|
419
|
+
try {
|
|
420
|
+
shown = found.renderer.render(e.data);
|
|
421
|
+
} catch (err) {
|
|
422
|
+
return renderFailed(found.plugin, e.type, err);
|
|
447
423
|
}
|
|
424
|
+
if (!shown || typeof shown.line !== "string") return;
|
|
425
|
+
const details = typeof shown.details === "string" && shown.details ? shown.details.replace(/^/gm, " ") : undefined;
|
|
426
|
+
screen.log(shown.line, { details });
|
|
448
427
|
}
|
|
449
428
|
|
|
450
429
|
/** 插件用 ctx.emit("notice", { text, level? }) 写入的提示,显示成 [插件 id] 文本 */
|