@uncarved/jade 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/jade.js +5 -27
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +159 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -100
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +73 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +19 -42
- package/{src/tools → plugins/fs}/grep.ts +1 -1
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +74 -99
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +58 -26
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
- package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +50 -24
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +155 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/README.md +0 -204
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ 引用文件的补全:输入框里打 @ 时找出光标处正在输入的路径、给候选路径排序。
|
|
2
|
+
// 候选从工作目录来(git 仓库里只看版本控制的,和 glob 一样),发送时附上文件内容由 jade/mentions 负责。
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { readdir } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
/** 候选(文件加目录)最多这么多,再多也只是拖慢补全 */
|
|
7
|
+
const MAX_CANDIDATES = 20_000;
|
|
8
|
+
/** 光标正在输入的 @ 引用:@ 的下标和已经输入的部分;不在引用里时返回 undefined */
|
|
9
|
+
export function mentionAt(value, cursor) {
|
|
10
|
+
const m = /(?:^|\s)@("?[^\s"]*)$/.exec(value.slice(0, cursor));
|
|
11
|
+
if (!m)
|
|
12
|
+
return undefined;
|
|
13
|
+
return { start: cursor - m[1].length - 1, query: m[1].replace(/^"/, "") };
|
|
14
|
+
}
|
|
15
|
+
/** 补全后的文本:@ 引用加一个空格,含空白的路径加引号 */
|
|
16
|
+
export const mentionText = (p) => (/\s/.test(p) ? `@"${p}"` : `@${p}`);
|
|
17
|
+
/**
|
|
18
|
+
* 按 query 给候选路径排序:文件名以 query 开头的最前,其次文件名包含、路径包含,
|
|
19
|
+
* 最后是按顺序出现 query 每个字符的模糊匹配;同一档里短的在前
|
|
20
|
+
*/
|
|
21
|
+
export function rankPaths(paths, query, limit) {
|
|
22
|
+
const q = query.toLowerCase().replaceAll("\\", "/");
|
|
23
|
+
if (!q)
|
|
24
|
+
return paths.filter((p) => !p.slice(0, -1).includes("/")).slice(0, limit);
|
|
25
|
+
const scored = [];
|
|
26
|
+
for (const p of paths) {
|
|
27
|
+
const lower = p.toLowerCase();
|
|
28
|
+
const base = lower.replace(/\/$/, "").split("/").pop();
|
|
29
|
+
let score;
|
|
30
|
+
if (lower.startsWith(q))
|
|
31
|
+
score = 0;
|
|
32
|
+
else if (base.startsWith(q))
|
|
33
|
+
score = 1;
|
|
34
|
+
else if (base.includes(q))
|
|
35
|
+
score = 2;
|
|
36
|
+
else if (lower.includes(q))
|
|
37
|
+
score = 3;
|
|
38
|
+
else if (subsequence(lower, q))
|
|
39
|
+
score = 4;
|
|
40
|
+
else
|
|
41
|
+
continue;
|
|
42
|
+
scored.push({ p, score });
|
|
43
|
+
}
|
|
44
|
+
scored.sort((a, b) => a.score - b.score || a.p.length - b.p.length || a.p.localeCompare(b.p));
|
|
45
|
+
return scored.slice(0, limit).map((s) => s.p);
|
|
46
|
+
}
|
|
47
|
+
function subsequence(text, q) {
|
|
48
|
+
let i = 0;
|
|
49
|
+
for (const ch of text)
|
|
50
|
+
if (ch === q[i] && ++i === q.length)
|
|
51
|
+
return true;
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @ 补全的候选:工作目录里的文件(git 仓库里只看版本控制的)和它们所在的目录,目录以 / 结尾。
|
|
56
|
+
* 5 秒还没列完就先给已经找到的(大仓库第一次列得慢,不该让输入框卡住)
|
|
57
|
+
*/
|
|
58
|
+
export async function mentionCandidates(cwd, signal = AbortSignal.timeout(5000)) {
|
|
59
|
+
const files = [];
|
|
60
|
+
const dirs = new Set();
|
|
61
|
+
try {
|
|
62
|
+
for await (const full of await listFiles(cwd, signal)) {
|
|
63
|
+
const rel = display(cwd, full);
|
|
64
|
+
files.push(rel);
|
|
65
|
+
for (let i = rel.lastIndexOf("/"); i > 0; i = rel.lastIndexOf("/", i - 1)) {
|
|
66
|
+
const dir = rel.slice(0, i + 1);
|
|
67
|
+
if (dirs.has(dir))
|
|
68
|
+
break;
|
|
69
|
+
dirs.add(dir);
|
|
70
|
+
}
|
|
71
|
+
if (files.length + dirs.size >= MAX_CANDIDATES)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// 列到一半被中止(超时):用已经找到的
|
|
77
|
+
}
|
|
78
|
+
return [...dirs, ...files];
|
|
79
|
+
}
|
|
80
|
+
// 以下和 jade/fs 的 listFiles、display 相同:插件之间不共享代码(只能共享类型),所以这里留一份
|
|
81
|
+
const SKIP_DIRS = new Set([".git", "node_modules"]);
|
|
82
|
+
/** 显示用:工作目录内的路径用相对形式,统一为正斜杠 */
|
|
83
|
+
function display(cwd, full) {
|
|
84
|
+
const rel = path.relative(cwd, full);
|
|
85
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
86
|
+
return shown.split(path.sep).join("/");
|
|
87
|
+
}
|
|
88
|
+
/** git 仓库里的文件(版本控制的和没忽略的新文件);不是仓库、没有 git 时 undefined */
|
|
89
|
+
function gitFiles(root) {
|
|
90
|
+
return new Promise((resolve) => {
|
|
91
|
+
execFile("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], { cwd: root, maxBuffer: 256 * 1024 * 1024, windowsHide: true }, (err, out) =>
|
|
92
|
+
// 合并冲突中的文件会出现多次
|
|
93
|
+
resolve(err ? undefined : [...new Set(out.split("\0").filter(Boolean))]));
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function listFiles(root, signal) {
|
|
97
|
+
const tracked = await gitFiles(root);
|
|
98
|
+
if (!tracked)
|
|
99
|
+
return walk(root, signal);
|
|
100
|
+
return tracked.filter((rel) => !rel.split("/").some((seg) => SKIP_DIRS.has(seg))).map((rel) => path.join(root, rel));
|
|
101
|
+
}
|
|
102
|
+
async function* walk(dir, signal) {
|
|
103
|
+
signal.throwIfAborted();
|
|
104
|
+
const entries = (await readdir(dir, { withFileTypes: true })).sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
105
|
+
for (const e of entries) {
|
|
106
|
+
const full = path.join(dir, e.name);
|
|
107
|
+
if (e.isDirectory()) {
|
|
108
|
+
if (!SKIP_DIRS.has(e.name))
|
|
109
|
+
yield* walk(full, signal);
|
|
110
|
+
}
|
|
111
|
+
else if (e.isFile()) {
|
|
112
|
+
yield full;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "jade/tui",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"api": "^1",
|
|
5
|
+
"entry": "./index.js",
|
|
6
|
+
"provides": [
|
|
7
|
+
"frontend@1",
|
|
8
|
+
"ui@1"
|
|
9
|
+
],
|
|
10
|
+
"requires": [
|
|
11
|
+
"commands@1",
|
|
12
|
+
"keys@1",
|
|
13
|
+
"renderers@1"
|
|
14
|
+
],
|
|
15
|
+
"optional": [
|
|
16
|
+
"modes@1",
|
|
17
|
+
"models@1",
|
|
18
|
+
"compact@1",
|
|
19
|
+
"sessions@1"
|
|
20
|
+
],
|
|
21
|
+
"frontend": {
|
|
22
|
+
"name": "tui",
|
|
23
|
+
"default": true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// 宿主显示用的纯函数:工具调用的默认摘要和预览、折叠的工具结果。不依赖运行时和界面状态。
|
|
2
|
-
//
|
|
2
|
+
// 各个工具自己的显示由插件经 renderers@1 登记。
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { display } from "../tools/fs.js";
|
|
6
5
|
import { dim } from "./screen.js";
|
|
6
|
+
/** 显示用的路径:工作目录里的用相对路径,其余用绝对路径;都用正斜杠。和 jade/fs 的 display 相同,插件之间不 import 值,所以这里留一份 */
|
|
7
|
+
function display(cwd, full) {
|
|
8
|
+
const rel = path.relative(cwd, full);
|
|
9
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
10
|
+
return shown.split(path.sep).join("/");
|
|
11
|
+
}
|
|
7
12
|
export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
8
13
|
/**
|
|
9
14
|
* 带颜色(SGR 序列)的文字截到 n 个可见字符:序列不算长度、不会被切开;截断时在最后复位颜色,
|
|
@@ -54,4 +59,3 @@ export function detailsOf(lines, color, max) {
|
|
|
54
59
|
body.push(dim(` … ${lines.length - max} more lines`));
|
|
55
60
|
return body.join("\n");
|
|
56
61
|
}
|
|
57
|
-
//# sourceMappingURL=render.js.map
|
|
@@ -84,7 +84,12 @@ export function safeScreen(screen) {
|
|
|
84
84
|
input: (title, o) => screen.input(s(title), o && { ...o, initial: opt(o.initial), placeholder: opt(o.placeholder) }),
|
|
85
85
|
// 输入框里的 \r 是换行(旧 Mac 的换行符),不是进度条:先换成 \n,terminalSafe 才不会只留最后一段。
|
|
86
86
|
// 输入框里是要发给模型的纯文字,颜色也去掉
|
|
87
|
-
draft: screen.draft && {
|
|
87
|
+
draft: screen.draft && {
|
|
88
|
+
text: () => screen.draft.text(),
|
|
89
|
+
insert: (t) => screen.draft.insert(plain(lf(t))),
|
|
90
|
+
set: (t) => screen.draft.set(plain(lf(t))),
|
|
91
|
+
hint: (t) => screen.draft.hint(t === undefined ? undefined : plain(lf(t))),
|
|
92
|
+
},
|
|
88
93
|
clear: () => screen.clear(),
|
|
89
94
|
close: () => screen.close(),
|
|
90
95
|
};
|
|
@@ -194,4 +199,3 @@ export function plainScreen(opts) {
|
|
|
194
199
|
},
|
|
195
200
|
};
|
|
196
201
|
}
|
|
197
|
-
//# sourceMappingURL=screen.js.map
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
// 把运行时的通知和日志事件显示成对话:模型的流式输出、工具调用和结果、轮次结束的原因,
|
|
2
2
|
// 以及恢复会话时重新显示历史。顺带统计本会话的 token 用量、更新状态栏的上下文用量。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
import { readAll } from "uncarved";
|
|
6
|
-
import { renderTodos } from "../tools/todo.js";
|
|
4
|
+
// 只负责显示和统计,不驱动运行时;前端(frontend.ts)用 lastEnd、turnFailed 决定接下来做什么。
|
|
7
5
|
import { clip, clipStyled, detailsOf, preview, summarize } from "./render.js";
|
|
8
6
|
import { bold, cyan, dim, green, red, yellow } from "./screen.js";
|
|
9
7
|
/** 工具结果折叠起来的完整内容最多这么多行 */
|
|
10
8
|
const MAX_DETAIL_LINES = 2000;
|
|
9
|
+
/** 插件事件里的用量:只取数字字段 */
|
|
10
|
+
function usageOf(u) {
|
|
11
|
+
if (typeof u !== "object" || u === null)
|
|
12
|
+
return undefined;
|
|
13
|
+
const out = {};
|
|
14
|
+
for (const k of ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"]) {
|
|
15
|
+
const v = u[k];
|
|
16
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
17
|
+
out[k] = v;
|
|
18
|
+
}
|
|
19
|
+
return Object.keys(out).length ? out : undefined;
|
|
20
|
+
}
|
|
11
21
|
const textOf = (blocks) => blocks.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
|
|
12
22
|
const errorText = (err) => (err instanceof Error ? err.message : String(err));
|
|
13
23
|
export function transcript(opts) {
|
|
14
|
-
const { screen, cwd
|
|
24
|
+
const { screen, cwd } = opts;
|
|
15
25
|
const usage = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
16
26
|
const addUsage = (u) => {
|
|
17
27
|
for (const k of Object.keys(usage))
|
|
@@ -19,16 +29,19 @@ export function transcript(opts) {
|
|
|
19
29
|
if (u)
|
|
20
30
|
screen.status({ spent: { input: usage.inputTokens, output: usage.outputTokens } });
|
|
21
31
|
};
|
|
22
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* 一个事件带来的用量:模型回复;插件事件 data 里的 usage(压缩时的总结调用、auto 模式的审查这类插件自己发的请求);
|
|
34
|
+
* 子 Agent 的用量在它自己的日志里(读不到时不算,不让一个读失败变成没人处理的 rejection)
|
|
35
|
+
*/
|
|
23
36
|
async function countUsage(e) {
|
|
24
37
|
if (e.type === "model.responded")
|
|
25
38
|
addUsage(e.data.usage);
|
|
26
|
-
else if (e.
|
|
27
|
-
addUsage(e.data
|
|
39
|
+
else if (e.origin.by === "plugin")
|
|
40
|
+
addUsage(usageOf(e.data?.usage));
|
|
28
41
|
else if (e.type === "tool.completed") {
|
|
29
42
|
const child = e.data.child;
|
|
30
|
-
if (child)
|
|
31
|
-
for (const c of await
|
|
43
|
+
if (child && opts.readLog)
|
|
44
|
+
for (const c of await opts.readLog(child.sessionId).catch(() => []))
|
|
32
45
|
await countUsage(c);
|
|
33
46
|
}
|
|
34
47
|
}
|
|
@@ -90,15 +103,9 @@ export function transcript(opts) {
|
|
|
90
103
|
if (!replaying)
|
|
91
104
|
screen.busy(label);
|
|
92
105
|
};
|
|
93
|
-
/** 结果不用再显示的工具调用 */
|
|
94
|
-
const quiet = new Set();
|
|
95
106
|
let streamed = false;
|
|
96
107
|
/** 正在运行、显示着进度的工具 */
|
|
97
108
|
const running = new Set();
|
|
98
|
-
/** 子 Agent 调用过的工具,结束时放进 task 结果的折叠内容里 */
|
|
99
|
-
const steps = new Map();
|
|
100
|
-
/** 正在运行的子 Agent 的标签,显示在它的进度行开头 */
|
|
101
|
-
const tasks = new Map();
|
|
102
109
|
/** 调用行省略了的参数(例如很长的命令),结果出来后放在折叠内容的最前面 */
|
|
103
110
|
const calls = new Map();
|
|
104
111
|
/** renderer 的 before 在执行前记下的东西,结果出来时交给它的 result */
|
|
@@ -174,12 +181,9 @@ export function transcript(opts) {
|
|
|
174
181
|
usage[k] = 0;
|
|
175
182
|
reportsCache = undefined;
|
|
176
183
|
toolNames.clear();
|
|
177
|
-
quiet.clear();
|
|
178
184
|
for (const id of running)
|
|
179
185
|
screen.progress(id, undefined);
|
|
180
186
|
running.clear();
|
|
181
|
-
steps.clear();
|
|
182
|
-
tasks.clear();
|
|
183
187
|
calls.clear();
|
|
184
188
|
befores.clear();
|
|
185
189
|
inputs.clear();
|
|
@@ -234,32 +238,19 @@ export function transcript(opts) {
|
|
|
234
238
|
return renderEvent(n.event);
|
|
235
239
|
}
|
|
236
240
|
}
|
|
237
|
-
|
|
238
|
-
|
|
241
|
+
/** 工具的进度:有 renderer 的 progress 时由它换成一行;否则 { text } 形式的按输出逐行显示(例如 bash),其他的不显示 */
|
|
242
|
+
function renderProgress(toolUseId, update) {
|
|
243
|
+
const name = toolNames.get(toolUseId) ?? "?";
|
|
244
|
+
if (opts.renderer?.(name)?.renderer.progress) {
|
|
245
|
+
const line = customSync(name, (r) => r.progress?.(update, { toolUseId, summary }));
|
|
246
|
+
if (typeof line === "string" && line)
|
|
247
|
+
progress(toolUseId, clipStyled(line.split("\n")[0], 200));
|
|
239
248
|
return;
|
|
240
|
-
// 每个子 Agent 只有一行进度:标签、调用过几个工具、正在做什么。并行的几个靠标签分清
|
|
241
|
-
const taskLine = (what) => {
|
|
242
|
-
const n = steps.get(toolUseId)?.length ?? 0;
|
|
243
|
-
progress(toolUseId, dim(` ↳ ${tasks.get(toolUseId) ?? "sub-agent"}${n ? ` (${n} tool call${n > 1 ? "s" : ""})` : ""} · ${what}`));
|
|
244
|
-
};
|
|
245
|
-
if (p.kind === "task-start") {
|
|
246
|
-
tasks.set(toolUseId, p.description);
|
|
247
|
-
return taskLine("starting");
|
|
248
249
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
if (p.kind === "task-tool") {
|
|
252
|
-
// 要用户批准的调用在审批时显示
|
|
253
|
-
if (p.decision === "ask")
|
|
254
|
-
return;
|
|
255
|
-
const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summary(p.name, p.input)})`;
|
|
256
|
-
steps.set(toolUseId, [...(steps.get(toolUseId) ?? []), step]);
|
|
257
|
-
return taskLine(step);
|
|
258
|
-
}
|
|
259
|
-
// 第三方工具的进度格式 jade 不认识,不显示
|
|
260
|
-
if (typeof p.text !== "string")
|
|
250
|
+
const text = update?.text;
|
|
251
|
+
if (typeof text !== "string")
|
|
261
252
|
return;
|
|
262
|
-
for (const l of
|
|
253
|
+
for (const l of text.replace(/\n$/, "").split("\n"))
|
|
263
254
|
progress(toolUseId, dim(` │ ${clip(l, 200)}`), { output: true });
|
|
264
255
|
}
|
|
265
256
|
function renderEvent(e) {
|
|
@@ -309,16 +300,20 @@ export function transcript(opts) {
|
|
|
309
300
|
screen.log(red(`✗ ${head}`) + dim(d.reason ? ` — ${clip(d.reason, 200)}` : ""), { id: d.toolUseId, details: full });
|
|
310
301
|
else {
|
|
311
302
|
activity(`Running ${name}`);
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
303
|
+
// 用户批准的调用在审批时已经显示过;重新显示历史时没有审批这一步
|
|
304
|
+
if (d.decidedBy !== "user" || replaying) {
|
|
305
|
+
const own = customSync(name, (r) => r.call?.(d.input));
|
|
306
|
+
if (typeof own === "string" && own) {
|
|
307
|
+
// renderer 给的内容:第一行是调用行(结果接在它后面),其余的行不折叠
|
|
308
|
+
const [first, ...rest] = own.split("\n");
|
|
309
|
+
screen.log(cyan("● ") + first, { id: d.toolUseId, details: full });
|
|
310
|
+
if (rest.length)
|
|
311
|
+
screen.log(rest.join("\n"));
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
// auto 模式下审查放行的带着理由
|
|
315
|
+
screen.log(cyan("● ") + head + (d.reason ? dim(` — ${clip(d.reason, 160)}`) : ""), { id: d.toolUseId, details: full });
|
|
316
|
+
}
|
|
322
317
|
}
|
|
323
318
|
}
|
|
324
319
|
return;
|
|
@@ -328,20 +323,18 @@ export function transcript(opts) {
|
|
|
328
323
|
void countUsage(e);
|
|
329
324
|
activity("Working");
|
|
330
325
|
doneProgress(d.toolUseId);
|
|
331
|
-
const sub = steps.get(d.toolUseId) ?? [];
|
|
332
|
-
steps.delete(d.toolUseId);
|
|
333
|
-
tasks.delete(d.toolUseId);
|
|
334
326
|
const call = calls.get(d.toolUseId);
|
|
335
327
|
calls.delete(d.toolUseId);
|
|
336
328
|
const before = befores.get(d.toolUseId);
|
|
337
329
|
befores.delete(d.toolUseId);
|
|
338
330
|
const input = inputs.get(d.toolUseId);
|
|
339
331
|
inputs.delete(d.toolUseId);
|
|
340
|
-
if (quiet.delete(d.toolUseId) && !d.isError)
|
|
341
|
-
return;
|
|
342
332
|
const text = textOf(d.content).trim();
|
|
343
333
|
const name = toolNames.get(d.toolUseId) ?? "?";
|
|
344
|
-
const mine = customSync(name, (r) => r.result?.({ input, text, isError: d.isError === true, before }));
|
|
334
|
+
const mine = customSync(name, (r) => r.result?.({ toolUseId: d.toolUseId, input, text, isError: d.isError === true, before }));
|
|
335
|
+
// null:renderer 不要显示结果
|
|
336
|
+
if (mine === null)
|
|
337
|
+
return;
|
|
345
338
|
if (mine && typeof mine.line === "string") {
|
|
346
339
|
const own = typeof mine.details === "string" && mine.details ? [mine.details.replace(/^/gm, " ")] : [];
|
|
347
340
|
const folded = [...(call ? [call] : []), ...own].join("\n") || undefined;
|
|
@@ -352,13 +345,9 @@ export function transcript(opts) {
|
|
|
352
345
|
// 结果接在调用的那一行后面;摘要省略了内容时,把完整结果(和子 Agent 调用过的工具)折叠起来,点击展开
|
|
353
346
|
const shown = d.isError ? 4 : 1;
|
|
354
347
|
const width = d.isError ? 200 : 160;
|
|
355
|
-
const hidden =
|
|
348
|
+
const hidden = lines.length > shown || lines.some((l) => l.length > width);
|
|
356
349
|
const details = hidden || call
|
|
357
|
-
? [
|
|
358
|
-
...(call ? [call] : []),
|
|
359
|
-
...(sub.length ? [dim(` sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`))] : []),
|
|
360
|
-
...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : []),
|
|
361
|
-
].join("\n")
|
|
350
|
+
? [...(call ? [call] : []), ...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : [])].join("\n")
|
|
362
351
|
: undefined;
|
|
363
352
|
if (d.isError)
|
|
364
353
|
screen.amend(d.toolUseId, red(`⎿ ${lines.slice(0, shown).map((l) => clip(l, width)).join("\n ")}`), { details });
|
|
@@ -369,7 +358,6 @@ export function transcript(opts) {
|
|
|
369
358
|
case "tool.interrupted": {
|
|
370
359
|
const d = e.data;
|
|
371
360
|
doneProgress(d.toolUseId);
|
|
372
|
-
tasks.delete(d.toolUseId);
|
|
373
361
|
calls.delete(d.toolUseId);
|
|
374
362
|
befores.delete(d.toolUseId);
|
|
375
363
|
inputs.delete(d.toolUseId);
|
|
@@ -397,42 +385,33 @@ export function transcript(opts) {
|
|
|
397
385
|
screen.log(dim("[send /retry to request again without adding a message]"));
|
|
398
386
|
return;
|
|
399
387
|
}
|
|
400
|
-
case "jade/compact/compacted": {
|
|
401
|
-
const d = e.data;
|
|
402
|
-
void countUsage(e);
|
|
403
|
-
screen.log(dim(`[compacted ${d.upTo - d.from} messages, ~${d.before} tokens before]`));
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
case "jade/checks/checked": {
|
|
407
|
-
const d = e.data;
|
|
408
|
-
const bad = d.summary.filter((s) => s.problems > 0 || s.others || s.failed);
|
|
409
|
-
const details = d.report ? detailsOf(d.report.split("\n").slice(1), (s) => s, MAX_DETAIL_LINES) : undefined;
|
|
410
|
-
if (bad.length === 0) {
|
|
411
|
-
screen.log(dim(` ✓ checks passed: ${d.summary.map((s) => s.name).join(", ")}`), { details });
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
const what = bad.map((s) => s.failed
|
|
415
|
-
? `${s.name} ${s.failed}`
|
|
416
|
-
: `${s.name}: ${[s.problems > 0 ? `${s.problems} problem${s.problems > 1 ? "s" : ""} in changed files` : "", s.others ? `${s.others} new elsewhere` : ""]
|
|
417
|
-
.filter(Boolean)
|
|
418
|
-
.join(", ")}`);
|
|
419
|
-
screen.log(yellow(` ⚠ checks: ${what.join("; ")}`), { details });
|
|
420
|
-
}
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
case "jade/policy/reviewed":
|
|
424
|
-
// 审查的结果显示在工具调用那一行,这里只计用量
|
|
425
|
-
void countUsage(e);
|
|
426
|
-
return;
|
|
427
|
-
case "jade/compact/trimmed": {
|
|
428
|
-
const d = e.data;
|
|
429
|
-
screen.log(dim(`[cleared old tool output, ~${d.saved} tokens]`));
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
388
|
default:
|
|
433
|
-
return
|
|
389
|
+
return renderPluginEvent(e);
|
|
434
390
|
}
|
|
435
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* 插件的事件:用量照常统计;插件为它注册了渲染器时由渲染器显示,
|
|
394
|
+
* 否则只有 ctx.emit("notice", { text, level? }) 写入的提示显示成 [插件 id] 文本
|
|
395
|
+
*/
|
|
396
|
+
function renderPluginEvent(e) {
|
|
397
|
+
if (e.origin.by !== "plugin")
|
|
398
|
+
return;
|
|
399
|
+
void countUsage(e);
|
|
400
|
+
const found = opts.eventRenderer?.(e.type);
|
|
401
|
+
if (!found)
|
|
402
|
+
return renderPluginNotice(e);
|
|
403
|
+
let shown;
|
|
404
|
+
try {
|
|
405
|
+
shown = found.renderer.render(e.data);
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
return renderFailed(found.plugin, e.type, err);
|
|
409
|
+
}
|
|
410
|
+
if (!shown || typeof shown.line !== "string")
|
|
411
|
+
return;
|
|
412
|
+
const details = typeof shown.details === "string" && shown.details ? shown.details.replace(/^/gm, " ") : undefined;
|
|
413
|
+
screen.log(shown.line, { details });
|
|
414
|
+
}
|
|
436
415
|
/** 插件用 ctx.emit("notice", { text, level? }) 写入的提示,显示成 [插件 id] 文本 */
|
|
437
416
|
function renderPluginNotice(e) {
|
|
438
417
|
if (e.origin.by !== "plugin" || !e.type.endsWith("/notice"))
|
|
@@ -495,4 +474,3 @@ export function transcript(opts) {
|
|
|
495
474
|
}
|
|
496
475
|
return self;
|
|
497
476
|
}
|
|
498
|
-
//# sourceMappingURL=transcript.js.map
|