@uncarved/jade 0.2.1 → 0.3.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/README.md +64 -2
- package/assets/logo.svg +1 -0
- package/bin/jade.js +4 -0
- package/dist/api.d.ts +5 -250
- package/dist/api.js +5 -7
- package/dist/api.js.map +1 -1
- package/dist/fetch.d.ts +8 -0
- package/dist/fetch.js +19 -17
- package/dist/fetch.js.map +1 -1
- package/dist/host.d.ts +12 -1
- package/dist/host.js +49 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +26 -4
- package/dist/main.js.map +1 -1
- package/dist/remote.js +4 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/dist/session.js +133 -13
- package/dist/session.js.map +1 -1
- package/dist/source.d.ts +2 -10
- package/dist/source.js.map +1 -1
- package/dist/update.d.ts +8 -20
- package/dist/update.js +12 -1
- package/dist/update.js.map +1 -1
- package/package.json +4 -2
- package/plugins/approval/index.ts +233 -85
- package/plugins/approval/plugin.json +1 -1
- package/plugins/approval/policy.ts +2 -1
- package/plugins/approval/review.ts +1 -1
- package/plugins/ask/index.ts +2 -2
- package/plugins/budget/index.ts +1 -1
- package/plugins/checks/checks.ts +3 -2
- package/plugins/checks/index.ts +2 -5
- package/plugins/commands/index.ts +2 -44
- package/plugins/compact/compact.ts +8 -3
- package/plugins/compact/index.ts +13 -16
- package/plugins/continue/index.ts +1 -1
- package/plugins/cost/index.ts +143 -0
- package/plugins/cost/plugin.json +13 -0
- package/plugins/custom-commands/index.ts +85 -0
- package/plugins/custom-commands/plugin.json +8 -0
- package/plugins/editor/index.ts +88 -0
- package/plugins/editor/plugin.json +17 -0
- package/plugins/fs/fs.ts +33 -6
- package/plugins/fs/grep.ts +6 -4
- package/plugins/fs/index.ts +2 -3
- package/plugins/fs/renderers.ts +1 -1
- package/plugins/hooks/index.ts +152 -0
- package/plugins/hooks/plugin.json +14 -0
- package/plugins/keys/index.ts +2 -18
- package/plugins/mcp/index.ts +40 -12
- package/plugins/mcp/install.ts +139 -0
- package/plugins/mcp/mcp.ts +2 -1
- package/plugins/mcp/plugin.json +1 -1
- package/plugins/mcp/project.ts +37 -1
- package/plugins/memory/index.ts +4 -9
- package/plugins/memory/plugin.json +1 -1
- package/plugins/mentions/index.ts +2 -2
- package/plugins/models/configure.ts +258 -150
- package/plugins/models/context.ts +2 -2
- package/plugins/models/index.ts +35 -42
- package/plugins/models/plugin.json +1 -1
- package/plugins/models/provider.ts +22 -4
- package/plugins/models/saved.ts +8 -4
- package/plugins/modes/index.ts +2 -17
- package/plugins/plugins/index.ts +2 -2
- package/plugins/print/index.ts +36 -6
- package/plugins/print/plugin.json +1 -0
- package/plugins/prompts/index.ts +22 -14
- package/plugins/{memory → prompts}/notes.ts +21 -9
- package/plugins/prompts/plugin.json +8 -2
- package/plugins/prompts/prompts.ts +5 -4
- package/plugins/renderers/index.ts +2 -43
- package/plugins/repeats/index.ts +1 -1
- package/plugins/schedule/index.ts +2 -2
- package/plugins/scratch/index.ts +2 -3
- package/plugins/screenshot/index.ts +26 -13
- package/plugins/screenshot/plugin.json +1 -1
- package/plugins/sessions/index.ts +2 -17
- package/plugins/shell/index.ts +56 -6
- package/plugins/shell/plugin.json +3 -1
- package/plugins/shell/renderers.ts +1 -1
- package/plugins/shell/service.ts +2 -13
- package/plugins/shell/shell.ts +31 -16
- package/plugins/skills/index.ts +172 -37
- package/plugins/skills/install.ts +212 -0
- package/plugins/skills/plugin.json +3 -2
- package/plugins/skills/project.ts +38 -1
- package/plugins/skills/skills.ts +28 -9
- package/plugins/steer/index.ts +142 -0
- package/plugins/steer/plugin.json +8 -0
- package/plugins/suggest/index.ts +16 -11
- package/plugins/suggest/plugin.json +1 -1
- package/plugins/task/index.ts +7 -16
- package/plugins/task/plugin.json +9 -2
- package/plugins/task/subagent.ts +23 -5
- package/plugins/todo/index.ts +2 -2
- package/plugins/tui/editor.ts +10 -2
- package/plugins/tui/frontend.ts +103 -21
- package/plugins/tui/index.ts +3 -8
- package/plugins/tui/markdown.ts +51 -6
- package/plugins/tui/mascot.ts +505 -0
- package/plugins/tui/plugin.json +2 -2
- package/plugins/tui/screen.ts +6 -0
- package/plugins/tui/transcript.ts +17 -2
- package/plugins/tui/tui.ts +321 -90
- package/plugins/undo/checkpoint.ts +2 -2
- package/plugins/undo/index.ts +84 -26
- package/plugins/undo/plugin.json +8 -2
- package/plugins/undo/snapshot.ts +129 -0
- package/plugins/update/index.ts +11 -15
- package/plugins/update/plugin.json +2 -1
- package/plugins/web/index.ts +2 -5
- package/plugins/web/renderers.ts +1 -1
- package/plugins-dist/approval/index.js +217 -51
- package/plugins-dist/approval/plugin.json +1 -1
- package/plugins-dist/ask/index.js +1 -1
- package/plugins-dist/budget/index.js +1 -1
- package/plugins-dist/checks/checks.js +2 -1
- package/plugins-dist/checks/index.js +1 -1
- package/plugins-dist/commands/index.js +1 -1
- package/plugins-dist/compact/compact.js +6 -1
- package/plugins-dist/compact/index.js +12 -8
- package/plugins-dist/continue/index.js +1 -1
- package/plugins-dist/cost/index.js +135 -0
- package/plugins-dist/cost/plugin.json +16 -0
- package/plugins-dist/custom-commands/index.js +86 -0
- package/plugins-dist/custom-commands/plugin.json +12 -0
- package/plugins-dist/editor/index.js +89 -0
- package/plugins-dist/editor/plugin.json +21 -0
- package/plugins-dist/fs/fs.js +34 -6
- package/plugins-dist/fs/grep.js +5 -3
- package/plugins-dist/fs/index.js +1 -1
- package/plugins-dist/hooks/index.js +145 -0
- package/plugins-dist/hooks/plugin.json +19 -0
- package/plugins-dist/keys/index.js +1 -1
- package/plugins-dist/mcp/index.js +41 -9
- package/plugins-dist/mcp/install.js +160 -0
- package/plugins-dist/mcp/mcp.js +2 -1
- package/plugins-dist/mcp/plugin.json +2 -1
- package/plugins-dist/mcp/project.js +42 -1
- package/plugins-dist/memory/index.js +3 -5
- package/plugins-dist/memory/plugin.json +1 -1
- package/plugins-dist/mentions/index.js +1 -1
- package/plugins-dist/models/configure.js +252 -151
- package/plugins-dist/models/context.js +2 -2
- package/plugins-dist/models/index.js +37 -14
- package/plugins-dist/models/plugin.json +1 -1
- package/plugins-dist/models/provider.js +4 -2
- package/plugins-dist/models/saved.js +9 -4
- package/plugins-dist/modes/index.js +1 -1
- package/plugins-dist/plugins/index.js +1 -1
- package/plugins-dist/print/index.js +37 -3
- package/plugins-dist/print/plugin.json +3 -0
- package/plugins-dist/prompts/index.js +22 -3
- package/plugins-dist/{memory → prompts}/notes.js +10 -7
- package/plugins-dist/prompts/plugin.json +8 -2
- package/plugins-dist/prompts/prompts.js +5 -4
- package/plugins-dist/renderers/index.js +1 -1
- package/plugins-dist/repeats/index.js +1 -1
- package/plugins-dist/schedule/index.js +1 -1
- package/plugins-dist/scratch/index.js +1 -1
- package/plugins-dist/screenshot/index.js +25 -11
- package/plugins-dist/screenshot/plugin.json +1 -1
- package/plugins-dist/sessions/index.js +1 -1
- package/plugins-dist/shell/index.js +55 -3
- package/plugins-dist/shell/plugin.json +3 -1
- package/plugins-dist/shell/shell.js +26 -8
- package/plugins-dist/skills/index.js +184 -35
- package/plugins-dist/skills/install.js +178 -0
- package/plugins-dist/skills/plugin.json +6 -2
- package/plugins-dist/skills/project.js +43 -1
- package/plugins-dist/skills/skills.js +27 -10
- package/plugins-dist/steer/index.js +135 -0
- package/plugins-dist/steer/plugin.json +12 -0
- package/plugins-dist/suggest/index.js +15 -9
- package/plugins-dist/suggest/plugin.json +1 -1
- package/plugins-dist/task/index.js +6 -4
- package/plugins-dist/task/plugin.json +10 -2
- package/plugins-dist/task/subagent.js +20 -5
- package/plugins-dist/todo/index.js +1 -1
- package/plugins-dist/tui/editor.js +7 -2
- package/plugins-dist/tui/frontend.js +107 -13
- package/plugins-dist/tui/index.js +2 -1
- package/plugins-dist/tui/markdown.js +48 -6
- package/plugins-dist/tui/mascot.js +439 -0
- package/plugins-dist/tui/plugin.json +3 -2
- package/plugins-dist/tui/screen.js +2 -0
- package/plugins-dist/tui/transcript.js +16 -1
- package/plugins-dist/tui/tui.js +302 -81
- package/plugins-dist/undo/checkpoint.js +1 -1
- package/plugins-dist/undo/index.js +91 -24
- package/plugins-dist/undo/plugin.json +10 -3
- package/plugins-dist/undo/snapshot.js +111 -0
- package/plugins-dist/update/index.js +9 -10
- package/plugins-dist/update/plugin.json +4 -1
- package/plugins-dist/web/index.js +1 -1
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +8 -0
- package/src/api.ts +7 -262
- package/src/fetch.ts +18 -16
- package/src/host.ts +49 -1
- package/src/index.ts +1 -1
- package/src/main.ts +23 -5
- package/src/remote.ts +2 -0
- package/src/session.ts +134 -15
- package/src/source.ts +2 -11
- package/src/update.ts +16 -10
- package/plugins/undo/notes.ts +0 -43
- package/plugins-dist/undo/notes.js +0 -36
|
@@ -77,7 +77,49 @@ export function markdownStream() {
|
|
|
77
77
|
export function renderMarkdown(text, width) {
|
|
78
78
|
const md = markdownStream();
|
|
79
79
|
const out = [...text.split("\n").flatMap((l) => md.push(l)), ...md.flush()];
|
|
80
|
-
return out.flatMap((l) => (typeof l === "string" ? [l] : l.render(width)));
|
|
80
|
+
return out.flatMap((l) => (typeof l === "string" ? [l] : l.render(width))).map(visibleRow);
|
|
81
|
+
}
|
|
82
|
+
// ---------- 自动折行的记号 ----------
|
|
83
|
+
//
|
|
84
|
+
// 一行太长折成屏幕上的几行时,后面的几行(续行)开头带一个看不见的记号:用鼠标选中复制时,续行接回上一行,
|
|
85
|
+
// 而不是变成换行。记号只用几个控制字符(显示之前去掉;外面来的文字里的控制字符早被 safeScreen 去掉了,不会撞上):
|
|
86
|
+
// \x1f \x1e × gap \x1d × indent \x1c
|
|
87
|
+
// gap:折行时上一行行尾去掉了几个空格,接回去时补上;indent:续行开头排版加的几列(列表的缩进、代码块的竖线),接回去时跳过
|
|
88
|
+
const SOFT_HEAD = /^\x1f(\x1e*)(\x1d*)\x1c/;
|
|
89
|
+
/** 把一行标成续行 */
|
|
90
|
+
export const softRow = (row, gap = 0, indent = 0) => `\x1f${"\x1e".repeat(gap)}${"\x1d".repeat(indent)}\x1c${row}`;
|
|
91
|
+
/** 去掉记号,得到要显示的那一行 */
|
|
92
|
+
export const visibleRow = (row) => (row.charCodeAt(0) === 0x1f ? row.replace(SOFT_HEAD, "") : row);
|
|
93
|
+
/** 一行是不是续行,以及接回上一行时要补的空格数、要跳过的列数;text 是去掉记号的那一行 */
|
|
94
|
+
export function softInfo(row) {
|
|
95
|
+
const m = row.charCodeAt(0) === 0x1f ? SOFT_HEAD.exec(row) : null;
|
|
96
|
+
if (!m)
|
|
97
|
+
return { text: row, soft: false, gap: 0, indent: 0 };
|
|
98
|
+
return { text: row.slice(m[0].length), soft: true, gap: m[1].length, indent: m[2].length };
|
|
99
|
+
}
|
|
100
|
+
const WRAP = { hard: true, trim: false };
|
|
101
|
+
/**
|
|
102
|
+
* 按显示宽度折行,保留颜色;每一项是屏幕上的一行,续行带记号。制表符先换成空格:按 0 列算宽度会对不齐、超宽。
|
|
103
|
+
* 不去掉空格(trim: false),所以续行直接接在上一行后面就是原文
|
|
104
|
+
*/
|
|
105
|
+
export function wrapRows(text, width) {
|
|
106
|
+
const expanded = expandTabs(text);
|
|
107
|
+
// 整段一起折:颜色可能跨行,分开折会丢掉后面几行的颜色
|
|
108
|
+
const rows = wrapAnsi(expanded, width, WRAP).split("\n");
|
|
109
|
+
const logical = expanded.split("\n");
|
|
110
|
+
if (rows.length === logical.length)
|
|
111
|
+
return rows;
|
|
112
|
+
// 每个原来的行占了几行:放得下的占一行,放不下的单独折一次数出来(颜色不占宽度,不影响在哪里折)
|
|
113
|
+
const counts = logical.map((l) => (stringWidth(l) <= width ? 1 : wrapAnsi(l, width, WRAP).split("\n").length));
|
|
114
|
+
if (counts.reduce((a, b) => a + b, 0) !== rows.length)
|
|
115
|
+
return rows;
|
|
116
|
+
let at = 0;
|
|
117
|
+
for (const n of counts) {
|
|
118
|
+
for (let i = 1; i < n; i++)
|
|
119
|
+
rows[at + i] = softRow(rows[at + i]);
|
|
120
|
+
at += n;
|
|
121
|
+
}
|
|
122
|
+
return rows;
|
|
81
123
|
}
|
|
82
124
|
/** 代码块和表格以外的一行 */
|
|
83
125
|
function renderLine(line) {
|
|
@@ -148,11 +190,11 @@ export function expandTabs(text, stop = 4) {
|
|
|
148
190
|
function hanging(head, body, rest = " ".repeat(stringWidth(head))) {
|
|
149
191
|
return {
|
|
150
192
|
render: (width) => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
193
|
+
const indent = stringWidth(head);
|
|
194
|
+
const room = Math.max(1, width - indent);
|
|
195
|
+
const rows = wrapAnsi(expandTabs(body), room, WRAP).split("\n");
|
|
196
|
+
// 折行处留下的行尾空格看不见,去掉免得多占一列;去掉了几个记在续行的记号里,复制时补回去
|
|
197
|
+
return rows.map((r, i) => (i === 0 ? head + r.trimEnd() : softRow(rest + r.trimEnd(), rows[i - 1].length - rows[i - 1].trimEnd().length, indent)));
|
|
156
198
|
},
|
|
157
199
|
};
|
|
158
200
|
}
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
// 标题左边的吉祥物:一个玉做的团子,按当前在做的事换表情、带一点动画;还有终端标签页标题上的 jade 标志。
|
|
2
|
+
// 不碰 Ink:动画由 App 统一重画推动(见 tui.ts 的 tick),这里每次按时间算出这一帧。
|
|
3
|
+
//
|
|
4
|
+
// 画布 15×6 个像素,每格字符上下两个像素(▀ 前景是上面、背景是下面),6 个像素高正好三行,和右边三行文字并排。
|
|
5
|
+
// 左边 9 列是身体,空一列,右边 5 列放表情以外的小东西(思考的三个点、工具的转圈、提问的感叹号、做完的 ✓……都用像素画)。画布宽度不随表情变,标题右边的文字不会跟着左右跳。
|
|
6
|
+
//
|
|
7
|
+
// 精度只有这么多,细节靠颜色:身体按光照着色(左上亮、边缘暗、一点高光),眼睛是深色的形状,
|
|
8
|
+
// 每个像素按 4×4 次采样算出眼睛盖住了多少、和身体的颜色混合,所以眼睛可以不按整格移动、眨眼也有中间的几帧。
|
|
9
|
+
// 身体外面是终端背景,颜色未知、没法混合,所以轮廓只按整格变(只有做完后蹦那一下会变)、混色只在身体里面做。
|
|
10
|
+
// 视线、睁眼的程度、颜色在状态之间缓动(Mascot),不会一下跳过去。
|
|
11
|
+
export const JADE = "#00a86b";
|
|
12
|
+
/** 做完后笑多久 */
|
|
13
|
+
export const HAPPY_MS = 4000;
|
|
14
|
+
export function moodOf(s, now) {
|
|
15
|
+
if (s.asking)
|
|
16
|
+
return "asking";
|
|
17
|
+
const b = s.busy;
|
|
18
|
+
if (b === undefined)
|
|
19
|
+
return s.doneAt !== undefined && now - s.doneAt < HAPPY_MS ? "happy" : "idle";
|
|
20
|
+
if (b === "Interrupting")
|
|
21
|
+
return "stopping";
|
|
22
|
+
if (b === "Thinking")
|
|
23
|
+
return "thinking";
|
|
24
|
+
if (b.startsWith("Writing"))
|
|
25
|
+
return "writing";
|
|
26
|
+
if (b.startsWith("Running "))
|
|
27
|
+
return "tool";
|
|
28
|
+
return "waiting";
|
|
29
|
+
}
|
|
30
|
+
const rgb = (hex) => [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16));
|
|
31
|
+
const hex = (c) => `#${c.map((v) => Math.round(Math.max(0, Math.min(255, v))).toString(16).padStart(2, "0")).join("")}`;
|
|
32
|
+
const mix = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
33
|
+
/** 按 t(0–1)在一串颜色之间插值 */
|
|
34
|
+
const ramp = (stops, t) => {
|
|
35
|
+
const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);
|
|
36
|
+
const i = Math.min(stops.length - 2, Math.floor(x));
|
|
37
|
+
return mix(stops[i], stops[i + 1], x - i);
|
|
38
|
+
};
|
|
39
|
+
/** 从暗到亮的玉色;中断时换成琥珀色那一套 */
|
|
40
|
+
const JADE_RAMP = ["#004a33", "#00744c", JADE, "#2ccc8a", "#8eeec0"].map(rgb);
|
|
41
|
+
const AMBER_RAMP = ["#5a3a00", "#9a6500", "#e0a526", "#f4c75a", "#fde4a0"].map(rgb);
|
|
42
|
+
const SPECULAR = rgb("#effff6");
|
|
43
|
+
const EYE = rgb("#0b2219");
|
|
44
|
+
const PALE = rgb("#b6f2d4");
|
|
45
|
+
const DEEP = rgb("#00744c");
|
|
46
|
+
const BANG = [rgb("#f5c518"), rgb("#fff1a8")];
|
|
47
|
+
const SWEAT = rgb("#8fd3ff");
|
|
48
|
+
/** 蹦起来时地上的影子:身体外面没法和终端背景混合,用一个暗的玉色 */
|
|
49
|
+
const SHADOW = mix(DEEP, EYE, 0.55);
|
|
50
|
+
// ---------- 形状 ----------
|
|
51
|
+
const W = 15;
|
|
52
|
+
/** 右边小东西的第一列:和身体之间空一列,不贴着 */
|
|
53
|
+
const SIDE = 10;
|
|
54
|
+
const H = 6;
|
|
55
|
+
/** 身体的轮廓(9 列),轮廓外是终端背景 */
|
|
56
|
+
const MASK = ["..#####..", ".#######.", "#########", "#########", "#########", ".#######."];
|
|
57
|
+
const CX = 4.5;
|
|
58
|
+
const SHAPES = {
|
|
59
|
+
rest: { mask: MASK, top: 0, bottom: 6, dy: 0 },
|
|
60
|
+
crouch: { mask: [".........", ".#######.", "#########", "#########", "#########", ".#######."], top: 1, bottom: 6, dy: 1 },
|
|
61
|
+
air: { mask: ["..#####..", ".#######.", "#########", "#########", ".#######.", "........."], top: 0, bottom: 5, dy: -1 },
|
|
62
|
+
};
|
|
63
|
+
/** 做完后的一跳:蹲下蓄力 → 跳起 → 落地压扁一下 → 站好(t 是进入 happy 之后的毫秒) */
|
|
64
|
+
const HOP = { crouch: 90, air: 380, land: 470 };
|
|
65
|
+
function shapeAt(mood, t) {
|
|
66
|
+
if (mood !== "happy" || t >= HOP.land)
|
|
67
|
+
return SHAPES.rest;
|
|
68
|
+
return t < HOP.crouch || t >= HOP.air ? SHAPES.crouch : SHAPES.air;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 两只眼睛:中心的 x、下沿的 y(像素坐标,像素 (x, y) 覆盖 [x, x+1)×[y, y+1)),宽 1、高 2 个像素。
|
|
72
|
+
* 停住的位置都正好对齐像素,眼睛是清楚的两块;只有移动、眨眼的中间几帧才会混出过渡色
|
|
73
|
+
*/
|
|
74
|
+
const EYES_X = [2.5, 6.5];
|
|
75
|
+
const EYE_BOTTOM = 4;
|
|
76
|
+
const EYE_H = 2;
|
|
77
|
+
const smooth = (t) => {
|
|
78
|
+
const x = Math.max(0, Math.min(1, t));
|
|
79
|
+
return x * x * (3 - 2 * x);
|
|
80
|
+
};
|
|
81
|
+
const gauss = (dx, dy, s) => Math.exp(-(dx * dx + dy * dy) / (2 * s * s));
|
|
82
|
+
const REST = { gx: 0, gy: 0, open: 1, happy: 0, wink: 0, tint: 0, glow: 0 };
|
|
83
|
+
// ---------- 时间轴 ----------
|
|
84
|
+
const ease = (now, keys, period) => {
|
|
85
|
+
// keys:[时刻, 值],时刻在 [0, period) 里递增;相邻两个之间平滑过渡,最后一个过渡回第一个
|
|
86
|
+
const t = now % period;
|
|
87
|
+
for (let i = 0; i < keys.length; i++) {
|
|
88
|
+
const [t0, v0] = keys[i];
|
|
89
|
+
const [t1raw, v1] = keys[(i + 1) % keys.length];
|
|
90
|
+
const t1 = i + 1 < keys.length ? t1raw : t1raw + period;
|
|
91
|
+
if (t >= t0 && t < t1)
|
|
92
|
+
return v0 + (v1 - v0) * smooth((t - t0) / (t1 - t0));
|
|
93
|
+
}
|
|
94
|
+
return keys[0][1];
|
|
95
|
+
};
|
|
96
|
+
/** 关键帧之间停一会儿再动:每个值先停 hold 毫秒,再用 move 毫秒移到下一个 */
|
|
97
|
+
const steps = (values, hold, move) => {
|
|
98
|
+
const keys = [];
|
|
99
|
+
values.forEach((v, i) => {
|
|
100
|
+
keys.push([i * (hold + move), v], [i * (hold + move) + hold, v]);
|
|
101
|
+
});
|
|
102
|
+
return [keys, values.length * (hold + move)];
|
|
103
|
+
};
|
|
104
|
+
/** 每隔多久眨一次眼,眨一下多久 */
|
|
105
|
+
const BLINK_EVERY = 4200;
|
|
106
|
+
const BLINK_MS = 220;
|
|
107
|
+
/** 空闲时每隔多久往旁边瞟一眼,从什么时候到什么时候 */
|
|
108
|
+
const GLANCE_EVERY = 11_000;
|
|
109
|
+
const GLANCE = [7000, 8600];
|
|
110
|
+
/** 眨眼:返回睁眼程度的系数。每第三次连眨两下 */
|
|
111
|
+
function blink(now) {
|
|
112
|
+
const n = Math.floor(now / BLINK_EVERY);
|
|
113
|
+
const t = now % BLINK_EVERY;
|
|
114
|
+
const one = (t0) => (t >= t0 && t < t0 + BLINK_MS ? 1 - Math.sin((Math.PI * (t - t0)) / BLINK_MS) : 1);
|
|
115
|
+
return Math.min(one(0), n % 3 === 2 ? one(BLINK_MS + 90) : 1);
|
|
116
|
+
}
|
|
117
|
+
/** 做完后什么时候回过头眨眼(落地后先看着 ✓ 画出来) */
|
|
118
|
+
const WINK_AT = 1500;
|
|
119
|
+
/** 这个状态此刻想要的样子(Mascot 往这里缓动);t 是进入这个状态之后的毫秒,只有 happy 用 */
|
|
120
|
+
export function goal(mood, now, t = HAPPY_MS / 2) {
|
|
121
|
+
switch (mood) {
|
|
122
|
+
case "idle": {
|
|
123
|
+
const t = now % GLANCE_EVERY;
|
|
124
|
+
const look = t >= GLANCE[0] && t < GLANCE[1] ? -1 : 0;
|
|
125
|
+
return { ...REST, gx: look, open: blink(now) };
|
|
126
|
+
}
|
|
127
|
+
case "waiting": {
|
|
128
|
+
const [keys, period] = steps([0, -1, 0, 1], 600, 350);
|
|
129
|
+
return { ...REST, gx: ease(now, keys, period), open: blink(now) };
|
|
130
|
+
}
|
|
131
|
+
case "thinking": {
|
|
132
|
+
// 琢磨:眯起眼往左上方望,身体一点点亮起来(在攒想法);
|
|
133
|
+
// 想到了:睁开眼转向右上角,看着三个点一个个冒出来,攒的亮光随着点冒出来慢慢退掉
|
|
134
|
+
const gx = ease(now, [[0, -1], [THINK.ponder - 350, -1], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
135
|
+
const open = ease(now, [[0, 0.5], [THINK.ponder - 350, 0.5], [THINK.ponder, 1], [THINK.period - 350, 1]], THINK.period);
|
|
136
|
+
const glow = ease(now, [[0, 0], [THINK.ponder, 0.75], [THINK.dot(2), 0]], THINK.period);
|
|
137
|
+
return { ...REST, gx, gy: -1, open: open * blink(now + 1700), glow };
|
|
138
|
+
}
|
|
139
|
+
case "writing": {
|
|
140
|
+
// 读着刚写的字:一行里从左往右扫,到头回来
|
|
141
|
+
const [keys, period] = steps([-1, 0, 1], 260, 140);
|
|
142
|
+
return { ...REST, gx: ease(now, keys, period), gy: 1, open: 0.5 + 0.5 * blink(now + 600) };
|
|
143
|
+
}
|
|
144
|
+
case "tool":
|
|
145
|
+
return { ...REST, gx: 1, open: blink(now + 900) };
|
|
146
|
+
case "asking":
|
|
147
|
+
return { ...REST, open: 1.5 * blink(now + 2500) };
|
|
148
|
+
case "stopping":
|
|
149
|
+
return { ...REST, open: 0, tint: 1 };
|
|
150
|
+
case "happy": {
|
|
151
|
+
// 只有眼睛,不加嘴和脸红:别的表情都只靠眼睛,加了反而不像同一个。
|
|
152
|
+
// 蹦的时候 ^ ^;落地那一下身体一亮,睁眼看右边的 ✓ 画出来;然后回过头,左眼 ^ 冲你眨一下
|
|
153
|
+
const glow = t >= HOP.air ? Math.exp(-(t - HOP.air) / 260) : 0;
|
|
154
|
+
if (t < HOP.land)
|
|
155
|
+
return { ...REST, happy: 1, glow };
|
|
156
|
+
if (t < WINK_AT)
|
|
157
|
+
return { ...REST, gx: 1, glow };
|
|
158
|
+
return { ...REST, wink: 1 };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/** 画一帧:返回 6 行、每行 15 个颜色("#rrggbb"),undefined 是透明(终端背景);t 同 goal */
|
|
163
|
+
export function paint(p, mood, now, t = HAPPY_MS / 2) {
|
|
164
|
+
const shape = shapeAt(mood, t);
|
|
165
|
+
const cy = (shape.top + shape.bottom) / 2;
|
|
166
|
+
const half = (shape.bottom - shape.top) / 2;
|
|
167
|
+
const ramp_ = (t) => mix(ramp(JADE_RAMP, t), ramp(AMBER_RAMP, t), p.tint);
|
|
168
|
+
const grid = Array.from({ length: H }, () => Array(W).fill(undefined));
|
|
169
|
+
// 工具运行时,一道光从左往右扫过身体
|
|
170
|
+
const sweep = mood === "tool" ? ((now % 1400) / 1400) * 16 - 4 : undefined;
|
|
171
|
+
for (let y = 0; y < H; y++)
|
|
172
|
+
for (let x = 0; x < 9; x++) {
|
|
173
|
+
if (shape.mask[y]?.[x] !== "#")
|
|
174
|
+
continue;
|
|
175
|
+
const nx = (x + 0.5 - CX) / 4.5;
|
|
176
|
+
const ny = (y + 0.5 - cy) / half;
|
|
177
|
+
const r = Math.max(Math.abs(nx), Math.abs(ny) * 0.9, Math.hypot(nx, ny) * 0.82);
|
|
178
|
+
let light = 0.62 - 0.3 * ny - 0.14 * nx - 0.32 * smooth((r - 0.55) / 0.45) + 0.18 * p.glow;
|
|
179
|
+
if (sweep !== undefined)
|
|
180
|
+
light += 0.22 * Math.exp(-(((x - y * 0.5 - sweep) / 0.8) ** 2));
|
|
181
|
+
let c = ramp_(light);
|
|
182
|
+
// 高光:左上角一个像素,旁边一圈淡淡的
|
|
183
|
+
c = mix(c, SPECULAR, 0.9 * gauss(x - 2, y - shape.top - 1, 0.45));
|
|
184
|
+
// 眼睛:4×4 次采样,算出盖住了多少
|
|
185
|
+
let cover = 0;
|
|
186
|
+
for (let sy = 0; sy < 4; sy++)
|
|
187
|
+
for (let sx = 0; sx < 4; sx++) {
|
|
188
|
+
const px = x + (sx + 0.5) / 4;
|
|
189
|
+
const py = y + (sy + 0.5) / 4;
|
|
190
|
+
cover += eyeAt(p, px, py - shape.dy) / 16;
|
|
191
|
+
}
|
|
192
|
+
c = mix(c, mix(EYE, ramp_(0.05), p.tint * 0.4), Math.min(1, cover));
|
|
193
|
+
grid[y][x] = c;
|
|
194
|
+
}
|
|
195
|
+
// 跳在空中时脚下一块影子
|
|
196
|
+
if (shape === SHAPES.air)
|
|
197
|
+
for (let x = 3; x < 6; x++)
|
|
198
|
+
grid[5][x] = SHADOW;
|
|
199
|
+
for (const [x, y, c] of extras(mood, now, t))
|
|
200
|
+
grid[y][x] = c;
|
|
201
|
+
return grid.map((row) => row.map((c) => (c ? hex(c) : undefined)));
|
|
202
|
+
}
|
|
203
|
+
/** 眼睛在 (px, py) 处的覆盖(0 或 1):普通的眼睛和 ^ 形的笑眼按 happy 混合(左眼还算上 wink) */
|
|
204
|
+
function eyeAt(p, px, py) {
|
|
205
|
+
let best = 0;
|
|
206
|
+
for (const [i, bx] of EYES_X.entries()) {
|
|
207
|
+
const happy = i === 0 ? Math.max(p.happy, p.wink) : p.happy;
|
|
208
|
+
// 笑分两步:先是下眼皮往上推,眼睛压成上面一格的一条线(连续的);
|
|
209
|
+
// 推到头之后一下子变成 ^(像素画按帧换形状,滑过去的中间几帧是糊的)
|
|
210
|
+
const smile = happy > 0.6;
|
|
211
|
+
// 两只都变成 ^ 时各往外一格:^ 有三格宽,不挪开的话两只里边的眼角只隔一格,连成一排锯齿;
|
|
212
|
+
// 只眨一只眼时另一只是普通的眼睛,不会连起来,^ 留在原位
|
|
213
|
+
// ^ 对齐整格:从别的表情缓过来时视线还没回正,不对齐的话 ^ 是糊的
|
|
214
|
+
const out = p.happy > 0.6 ? (i === 0 ? -1 : 1) : 0;
|
|
215
|
+
const ex = smile ? Math.round(bx + p.gx - 0.5) + 0.5 + out : bx + p.gx;
|
|
216
|
+
const bottom = smile ? Math.round(EYE_BOTTOM + p.gy) : EYE_BOTTOM + p.gy;
|
|
217
|
+
if (Math.abs(px - ex) < 0.5) {
|
|
218
|
+
// 闭眼是上眼皮往下:下沿不动,高度变小,最少留 1 像素的一条线
|
|
219
|
+
const lower = bottom - Math.min(1, happy / 0.6);
|
|
220
|
+
const upper = Math.min(bottom - Math.max(1, EYE_H * p.open), lower - 1);
|
|
221
|
+
if (py >= upper && py < lower)
|
|
222
|
+
best = 1;
|
|
223
|
+
}
|
|
224
|
+
if (smile && Math.abs(Math.abs(px - ex) - 1) < 0.5 && py >= bottom - 1 && py < bottom)
|
|
225
|
+
best = 1;
|
|
226
|
+
}
|
|
227
|
+
return best;
|
|
228
|
+
}
|
|
229
|
+
/** 右边的小东西:[列, 行, 颜色],列是 SIDE 起的 0–4 */
|
|
230
|
+
function extras(mood, now, t) {
|
|
231
|
+
return side(mood, now, t).map(([x, y, c]) => [SIDE + x, y, c]);
|
|
232
|
+
}
|
|
233
|
+
/** ✓ 的五个像素,按笔画的顺序:短的一笔往右下,长的一笔往右上 */
|
|
234
|
+
const CHECK = [
|
|
235
|
+
[0, 3],
|
|
236
|
+
[1, 4],
|
|
237
|
+
[2, 3],
|
|
238
|
+
[3, 2],
|
|
239
|
+
[4, 1],
|
|
240
|
+
];
|
|
241
|
+
/** ✓ 落地后一笔画出来,每个像素隔多久;画完过一会儿一道光沿着笔画走一遍;最后按笔画的顺序暗下去消失 */
|
|
242
|
+
const CHECK_STEP = 55;
|
|
243
|
+
const CHECK_SHINE = 1900;
|
|
244
|
+
const CHECK_FADE = HAPPY_MS - 600;
|
|
245
|
+
function check(t) {
|
|
246
|
+
const white = rgb("#ffffff");
|
|
247
|
+
return CHECK.flatMap(([x, y], i) => {
|
|
248
|
+
const age = t - (HOP.land + i * CHECK_STEP);
|
|
249
|
+
if (age < 0)
|
|
250
|
+
return [];
|
|
251
|
+
// 刚画上的是白的笔尖,很快沉成淡玉色
|
|
252
|
+
let c = mix(PALE, white, Math.exp(-age / 120));
|
|
253
|
+
// 一道光:亮点沿着笔画走过去
|
|
254
|
+
c = mix(c, white, 0.85 * Math.exp(-(((t - CHECK_SHINE) / 60 - i) ** 2)));
|
|
255
|
+
// 消失:一个个暗下去再拿掉(外面是终端背景,没法渐隐)
|
|
256
|
+
const out = (t - CHECK_FADE - i * 70) / 280;
|
|
257
|
+
if (out >= 1)
|
|
258
|
+
return [];
|
|
259
|
+
if (out > 0)
|
|
260
|
+
c = mix(c, DEEP, out);
|
|
261
|
+
return [[x, y, c]];
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
const fade = (t) => ramp([DEEP, rgb(JADE), PALE], t);
|
|
265
|
+
/**
|
|
266
|
+
* 思考的节奏(一圈的毫秒数):先琢磨 ponder,然后三个点隔 gap 一个个冒出来;
|
|
267
|
+
* 三个都在了停一会儿,从 dim 起一起暗下去、拿掉,再接着琢磨
|
|
268
|
+
*/
|
|
269
|
+
const THINK = {
|
|
270
|
+
period: 4800,
|
|
271
|
+
ponder: 1700,
|
|
272
|
+
gap: 550,
|
|
273
|
+
/** 第 i 个点冒出来的时刻 */
|
|
274
|
+
dot: (i) => THINK.ponder + 250 + i * THINK.gap,
|
|
275
|
+
dim: 4200,
|
|
276
|
+
/** 暗下去用多久:之后拿掉(外面是终端背景,没法渐隐) */
|
|
277
|
+
fade: 400,
|
|
278
|
+
};
|
|
279
|
+
/** 三个点:在右上方从左往右排成一排,和往右上看的眼睛同一高度附近,像省略号 */
|
|
280
|
+
const DOTS = [
|
|
281
|
+
[0, 1],
|
|
282
|
+
[2, 1],
|
|
283
|
+
[4, 1],
|
|
284
|
+
];
|
|
285
|
+
function dots(now) {
|
|
286
|
+
const t = now % THINK.period;
|
|
287
|
+
const out = (t - THINK.dim) / THINK.fade;
|
|
288
|
+
if (out >= 1)
|
|
289
|
+
return [];
|
|
290
|
+
return DOTS.flatMap(([x, y], i) => {
|
|
291
|
+
const age = t - THINK.dot(i);
|
|
292
|
+
if (age < 0)
|
|
293
|
+
return [];
|
|
294
|
+
// 冒出来时白一下,很快沉成淡玉色
|
|
295
|
+
let c = mix(fade(0.85), rgb("#ffffff"), Math.exp(-age / 140));
|
|
296
|
+
if (out > 0)
|
|
297
|
+
c = mix(c, DEEP, out);
|
|
298
|
+
return [[x, y, c]];
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function side(mood, now, t) {
|
|
302
|
+
switch (mood) {
|
|
303
|
+
case "happy":
|
|
304
|
+
return check(t);
|
|
305
|
+
case "thinking":
|
|
306
|
+
return dots(now);
|
|
307
|
+
case "writing": {
|
|
308
|
+
// 打字的点:一个个亮起来,亮过之后慢慢暗下去
|
|
309
|
+
const t = (now % 1200) / 1200;
|
|
310
|
+
return [0, 1, 2].flatMap((x) => {
|
|
311
|
+
const age = t - x * 0.18;
|
|
312
|
+
return age >= 0 && age < 0.75 ? [[x, 5, fade(1 - Math.max(0, age - 0.25) * 2)]] : [];
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
case "tool": {
|
|
316
|
+
// 彗星一样转圈:亮的头,后面跟着越来越暗的尾巴
|
|
317
|
+
const ring = [
|
|
318
|
+
[1, 1],
|
|
319
|
+
[2, 2],
|
|
320
|
+
[2, 3],
|
|
321
|
+
[1, 4],
|
|
322
|
+
[0, 3],
|
|
323
|
+
[0, 2],
|
|
324
|
+
];
|
|
325
|
+
const head = Math.floor(now / 90) % ring.length;
|
|
326
|
+
return [0, 1, 2, 3].map((k) => {
|
|
327
|
+
const [x, y] = ring[(head - k + ring.length) % ring.length];
|
|
328
|
+
return [x, y, fade(1 - k / 3.2)];
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
case "asking": {
|
|
332
|
+
// 感叹号在两种黄之间呼吸
|
|
333
|
+
const c = mix(BANG[0], BANG[1], 0.5 + 0.5 * Math.sin(now / 160));
|
|
334
|
+
return [0, 1, 2, 4].map((y) => [1, y, c]);
|
|
335
|
+
}
|
|
336
|
+
case "stopping":
|
|
337
|
+
// 汗珠挂在头的右上角,贴着身体
|
|
338
|
+
return [
|
|
339
|
+
[-1, 0, SWEAT],
|
|
340
|
+
[-1, 1, mix(SWEAT, rgb("#ffffff"), 0.4)],
|
|
341
|
+
];
|
|
342
|
+
default:
|
|
343
|
+
return [];
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* 有状态的动画:每次 frame 把 Pose 往当前状态想要的样子缓动一点,所以换状态时眼睛是滑过去的。
|
|
348
|
+
* 眨眼这种很快的动作直接用目标值,不缓动
|
|
349
|
+
*/
|
|
350
|
+
export class Mascot {
|
|
351
|
+
pose = { ...REST };
|
|
352
|
+
#last;
|
|
353
|
+
#mood;
|
|
354
|
+
/** 进入当前状态的时刻:做完后那一套动作按它排时间 */
|
|
355
|
+
#since = 0;
|
|
356
|
+
frame(mood, now) {
|
|
357
|
+
if (mood !== this.#mood) {
|
|
358
|
+
this.#mood = mood;
|
|
359
|
+
this.#since = now;
|
|
360
|
+
}
|
|
361
|
+
const t = now - this.#since;
|
|
362
|
+
const want = goal(mood, now, t);
|
|
363
|
+
const dt = this.#last === undefined ? 1e9 : Math.max(0, now - this.#last);
|
|
364
|
+
this.#last = now;
|
|
365
|
+
const k = 1 - Math.exp(-dt / 110);
|
|
366
|
+
const p = this.pose;
|
|
367
|
+
for (const key of ["gx", "gy", "happy", "wink", "tint"])
|
|
368
|
+
p[key] += (want[key] - p[key]) * k;
|
|
369
|
+
p.open = want.open < p.open ? want.open : p.open + (want.open - p.open) * (1 - Math.exp(-dt / 50));
|
|
370
|
+
p.glow = want.glow;
|
|
371
|
+
return paint(p, mood, now, t);
|
|
372
|
+
}
|
|
373
|
+
/** 还在往目标缓动(空闲时也要接着重画几帧) */
|
|
374
|
+
moving(mood, now) {
|
|
375
|
+
const want = goal(mood, now, mood === this.#mood ? now - this.#since : 0);
|
|
376
|
+
const p = this.pose;
|
|
377
|
+
return ["gx", "gy", "happy", "wink", "tint", "open"].some((k) => Math.abs(want[k] - p[k]) > 0.02);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/** 把像素合成半格字符,每一行是若干段同色的字符 */
|
|
381
|
+
export function cells(grid) {
|
|
382
|
+
const out = [];
|
|
383
|
+
for (let y = 0; y < grid.length; y += 2) {
|
|
384
|
+
const top = grid[y];
|
|
385
|
+
const bottom = grid[y + 1] ?? [];
|
|
386
|
+
const line = [];
|
|
387
|
+
for (let x = 0; x < top.length; x++) {
|
|
388
|
+
const t = top[x];
|
|
389
|
+
const b = bottom[x];
|
|
390
|
+
const cell = !t && !b ? { text: " " }
|
|
391
|
+
: t === b ? { text: "█", fg: t }
|
|
392
|
+
: !t ? { text: "▄", fg: b }
|
|
393
|
+
: !b ? { text: "▀", fg: t }
|
|
394
|
+
: { text: "▀", fg: t, bg: b };
|
|
395
|
+
const last = line.at(-1);
|
|
396
|
+
if (last && last.fg === cell.fg && last.bg === cell.bg)
|
|
397
|
+
last.text += cell.text;
|
|
398
|
+
else
|
|
399
|
+
line.push(cell);
|
|
400
|
+
}
|
|
401
|
+
out.push(line);
|
|
402
|
+
}
|
|
403
|
+
return out;
|
|
404
|
+
}
|
|
405
|
+
/** 动画帧之间隔多久 */
|
|
406
|
+
export const FRAME_MS = 50;
|
|
407
|
+
/**
|
|
408
|
+
* 不在运行时,下一次需要重画还要多久(毫秒):缓动没结束、正在眨眼或瞟眼时按帧画,
|
|
409
|
+
* 否则等到下一次眨眼、瞟眼或笑完。运行中由 App 定时重画,用不到这个
|
|
410
|
+
*/
|
|
411
|
+
export function nextChange(mood, now, doneAt, moving = false) {
|
|
412
|
+
if (moving)
|
|
413
|
+
return FRAME_MS;
|
|
414
|
+
if (mood === "asking" || mood === "happy") {
|
|
415
|
+
const end = mood === "happy" && doneAt !== undefined ? doneAt + HAPPY_MS - now : Infinity;
|
|
416
|
+
return Math.max(16, Math.min(FRAME_MS, end));
|
|
417
|
+
}
|
|
418
|
+
const tb = now % BLINK_EVERY;
|
|
419
|
+
// 眨眼(含连眨的第二下)期间按帧画
|
|
420
|
+
if (tb < 2 * BLINK_MS + 90)
|
|
421
|
+
return FRAME_MS;
|
|
422
|
+
const tg = now % GLANCE_EVERY;
|
|
423
|
+
const toGlance = tg < GLANCE[0] ? GLANCE[0] - tg : tg < GLANCE[1] ? GLANCE[1] - tg : GLANCE_EVERY - tg + GLANCE[0];
|
|
424
|
+
return Math.max(16, Math.min(BLINK_EVERY - tb, toGlance));
|
|
425
|
+
}
|
|
426
|
+
// ---------- 终端标题 ----------
|
|
427
|
+
/** jade 的标志:一块玉 */
|
|
428
|
+
export const LOGO = "◆";
|
|
429
|
+
const SPIN = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
430
|
+
/**
|
|
431
|
+
* 终端标签页标题:空闲时是标志,运行中换成转圈,等用户时加感叹号,在别的标签页里也能看出 jade 在做什么。
|
|
432
|
+
* dir 是当前目录的名字
|
|
433
|
+
*/
|
|
434
|
+
export function title(mood, dir, now) {
|
|
435
|
+
const mark = mood === "asking" ? `${LOGO}!`
|
|
436
|
+
: mood === "idle" || mood === "happy" ? LOGO
|
|
437
|
+
: SPIN[Math.floor(now / 250) % SPIN.length];
|
|
438
|
+
return `${mark} jade · ${dir}`;
|
|
439
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "jade/tui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"api": "^1",
|
|
5
5
|
"entry": "./index.js",
|
|
6
6
|
"provides": [
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"modes@1",
|
|
17
17
|
"models@1",
|
|
18
18
|
"compact@1",
|
|
19
|
-
"sessions@1"
|
|
19
|
+
"sessions@1",
|
|
20
|
+
"steer@1"
|
|
20
21
|
],
|
|
21
22
|
"frontend": {
|
|
22
23
|
"name": "tui",
|
|
@@ -90,6 +90,8 @@ export function safeScreen(screen) {
|
|
|
90
90
|
set: (t) => screen.draft.set(plain(lf(t))),
|
|
91
91
|
hint: (t) => screen.draft.hint(t === undefined ? undefined : plain(lf(t))),
|
|
92
92
|
},
|
|
93
|
+
...(screen.copy ? { copy: (t) => screen.copy(t) } : {}),
|
|
94
|
+
...(screen.suspend ? { suspend: (fn) => screen.suspend(fn) } : {}),
|
|
93
95
|
clear: () => screen.clear(),
|
|
94
96
|
close: () => screen.close(),
|
|
95
97
|
};
|
|
@@ -120,6 +120,8 @@ export function transcript(opts) {
|
|
|
120
120
|
};
|
|
121
121
|
/** 有 result renderer 的调用的参数,结果出来时交给它 */
|
|
122
122
|
const inputs = new Map();
|
|
123
|
+
/** 等人工审批的调用的参数,回答(input.received)来了按它显示 */
|
|
124
|
+
const asks = new Map();
|
|
123
125
|
/** 出过错的 renderer(插件 + 工具),只提示一次 */
|
|
124
126
|
const failed = new Set();
|
|
125
127
|
/** 调用插件的 renderer;没有、出错时返回 undefined(用默认的显示) */
|
|
@@ -187,6 +189,7 @@ export function transcript(opts) {
|
|
|
187
189
|
calls.clear();
|
|
188
190
|
befores.clear();
|
|
189
191
|
inputs.clear();
|
|
192
|
+
asks.clear();
|
|
190
193
|
self.lastEnd = undefined;
|
|
191
194
|
},
|
|
192
195
|
};
|
|
@@ -287,8 +290,10 @@ export function transcript(opts) {
|
|
|
287
290
|
calls.set(d.toolUseId, full);
|
|
288
291
|
if (opts.renderer?.(name)?.renderer.result)
|
|
289
292
|
inputs.set(d.toolUseId, d.input);
|
|
290
|
-
if (d.decision === "ask")
|
|
293
|
+
if (d.decision === "ask") {
|
|
294
|
+
asks.set(d.toolUseId, d.input);
|
|
291
295
|
return;
|
|
296
|
+
}
|
|
292
297
|
// 执行前交给 renderer 的 before(例如按文件当时的内容算 diff);重新显示历史时文件已经变了,不调用
|
|
293
298
|
if (d.decision === "allow" && !replaying) {
|
|
294
299
|
const before = customSync(name, (r) => r.before?.(d.input));
|
|
@@ -318,6 +323,16 @@ export function transcript(opts) {
|
|
|
318
323
|
}
|
|
319
324
|
return;
|
|
320
325
|
}
|
|
326
|
+
case "input.received": {
|
|
327
|
+
// 对等待审批的调用的回答:和关卡直接决定的一样显示
|
|
328
|
+
const d = e.data;
|
|
329
|
+
if (d.kind !== "approval")
|
|
330
|
+
return;
|
|
331
|
+
const input = asks.get(d.toolUseId);
|
|
332
|
+
asks.delete(d.toolUseId);
|
|
333
|
+
const decided = { toolUseId: d.toolUseId, decision: d.approved ? "allow" : "deny", input, ...(d.approved ? {} : { reason: d.reason }) };
|
|
334
|
+
return renderEvent({ ...e, type: "tool.decided", data: decided });
|
|
335
|
+
}
|
|
321
336
|
case "tool.completed": {
|
|
322
337
|
const d = e.data;
|
|
323
338
|
void countUsage(e);
|