@uncarved/jade 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/jade.js +5 -4
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -28
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +156 -1223
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +55 -0
- package/dist/update.js +258 -0
- package/dist/update.js.map +1 -0
- package/package.json +12 -9
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -84
- package/plugins/approval/review.ts +192 -0
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +68 -39
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +112 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +3 -4
- package/{src/tools → plugins/fs}/fs.ts +64 -46
- package/{src/tools → plugins/fs}/grep.ts +4 -3
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/plugins/fs/renderers.ts +138 -0
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +23 -27
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +36 -21
- package/{src → plugins/shell}/sys.ts +19 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +53 -1
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/{src/ui → plugins/tui}/markdown.ts +258 -219
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/plugins/tui/render.ts +67 -0
- package/plugins/tui/screen.ts +268 -0
- package/{src/ui → plugins/tui}/transcript.ts +179 -111
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/plugins/web/web.ts +713 -0
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
- package/plugins-dist/approval/review.js +176 -0
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +65 -34
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +95 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +3 -5
- package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/plugins-dist/fs/renderers.js +132 -0
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +22 -19
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +36 -23
- package/{dist → plugins-dist/shell}/sys.js +20 -44
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +57 -20
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/plugins-dist/tui/render.js +61 -0
- package/plugins-dist/tui/screen.js +201 -0
- package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
- package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/plugins-dist/web/web.js +660 -0
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -28
- package/src/install.ts +355 -0
- package/src/main.ts +152 -1263
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -0
- package/LICENSE +0 -21
- package/README.md +0 -198
- package/dist/commands.d.ts +0 -30
- package/dist/commands.js +0 -106
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -104
- package/dist/distro.js +0 -312
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -251
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -22
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -70
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -42
- package/dist/plugins/core.js +0 -190
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -182
- package/dist/plugins/loader.js +0 -253
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -96
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -38
- package/dist/plugins/prompts.js +0 -196
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -9
- package/dist/plugins/repeats.js +0 -90
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -16
- package/dist/plugins/review.js +0 -92
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/provider.d.ts +0 -111
- package/dist/provider.js.map +0 -1
- package/dist/sessions.d.ts +0 -22
- package/dist/sessions.js +0 -53
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -48
- package/dist/sys.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -35
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -35
- package/dist/tools/task.js +0 -89
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -23
- package/dist/tools/web.js +0 -426
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -378
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -33
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -17
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -15
- package/dist/ui/render.js +0 -94
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -98
- package/dist/ui/screen.js +0 -108
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -33
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -45
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -120
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -400
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -239
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -31
- package/src/plugins/core.ts +0 -217
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -386
- package/src/plugins/prompts.ts +0 -234
- package/src/plugins/repeats.ts +0 -96
- package/src/plugins/review.ts +0 -109
- package/src/sessions.ts +0 -61
- package/src/tools/task.ts +0 -109
- package/src/tools/web.ts +0 -451
- package/src/ui/configure.ts +0 -408
- package/src/ui/render.ts +0 -83
- package/src/ui/screen.ts +0 -169
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
// 把运行时的通知和日志事件显示成对话:模型的流式输出、工具调用和结果、轮次结束的原因,
|
|
2
2
|
// 以及恢复会话时重新显示历史。顺带统计本会话的 token 用量、更新状态栏的上下文用量。
|
|
3
3
|
//
|
|
4
|
-
//
|
|
4
|
+
// 只负责显示和统计,不驱动运行时;前端(frontend.ts)用 lastEnd、turnFailed 决定接下来做什么。
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
8
|
-
import
|
|
9
|
-
import { renderTodos, type Todo } from "../tools/todo.ts";
|
|
10
|
-
import { callDetails, clip, detailsOf, summarize } from "./render.ts";
|
|
6
|
+
import type { Block, EventDataMap, LogEvent, PendingCall, Runtime, TurnEndReason, Usage } from "uncarved";
|
|
7
|
+
import type { EventRenderer, ToolRenderer } from "../renderers/index.ts";
|
|
8
|
+
import { clip, clipStyled, detailsOf, preview, summarize } from "./render.ts";
|
|
11
9
|
import { bold, cyan, dim, green, red, yellow, type Screen } from "./screen.ts";
|
|
12
10
|
|
|
13
11
|
export type Notice = Parameters<Parameters<Runtime["subscribe"]>[0]>[0];
|
|
@@ -15,14 +13,18 @@ export type Notice = Parameters<Parameters<Runtime["subscribe"]>[0]>[0];
|
|
|
15
13
|
export interface TranscriptOptions {
|
|
16
14
|
screen: Screen;
|
|
17
15
|
cwd: string;
|
|
18
|
-
/** 子 Agent
|
|
19
|
-
|
|
16
|
+
/** 子 Agent 的用量在它自己的日志里,从这里读;不给就不统计子 Agent 的用量 */
|
|
17
|
+
readLog?(sessionId: string): Promise<LogEvent[]>;
|
|
20
18
|
/** 模型的上下文窗口(状态栏显示用) */
|
|
21
19
|
contextWindow(): number;
|
|
22
20
|
/** 自动压缩的阈值(状态栏显示用) */
|
|
23
21
|
compactAt?(): number;
|
|
24
22
|
/** 上一轮失败后能否用 /retry 重新请求 */
|
|
25
23
|
canRetry(): boolean;
|
|
24
|
+
/** 插件为自己的工具注册的显示方式(随会话的插件实例变) */
|
|
25
|
+
renderer?(tool: string): { plugin: string; renderer: ToolRenderer } | undefined;
|
|
26
|
+
/** 插件为自己的事件注册的显示方式,按完整的事件类型 */
|
|
27
|
+
eventRenderer?(type: string): { plugin: string; renderer: EventRenderer } | undefined;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
export interface Transcript {
|
|
@@ -41,41 +43,66 @@ export interface Transcript {
|
|
|
41
43
|
turnFailed: boolean;
|
|
42
44
|
/** 开始新会话时清空 */
|
|
43
45
|
reset(): void;
|
|
46
|
+
/** 工具调用括号里的一行摘要:插件的 renderer 优先 */
|
|
47
|
+
summary(name: string, input: unknown): string;
|
|
48
|
+
/** 摘要省略了的参数,调用行展开后显示在最前面(已经缩进);没有时是 undefined */
|
|
49
|
+
details(name: string, input: unknown): string | undefined;
|
|
50
|
+
/** 审批时的预览:工具的 renderer 给的,没有时是参数的 JSON */
|
|
51
|
+
preview(c: PendingCall): Promise<string>;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
/** 工具结果折叠起来的完整内容最多这么多行 */
|
|
47
55
|
const MAX_DETAIL_LINES = 2000;
|
|
48
56
|
|
|
57
|
+
/** 插件事件里的用量:只取数字字段 */
|
|
58
|
+
function usageOf(u: unknown): Usage | undefined {
|
|
59
|
+
if (typeof u !== "object" || u === null) return undefined;
|
|
60
|
+
const out: Usage = {};
|
|
61
|
+
for (const k of ["inputTokens", "outputTokens", "cacheReadTokens", "cacheWriteTokens"] as const) {
|
|
62
|
+
const v = (u as Record<string, unknown>)[k];
|
|
63
|
+
if (typeof v === "number" && Number.isFinite(v)) out[k] = v;
|
|
64
|
+
}
|
|
65
|
+
return Object.keys(out).length ? out : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
49
68
|
const textOf = (blocks: Block[]) => blocks.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
|
|
50
69
|
const errorText = (err: unknown) => (err instanceof Error ? err.message : String(err));
|
|
51
70
|
|
|
52
71
|
export function transcript(opts: TranscriptOptions): Transcript {
|
|
53
|
-
const { screen, cwd
|
|
72
|
+
const { screen, cwd } = opts;
|
|
54
73
|
|
|
55
74
|
const usage: Required<Usage> = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
56
75
|
const addUsage = (u?: Usage) => {
|
|
57
76
|
for (const k of Object.keys(usage) as (keyof Usage)[]) usage[k] += u?.[k] ?? 0;
|
|
58
77
|
if (u) screen.status({ spent: { input: usage.inputTokens, output: usage.outputTokens } });
|
|
59
78
|
};
|
|
60
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* 一个事件带来的用量:模型回复;插件事件 data 里的 usage(压缩时的总结调用、auto 模式的审查这类插件自己发的请求);
|
|
81
|
+
* 子 Agent 的用量在它自己的日志里(读不到时不算,不让一个读失败变成没人处理的 rejection)
|
|
82
|
+
*/
|
|
61
83
|
async function countUsage(e: LogEvent) {
|
|
62
84
|
if (e.type === "model.responded") addUsage((e as LogEvent<"model.responded">).data.usage);
|
|
63
|
-
else if (e.
|
|
85
|
+
else if (e.origin.by === "plugin") addUsage(usageOf((e.data as { usage?: unknown } | null)?.usage));
|
|
64
86
|
else if (e.type === "tool.completed") {
|
|
65
87
|
const child = (e as LogEvent<"tool.completed">).data.child;
|
|
66
|
-
if (child) for (const c of await
|
|
88
|
+
if (child && opts.readLog) for (const c of await opts.readLog(child.sessionId).catch(() => [])) await countUsage(c);
|
|
67
89
|
}
|
|
68
90
|
}
|
|
69
91
|
|
|
70
|
-
/**
|
|
71
|
-
|
|
92
|
+
/**
|
|
93
|
+
* 报过缓存命中数的 provider/模型。有的服务只在命中时才带这个字段,报过一次之后没带就是没命中;
|
|
94
|
+
* 换了服务或模型要重新看,否则从报缓存的服务换到不报的,会一直显示 0%
|
|
95
|
+
*/
|
|
96
|
+
let reportsCache: string | undefined;
|
|
72
97
|
/** 上下文用量:最近一次回复的输入加输出,就是下一次请求的大致起点;以及这次输入的缓存命中率 */
|
|
73
|
-
function showContext(
|
|
98
|
+
function showContext(e: LogEvent<"model.responded">) {
|
|
99
|
+
const u = e.data.usage;
|
|
74
100
|
if (u?.inputTokens === undefined) return;
|
|
75
|
-
|
|
101
|
+
const by = e.origin.by === "model" ? `${e.origin.provider}/${e.origin.model}` : "";
|
|
102
|
+
if (u.cacheReadTokens !== undefined) reportsCache = by;
|
|
76
103
|
screen.status({
|
|
77
104
|
context: { used: u.inputTokens + (u.outputTokens ?? 0), limit: opts.contextWindow(), compactAt: opts.compactAt?.() },
|
|
78
|
-
cache: reportsCache && u.inputTokens > 0 ? (u.cacheReadTokens ?? 0) / u.inputTokens : undefined,
|
|
105
|
+
cache: reportsCache === by && u.inputTokens > 0 ? (u.cacheReadTokens ?? 0) / u.inputTokens : undefined,
|
|
79
106
|
});
|
|
80
107
|
}
|
|
81
108
|
|
|
@@ -88,7 +115,11 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
88
115
|
const startSpeed = () => {
|
|
89
116
|
speed.first = 0;
|
|
90
117
|
speed.estimate = 0;
|
|
118
|
+
toolChars = 0;
|
|
91
119
|
};
|
|
120
|
+
/** 这次回复里工具参数已经生成的字数:写大文件时一写几分钟,显示出来才看得出不是卡住了 */
|
|
121
|
+
let toolChars = 0;
|
|
122
|
+
const toolLabel = () => (toolChars < 1000 ? "Writing" : `Writing (${Math.floor(toolChars / 1000)}k chars)`);
|
|
92
123
|
const trackSpeed = (text: string) => {
|
|
93
124
|
const now = Date.now();
|
|
94
125
|
if (!speed.first) speed.first = now;
|
|
@@ -112,24 +143,60 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
112
143
|
const activity = (label: string) => {
|
|
113
144
|
if (!replaying) screen.busy(label);
|
|
114
145
|
};
|
|
115
|
-
/** 结果不用再显示的工具调用 */
|
|
116
|
-
const quiet = new Set<string>();
|
|
117
146
|
let streamed = false;
|
|
118
147
|
/** 正在运行、显示着进度的工具 */
|
|
119
148
|
const running = new Set<string>();
|
|
120
|
-
/** 子 Agent 调用过的工具,结束时放进 task 结果的折叠内容里 */
|
|
121
|
-
const steps = new Map<string, string[]>();
|
|
122
|
-
/** 正在运行的子 Agent 的标签,显示在它的进度行开头 */
|
|
123
|
-
const tasks = new Map<string, string>();
|
|
124
149
|
/** 调用行省略了的参数(例如很长的命令),结果出来后放在折叠内容的最前面 */
|
|
125
150
|
const calls = new Map<string, string>();
|
|
126
|
-
|
|
151
|
+
/** renderer 的 before 在执行前记下的东西,结果出来时交给它的 result */
|
|
152
|
+
const befores = new Map<string, unknown>();
|
|
153
|
+
const progress =(id: string, line: string, o?: { output?: boolean }) => {
|
|
127
154
|
running.add(id);
|
|
128
155
|
screen.progress(id, line, o);
|
|
129
156
|
};
|
|
130
157
|
const doneProgress = (id: string) => {
|
|
131
158
|
if (running.delete(id)) screen.progress(id, undefined);
|
|
132
159
|
};
|
|
160
|
+
/** 有 result renderer 的调用的参数,结果出来时交给它 */
|
|
161
|
+
const inputs = new Map<string, unknown>();
|
|
162
|
+
|
|
163
|
+
/** 出过错的 renderer(插件 + 工具),只提示一次 */
|
|
164
|
+
const failed = new Set<string>();
|
|
165
|
+
/** 调用插件的 renderer;没有、出错时返回 undefined(用默认的显示) */
|
|
166
|
+
async function custom<T>(name: string, use: (r: ToolRenderer) => T | undefined | Promise<T | undefined>): Promise<T | undefined> {
|
|
167
|
+
const found = opts.renderer?.(name);
|
|
168
|
+
if (!found) return undefined;
|
|
169
|
+
try {
|
|
170
|
+
return await use(found.renderer);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
renderFailed(found.plugin, name, err);
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** 同步的版本:摘要和结果在事件通知里同步显示 */
|
|
177
|
+
function customSync<T>(name: string, use: (r: ToolRenderer) => T | undefined): T | undefined {
|
|
178
|
+
const found = opts.renderer?.(name);
|
|
179
|
+
if (!found) return undefined;
|
|
180
|
+
try {
|
|
181
|
+
return use(found.renderer);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
renderFailed(found.plugin, name, err);
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function renderFailed(plugin: string, name: string, err: unknown) {
|
|
188
|
+
if (failed.has(`${plugin}:${name}`)) return;
|
|
189
|
+
failed.add(`${plugin}:${name}`);
|
|
190
|
+
screen.log(yellow(`[warning] plugin ${plugin}: showing ${name} failed, using the default display: ${errorText(err)}`));
|
|
191
|
+
}
|
|
192
|
+
const summary = (name: string, input: unknown): string => {
|
|
193
|
+
const s = customSync(name, (r) => r.summary?.(input));
|
|
194
|
+
return typeof s === "string" ? clip(s.split("\n")[0]!, 120) : summarize(cwd, input);
|
|
195
|
+
};
|
|
196
|
+
const details = (name: string, input: unknown): string | undefined => {
|
|
197
|
+
const d = customSync(name, (r) => r.details?.(input));
|
|
198
|
+
return typeof d === "string" && d ? d.replace(/^/gm, " ") : undefined;
|
|
199
|
+
};
|
|
133
200
|
|
|
134
201
|
const self: Transcript = {
|
|
135
202
|
usage,
|
|
@@ -138,17 +205,22 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
138
205
|
turnFailed: false,
|
|
139
206
|
onNotice,
|
|
140
207
|
replay,
|
|
208
|
+
summary,
|
|
209
|
+
details,
|
|
210
|
+
async preview(c) {
|
|
211
|
+
const p = await custom(c.name, (r) => r.preview?.(c.input));
|
|
212
|
+
return typeof p === "string" ? p : preview(c.input);
|
|
213
|
+
},
|
|
141
214
|
echo: (text) => screen.log(text.startsWith("/") ? cyan(`› ${text}`) : `\n${bold(`› ${text.replace(/\n/g, "\n ")}`)}`),
|
|
142
215
|
reset() {
|
|
143
216
|
for (const k of Object.keys(usage) as (keyof Usage)[]) usage[k] = 0;
|
|
144
|
-
reportsCache =
|
|
217
|
+
reportsCache = undefined;
|
|
145
218
|
toolNames.clear();
|
|
146
|
-
quiet.clear();
|
|
147
219
|
for (const id of running) screen.progress(id, undefined);
|
|
148
220
|
running.clear();
|
|
149
|
-
steps.clear();
|
|
150
|
-
tasks.clear();
|
|
151
221
|
calls.clear();
|
|
222
|
+
befores.clear();
|
|
223
|
+
inputs.clear();
|
|
152
224
|
self.lastEnd = undefined;
|
|
153
225
|
},
|
|
154
226
|
};
|
|
@@ -169,7 +241,11 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
169
241
|
trackSpeed(n.delta.text);
|
|
170
242
|
// 工具参数只用来计时,不显示;也不算已经输出了内容(重试时不用标记作废,回复结束时照常打印没流式输出的正文)
|
|
171
243
|
if (n.delta.kind === "tool_input") {
|
|
172
|
-
|
|
244
|
+
// 只在千位变了时更新,不让每个增量都重画
|
|
245
|
+
const before = toolLabel();
|
|
246
|
+
toolChars += n.delta.text.length;
|
|
247
|
+
const label = toolLabel();
|
|
248
|
+
if (label !== before || toolChars === n.delta.text.length) screen.busy(label);
|
|
173
249
|
return;
|
|
174
250
|
}
|
|
175
251
|
streamed = true;
|
|
@@ -190,34 +266,23 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
190
266
|
case "awaiting":
|
|
191
267
|
return;
|
|
192
268
|
case "tool-progress":
|
|
193
|
-
return renderProgress(n.toolUseId, n.update
|
|
269
|
+
return renderProgress(n.toolUseId, n.update);
|
|
194
270
|
case "event":
|
|
195
271
|
return renderEvent(n.event);
|
|
196
272
|
}
|
|
197
273
|
}
|
|
198
274
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (p.kind === "task-start") {
|
|
207
|
-
tasks.set(toolUseId, p.description);
|
|
208
|
-
return taskLine("starting");
|
|
209
|
-
}
|
|
210
|
-
if (p.kind === "task-model") return taskLine("thinking");
|
|
211
|
-
if (p.kind === "task-tool") {
|
|
212
|
-
// 要用户批准的调用在审批时显示
|
|
213
|
-
if (p.decision === "ask") return;
|
|
214
|
-
const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summarize(cwd, p.name, p.input)})`;
|
|
215
|
-
steps.set(toolUseId, [...(steps.get(toolUseId) ?? []), step]);
|
|
216
|
-
return taskLine(step);
|
|
275
|
+
/** 工具的进度:有 renderer 的 progress 时由它换成一行;否则 { text } 形式的按输出逐行显示(例如 bash),其他的不显示 */
|
|
276
|
+
function renderProgress(toolUseId: string, update: unknown) {
|
|
277
|
+
const name = toolNames.get(toolUseId) ?? "?";
|
|
278
|
+
if (opts.renderer?.(name)?.renderer.progress) {
|
|
279
|
+
const line = customSync(name, (r) => r.progress?.(update, { toolUseId, summary }));
|
|
280
|
+
if (typeof line === "string" && line) progress(toolUseId, clipStyled(line.split("\n")[0]!, 200));
|
|
281
|
+
return;
|
|
217
282
|
}
|
|
218
|
-
|
|
219
|
-
if (typeof
|
|
220
|
-
for (const l of
|
|
283
|
+
const text = (update as { text?: unknown } | null)?.text;
|
|
284
|
+
if (typeof text !== "string") return;
|
|
285
|
+
for (const l of text.replace(/\n$/, "").split("\n")) progress(toolUseId, dim(` │ ${clip(l, 200)}`), { output: true });
|
|
221
286
|
}
|
|
222
287
|
|
|
223
288
|
function renderEvent(e: LogEvent) {
|
|
@@ -229,7 +294,7 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
229
294
|
case "model.responded": {
|
|
230
295
|
const d = e.data as EventDataMap["model.responded"];
|
|
231
296
|
void countUsage(e);
|
|
232
|
-
showContext(
|
|
297
|
+
showContext(e as LogEvent<"model.responded">);
|
|
233
298
|
if (!replaying) finishSpeed(d.usage);
|
|
234
299
|
for (const b of d.content) if (b.kind === "tool_use") toolNames.set(b.id, b.name);
|
|
235
300
|
// 不支持流式的 provider、重新显示历史:一次送出最终文本,和流式输出一样排版
|
|
@@ -244,22 +309,31 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
244
309
|
case "tool.decided": {
|
|
245
310
|
const d = e.data as EventDataMap["tool.decided"];
|
|
246
311
|
const name = toolNames.get(d.toolUseId) ?? "?";
|
|
247
|
-
const full =
|
|
312
|
+
const full = details(name, d.input);
|
|
248
313
|
if (full) calls.set(d.toolUseId, full);
|
|
314
|
+
if (opts.renderer?.(name)?.renderer.result) inputs.set(d.toolUseId, d.input);
|
|
249
315
|
if (d.decision === "ask") return;
|
|
250
|
-
|
|
316
|
+
// 执行前交给 renderer 的 before(例如按文件当时的内容算 diff);重新显示历史时文件已经变了,不调用
|
|
317
|
+
if (d.decision === "allow" && !replaying) {
|
|
318
|
+
const before = customSync(name, (r) => r.before?.(d.input));
|
|
319
|
+
if (before !== undefined) befores.set(d.toolUseId, before);
|
|
320
|
+
}
|
|
321
|
+
const head = `${bold(name)}(${summary(name, d.input)})`;
|
|
251
322
|
if (d.decision === "deny") screen.log(red(`✗ ${head}`) + dim(d.reason ? ` — ${clip(d.reason, 200)}` : ""), { id: d.toolUseId, details: full });
|
|
252
323
|
else {
|
|
253
324
|
activity(`Running ${name}`);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
325
|
+
// 用户批准的调用在审批时已经显示过;重新显示历史时没有审批这一步
|
|
326
|
+
if (d.decidedBy !== "user" || replaying) {
|
|
327
|
+
const own = customSync(name, (r) => r.call?.(d.input));
|
|
328
|
+
if (typeof own === "string" && own) {
|
|
329
|
+
// renderer 给的内容:第一行是调用行(结果接在它后面),其余的行不折叠
|
|
330
|
+
const [first, ...rest] = own.split("\n");
|
|
331
|
+
screen.log(cyan("● ") + first, { id: d.toolUseId, details: full });
|
|
332
|
+
if (rest.length) screen.log(rest.join("\n"));
|
|
333
|
+
} else {
|
|
334
|
+
// auto 模式下审查放行的带着理由
|
|
335
|
+
screen.log(cyan("● ") + head + (d.reason ? dim(` — ${clip(d.reason, 160)}`) : ""), { id: d.toolUseId, details: full });
|
|
336
|
+
}
|
|
263
337
|
}
|
|
264
338
|
}
|
|
265
339
|
return;
|
|
@@ -269,25 +343,31 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
269
343
|
void countUsage(e);
|
|
270
344
|
activity("Working");
|
|
271
345
|
doneProgress(d.toolUseId);
|
|
272
|
-
const sub = steps.get(d.toolUseId) ?? [];
|
|
273
|
-
steps.delete(d.toolUseId);
|
|
274
|
-
tasks.delete(d.toolUseId);
|
|
275
346
|
const call = calls.get(d.toolUseId);
|
|
276
347
|
calls.delete(d.toolUseId);
|
|
277
|
-
|
|
348
|
+
const before = befores.get(d.toolUseId);
|
|
349
|
+
befores.delete(d.toolUseId);
|
|
350
|
+
const input = inputs.get(d.toolUseId);
|
|
351
|
+
inputs.delete(d.toolUseId);
|
|
278
352
|
const text = textOf(d.content).trim();
|
|
353
|
+
const name = toolNames.get(d.toolUseId) ?? "?";
|
|
354
|
+
const mine = customSync(name, (r) => r.result?.({ toolUseId: d.toolUseId, input, text, isError: d.isError === true, before }));
|
|
355
|
+
// null:renderer 不要显示结果
|
|
356
|
+
if (mine === null) return;
|
|
357
|
+
if (mine && typeof mine.line === "string") {
|
|
358
|
+
const own = typeof mine.details === "string" && mine.details ? [mine.details.replace(/^/gm, " ")] : [];
|
|
359
|
+
const folded = [...(call ? [call] : []), ...own].join("\n") || undefined;
|
|
360
|
+
screen.amend(d.toolUseId, (d.isError ? red : dim)("⎿ ") + clipStyled(mine.line.split("\n")[0]!, 200), { details: folded });
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
279
363
|
const lines = text.split("\n");
|
|
280
364
|
// 结果接在调用的那一行后面;摘要省略了内容时,把完整结果(和子 Agent 调用过的工具)折叠起来,点击展开
|
|
281
365
|
const shown = d.isError ? 4 : 1;
|
|
282
366
|
const width = d.isError ? 200 : 160;
|
|
283
|
-
const hidden =
|
|
367
|
+
const hidden = lines.length > shown || lines.some((l) => l.length > width);
|
|
284
368
|
const details =
|
|
285
369
|
hidden || call
|
|
286
|
-
? [
|
|
287
|
-
...(call ? [call] : []),
|
|
288
|
-
...(sub.length ? [dim(` sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`))] : []),
|
|
289
|
-
...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : []),
|
|
290
|
-
].join("\n")
|
|
370
|
+
? [...(call ? [call] : []), ...(hidden ? [detailsOf(lines, d.isError ? red : (s) => s, MAX_DETAIL_LINES)] : [])].join("\n")
|
|
291
371
|
: undefined;
|
|
292
372
|
if (d.isError) screen.amend(d.toolUseId, red(`⎿ ${lines.slice(0, shown).map((l) => clip(l, width)).join("\n ")}`), { details });
|
|
293
373
|
else screen.amend(d.toolUseId, dim(`⎿ ${clip(lines[0] ?? "", width)}${lines.length > 1 ? ` (+${lines.length - 1} lines)` : ""}`), { details });
|
|
@@ -296,8 +376,9 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
296
376
|
case "tool.interrupted": {
|
|
297
377
|
const d = e.data as EventDataMap["tool.interrupted"];
|
|
298
378
|
doneProgress(d.toolUseId);
|
|
299
|
-
tasks.delete(d.toolUseId);
|
|
300
379
|
calls.delete(d.toolUseId);
|
|
380
|
+
befores.delete(d.toolUseId);
|
|
381
|
+
inputs.delete(d.toolUseId);
|
|
301
382
|
screen.amend(d.toolUseId, yellow("⎿ interrupted before finishing; not retried"));
|
|
302
383
|
return;
|
|
303
384
|
}
|
|
@@ -316,42 +397,29 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
316
397
|
if (self.turnFailed && !replaying && opts.canRetry()) screen.log(dim("[send /retry to request again without adding a message]"));
|
|
317
398
|
return;
|
|
318
399
|
}
|
|
319
|
-
case "jade/compact/compacted": {
|
|
320
|
-
const d = e.data as { from: number; upTo: number; before: number };
|
|
321
|
-
void countUsage(e);
|
|
322
|
-
screen.log(dim(`[compacted ${d.upTo - d.from} messages, ~${d.before} tokens before]`));
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
case "jade/checks/checked": {
|
|
326
|
-
const d = e.data as { summary: { name: string; problems: number; others?: number; failed?: string }[]; report: string };
|
|
327
|
-
const bad = d.summary.filter((s) => s.problems > 0 || s.others || s.failed);
|
|
328
|
-
const details = d.report ? detailsOf(d.report.split("\n").slice(1), (s) => s, MAX_DETAIL_LINES) : undefined;
|
|
329
|
-
if (bad.length === 0) {
|
|
330
|
-
screen.log(dim(` ✓ checks passed: ${d.summary.map((s) => s.name).join(", ")}`), { details });
|
|
331
|
-
} else {
|
|
332
|
-
const what = bad.map((s) =>
|
|
333
|
-
s.failed
|
|
334
|
-
? `${s.name} ${s.failed}`
|
|
335
|
-
: `${s.name}: ${[s.problems > 0 ? `${s.problems} problem${s.problems > 1 ? "s" : ""} in changed files` : "", s.others ? `${s.others} new elsewhere` : ""]
|
|
336
|
-
.filter(Boolean)
|
|
337
|
-
.join(", ")}`,
|
|
338
|
-
);
|
|
339
|
-
screen.log(yellow(` ⚠ checks: ${what.join("; ")}`), { details });
|
|
340
|
-
}
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
case "jade/policy/reviewed":
|
|
344
|
-
// 审查的结果显示在工具调用那一行,这里只计用量
|
|
345
|
-
void countUsage(e);
|
|
346
|
-
return;
|
|
347
|
-
case "jade/compact/trimmed": {
|
|
348
|
-
const d = e.data as { saved: number };
|
|
349
|
-
screen.log(dim(`[cleared old tool output, ~${d.saved} tokens]`));
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
400
|
default:
|
|
353
|
-
return
|
|
401
|
+
return renderPluginEvent(e);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* 插件的事件:用量照常统计;插件为它注册了渲染器时由渲染器显示,
|
|
407
|
+
* 否则只有 ctx.emit("notice", { text, level? }) 写入的提示显示成 [插件 id] 文本
|
|
408
|
+
*/
|
|
409
|
+
function renderPluginEvent(e: LogEvent) {
|
|
410
|
+
if (e.origin.by !== "plugin") return;
|
|
411
|
+
void countUsage(e);
|
|
412
|
+
const found = opts.eventRenderer?.(e.type);
|
|
413
|
+
if (!found) return renderPluginNotice(e);
|
|
414
|
+
let shown: ReturnType<EventRenderer["render"]>;
|
|
415
|
+
try {
|
|
416
|
+
shown = found.renderer.render(e.data);
|
|
417
|
+
} catch (err) {
|
|
418
|
+
return renderFailed(found.plugin, e.type, err);
|
|
354
419
|
}
|
|
420
|
+
if (!shown || typeof shown.line !== "string") return;
|
|
421
|
+
const details = typeof shown.details === "string" && shown.details ? shown.details.replace(/^/gm, " ") : undefined;
|
|
422
|
+
screen.log(shown.line, { details });
|
|
355
423
|
}
|
|
356
424
|
|
|
357
425
|
/** 插件用 ctx.emit("notice", { text, level? }) 写入的提示,显示成 [插件 id] 文本 */
|
|
@@ -367,7 +435,7 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
367
435
|
if (!show) {
|
|
368
436
|
for (const e of events) {
|
|
369
437
|
await countUsage(e);
|
|
370
|
-
if (e.type === "model.responded") showContext(
|
|
438
|
+
if (e.type === "model.responded") showContext(e as LogEvent<"model.responded">);
|
|
371
439
|
}
|
|
372
440
|
return;
|
|
373
441
|
}
|
|
@@ -387,10 +455,10 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
387
455
|
const d = e.data as EventDataMap["input.received"];
|
|
388
456
|
if (d.kind === "approval") {
|
|
389
457
|
const name = toolNames.get(d.toolUseId) ?? "?";
|
|
390
|
-
const head = `${bold(name)}(${
|
|
458
|
+
const head = `${bold(name)}(${summary(name, asked.get(d.toolUseId))})`;
|
|
391
459
|
screen.log(d.approved ? green(`✓ ${head}`) : red(`✗ ${head}`) + dim(d.reason ? ` — ${clip(d.reason, 200)}` : ""), {
|
|
392
460
|
id: d.toolUseId,
|
|
393
|
-
details:
|
|
461
|
+
details: details(name, asked.get(d.toolUseId)),
|
|
394
462
|
});
|
|
395
463
|
continue;
|
|
396
464
|
}
|