@uncarved/jade 0.3.0 → 0.4.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 +1 -0
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +39 -5
- package/dist/host.js.map +1 -1
- package/dist/remote.js +5 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +7 -0
- package/dist/session.js +482 -27
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +49 -24
- package/plugins/approval/policy.ts +48 -25
- package/plugins/approval/review.ts +9 -5
- package/plugins/checks/checks.ts +10 -7
- package/plugins/checks/index.ts +13 -13
- package/plugins/checks/plugin.json +1 -1
- package/plugins/checks/project.ts +37 -38
- package/plugins/commands/index.ts +27 -3
- package/plugins/compact/compact.ts +13 -5
- package/plugins/compact/index.ts +20 -3
- package/plugins/compact/style.ts +13 -14
- package/plugins/completions/index.ts +35 -0
- package/plugins/completions/plugin.json +7 -0
- package/plugins/copy/index.ts +46 -0
- package/plugins/copy/plugin.json +7 -0
- package/plugins/editor/index.ts +10 -4
- package/plugins/fs/diff.ts +7 -6
- package/plugins/fs/fs.ts +8 -4
- package/plugins/fs/grep.ts +55 -12
- package/plugins/fs/index.ts +2 -7
- package/plugins/fs/plugin.json +1 -1
- package/plugins/fs/renderers.ts +16 -15
- package/plugins/fs/style.ts +16 -15
- package/plugins/hooks/index.ts +3 -2
- package/plugins/keys/index.ts +5 -1
- package/plugins/mcp/index.ts +197 -78
- package/plugins/mcp/install.ts +5 -3
- package/plugins/mcp/mcp.ts +163 -11
- package/plugins/mcp/plugin.json +2 -1
- package/plugins/mcp/project.ts +47 -50
- package/plugins/memory/index.ts +4 -4
- package/plugins/memory/style.ts +13 -14
- package/plugins/mentions/candidates.ts +67 -0
- package/plugins/mentions/index.ts +12 -5
- package/plugins/mentions/plugin.json +1 -1
- package/plugins/mentions/style.ts +13 -14
- package/plugins/models/configure.ts +10 -9
- package/plugins/models/index.ts +31 -4
- package/plugins/models/provider.ts +12 -1
- package/plugins/modes/index.ts +13 -2
- package/plugins/print/index.ts +7 -4
- package/plugins/prompts/index.ts +0 -0
- package/plugins/renderers/index.ts +10 -5
- package/plugins/repeats/index.ts +39 -9
- package/plugins/schedule/index.ts +2 -0
- package/plugins/screenshot/browser.ts +231 -0
- package/plugins/screenshot/index.ts +3 -2
- package/plugins/screenshot/tool.ts +27 -51
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +75 -22
- package/plugins/shell/plugin.json +1 -2
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +93 -34
- package/plugins/skills/index.ts +28 -19
- package/plugins/skills/project.ts +12 -7
- package/plugins/steer/index.ts +5 -4
- package/plugins/task/index.ts +81 -81
- package/plugins/task/plugin.json +5 -2
- package/plugins/task/style.ts +13 -14
- package/plugins/task/subagent.ts +67 -184
- package/plugins/todo/index.ts +39 -9
- package/plugins/tools/index.ts +57 -0
- package/plugins/tools/plugin.json +7 -0
- package/plugins/tui/frontend.ts +161 -87
- package/plugins/tui/index.ts +2 -3
- package/plugins/tui/mascot.ts +8 -7
- package/plugins/tui/mentions.ts +11 -80
- package/plugins/tui/plugin.json +1 -1
- package/plugins/tui/screen.ts +55 -5
- package/plugins/tui/transcript.ts +17 -7
- package/plugins/tui/tui.ts +356 -104
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +5 -3
- package/plugins/undo/index.ts +43 -14
- package/plugins/undo/style.ts +13 -14
- package/plugins/web/index.ts +7 -18
- package/plugins/web/plugin.json +1 -1
- package/plugins-dist/approval/index.js +363 -414
- package/plugins-dist/approval/policy.js +395 -497
- package/plugins-dist/approval/review.js +132 -158
- package/plugins-dist/approval/schema.js +50 -55
- package/plugins-dist/ask/index.js +115 -129
- package/plugins-dist/budget/index.js +27 -31
- package/plugins-dist/checks/checks.js +293 -329
- package/plugins-dist/checks/index.js +119 -139
- package/plugins-dist/checks/plugin.json +2 -1
- package/plugins-dist/checks/project.js +57 -65
- package/plugins-dist/commands/index.js +47 -29
- package/plugins-dist/compact/compact.js +233 -249
- package/plugins-dist/compact/index.js +98 -95
- package/plugins-dist/compact/style.js +9 -14
- package/plugins-dist/completions/index.js +30 -0
- package/plugins-dist/completions/plugin.json +9 -0
- package/plugins-dist/continue/index.js +40 -52
- package/plugins-dist/copy/index.js +40 -0
- package/plugins-dist/copy/plugin.json +9 -0
- package/plugins-dist/cost/index.js +98 -115
- package/plugins-dist/custom-commands/index.js +55 -72
- package/plugins-dist/editor/index.js +64 -72
- package/plugins-dist/fs/diff.js +111 -124
- package/plugins-dist/fs/fs.js +426 -469
- package/plugins-dist/fs/grep.js +262 -244
- package/plugins-dist/fs/index.js +20 -34
- package/plugins-dist/fs/plugin.json +1 -2
- package/plugins-dist/fs/renderers.js +100 -112
- package/plugins-dist/fs/style.js +11 -15
- package/plugins-dist/fs/sys.js +31 -43
- package/plugins-dist/hooks/index.js +107 -127
- package/plugins-dist/keys/index.js +27 -31
- package/plugins-dist/mcp/index.js +271 -199
- package/plugins-dist/mcp/install.js +123 -137
- package/plugins-dist/mcp/mcp.js +638 -577
- package/plugins-dist/mcp/plugin.json +3 -1
- package/plugins-dist/mcp/project.js +98 -115
- package/plugins-dist/memory/index.js +83 -88
- package/plugins-dist/memory/memory.js +111 -128
- package/plugins-dist/memory/style.js +9 -14
- package/plugins-dist/mentions/attach.js +91 -99
- package/plugins-dist/mentions/candidates.js +49 -0
- package/plugins-dist/mentions/index.js +71 -81
- package/plugins-dist/mentions/plugin.json +2 -1
- package/plugins-dist/mentions/style.js +9 -14
- package/plugins-dist/models/config.js +29 -43
- package/plugins-dist/models/configure.js +392 -473
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -188
- package/plugins-dist/models/provider.js +243 -295
- package/plugins-dist/models/saved.js +59 -71
- package/plugins-dist/modes/index.js +138 -165
- package/plugins-dist/plugins/index.js +34 -34
- package/plugins-dist/print/index.js +192 -175
- package/plugins-dist/prompts/index.js +81 -89
- package/plugins-dist/prompts/notes.js +31 -37
- package/plugins-dist/prompts/prompts.js +155 -193
- package/plugins-dist/prompts/results.js +40 -53
- package/plugins-dist/prompts/sys.js +39 -50
- package/plugins-dist/renderers/index.js +32 -32
- package/plugins-dist/repeats/index.js +134 -151
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +229 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +169 -0
- package/plugins-dist/screenshot/index.js +37 -45
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +101 -151
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +117 -74
- package/plugins-dist/shell/plugin.json +1 -2
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +317 -320
- package/plugins-dist/shell/sys.js +64 -79
- package/plugins-dist/skills/index.js +193 -211
- package/plugins-dist/skills/install.js +122 -149
- package/plugins-dist/skills/project.js +65 -73
- package/plugins-dist/skills/skills.js +135 -171
- package/plugins-dist/steer/index.js +108 -125
- package/plugins-dist/suggest/index.js +235 -259
- package/plugins-dist/task/index.js +130 -148
- package/plugins-dist/task/plugin.json +5 -4
- package/plugins-dist/task/style.js +9 -14
- package/plugins-dist/task/subagent.js +156 -279
- package/plugins-dist/todo/index.js +79 -63
- package/plugins-dist/tools/index.js +43 -0
- package/plugins-dist/tools/plugin.json +9 -0
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +641 -655
- package/plugins-dist/tui/history.js +34 -37
- package/plugins-dist/tui/index.js +16 -18
- package/plugins-dist/tui/markdown.js +203 -247
- package/plugins-dist/tui/mascot.js +266 -353
- package/plugins-dist/tui/mentions.js +67 -144
- package/plugins-dist/tui/plugin.json +1 -2
- package/plugins-dist/tui/render.js +35 -45
- package/plugins-dist/tui/screen.js +197 -180
- package/plugins-dist/tui/transcript.js +436 -468
- package/plugins-dist/tui/tui.js +1554 -1645
- package/plugins-dist/tui/vendor.js +1388 -1088
- package/plugins-dist/undo/checkpoint.js +95 -118
- package/plugins-dist/undo/index.js +185 -192
- package/plugins-dist/undo/snapshot.js +83 -99
- package/plugins-dist/undo/style.js +9 -14
- package/plugins-dist/update/index.js +26 -28
- package/plugins-dist/web/env.js +55 -68
- package/plugins-dist/web/index.js +80 -110
- package/plugins-dist/web/plugin.json +1 -2
- package/plugins-dist/web/renderers.js +4 -5
- package/plugins-dist/web/web.js +514 -593
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +9 -2
- package/src/api.ts +1 -1
- package/src/host.ts +39 -4
- package/src/remote.ts +6 -1
- package/src/session.ts +489 -34
package/plugins/tui/screen.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { createInterface, type Interface } from "node:readline/promises";
|
|
6
6
|
import { stripVTControlCharacters } from "node:util";
|
|
7
|
+
import type { Span, StatusSegment, Text, TextStyle } from "@uncarved/jade-api";
|
|
7
8
|
|
|
8
9
|
export interface Choice<T> {
|
|
9
10
|
label: string;
|
|
@@ -14,14 +15,15 @@ export interface Choice<T> {
|
|
|
14
15
|
|
|
15
16
|
export interface StatusInfo {
|
|
16
17
|
/** 插件用 ctx.status 设置的段落(已经是一行、截断过) */
|
|
17
|
-
plugins?: { plugin: string; text: string }[];
|
|
18
|
+
plugins?: { plugin: string; text: string | StatusSegment }[];
|
|
19
|
+
/** 插件用 ctx.panel 设置的、显示在输入框上方的块(可以多行,已经限制过行数) */
|
|
20
|
+
panels?: { plugin: string; text: string }[];
|
|
18
21
|
cwd: string;
|
|
19
22
|
branch?: string;
|
|
20
23
|
model: string;
|
|
21
|
-
mode: string;
|
|
22
24
|
session?: string;
|
|
23
25
|
/** 上一次请求的上下文用量,limit 是模型的上下文窗口 */
|
|
24
|
-
context?: { used: number; limit: number
|
|
26
|
+
context?: { used: number; limit: number };
|
|
25
27
|
/** 本会话累计的用量(含子 Agent 和压缩) */
|
|
26
28
|
spent?: { input: number; output: number };
|
|
27
29
|
/** 上一次请求的输入中命中缓存的比例(0–1);服务不报告缓存用量时为 undefined */
|
|
@@ -34,6 +36,17 @@ export interface CommandInfo {
|
|
|
34
36
|
name: string;
|
|
35
37
|
args?: string;
|
|
36
38
|
about: string;
|
|
39
|
+
/** 输入的简写(Command.prefix),例如 "!" */
|
|
40
|
+
prefix?: string;
|
|
41
|
+
/** 打了简写时输入框上写的说明 */
|
|
42
|
+
prefixHint?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 输入框的一种补全(completions@1) */
|
|
46
|
+
export interface CompletionInfo {
|
|
47
|
+
trigger: string;
|
|
48
|
+
label: string;
|
|
49
|
+
hint?: string;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
52
|
export interface Screen {
|
|
@@ -99,6 +112,38 @@ export const bold = paint("1", "22");
|
|
|
99
112
|
export const italic = paint("3", "23");
|
|
100
113
|
export const underline = paint("4", "24");
|
|
101
114
|
export const strike = paint("9", "29");
|
|
115
|
+
const magenta = paint("35", "39");
|
|
116
|
+
|
|
117
|
+
/** 插件给的带语义样式的文字(jade-api 的 Text)怎么画 */
|
|
118
|
+
const STYLES: Record<TextStyle, (s: string) => string> = {
|
|
119
|
+
dim,
|
|
120
|
+
bold,
|
|
121
|
+
ok: green,
|
|
122
|
+
warn: yellow,
|
|
123
|
+
error: red,
|
|
124
|
+
accent: magenta,
|
|
125
|
+
code: cyan,
|
|
126
|
+
added: green,
|
|
127
|
+
removed: red,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** 插件给的文字画成终端里的样子:片段按样式上色(字符串里原有的 ANSI 照留),嵌套的数组按顺序接起来 */
|
|
131
|
+
export function ansi(t: Text | undefined): string {
|
|
132
|
+
if (t === undefined || t === null) return "";
|
|
133
|
+
if (typeof t === "string") return t;
|
|
134
|
+
if (Array.isArray(t)) return (t as readonly Text[]).map(ansi).join("");
|
|
135
|
+
const span = t as Span;
|
|
136
|
+
const styles = (Array.isArray(span.style) ? span.style : [span.style]) as TextStyle[];
|
|
137
|
+
return styles.reduce((s, style) => STYLES[style]?.(s) ?? s, String(span.text ?? ""));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** 只取文字:样式和字符串里的控制序列都去掉(不画颜色的地方用,例如 -p、测试) */
|
|
141
|
+
export function plain(t: Text | undefined): string {
|
|
142
|
+
if (t === undefined || t === null) return "";
|
|
143
|
+
if (typeof t === "string") return stripVTControlCharacters(t);
|
|
144
|
+
if (Array.isArray(t)) return (t as readonly Text[]).map(plain).join("");
|
|
145
|
+
return stripVTControlCharacters(String((t as Span).text ?? ""));
|
|
146
|
+
}
|
|
102
147
|
|
|
103
148
|
// ---------- 过滤控制字符 ----------
|
|
104
149
|
|
|
@@ -153,8 +198,13 @@ export function safeScreen(screen: Screen): Screen {
|
|
|
153
198
|
busy: (label) => screen.busy(opt(label)),
|
|
154
199
|
status: (info) => {
|
|
155
200
|
const out: Partial<StatusInfo> = { ...info };
|
|
156
|
-
for (const k of ["cwd", "branch", "model", "
|
|
157
|
-
if (info.plugins)
|
|
201
|
+
for (const k of ["cwd", "branch", "model", "session"] as const) if (typeof info[k] === "string") out[k] = s(info[k]);
|
|
202
|
+
if (info.plugins)
|
|
203
|
+
out.plugins = info.plugins.map((p) => ({
|
|
204
|
+
plugin: p.plugin,
|
|
205
|
+
text: typeof p.text === "string" ? s(p.text) : { ...p.text, text: s(p.text.text), ...(p.text.short !== undefined ? { short: s(p.text.short) } : {}) },
|
|
206
|
+
}));
|
|
207
|
+
if (info.panels) out.panels = info.panels.map((p) => ({ plugin: p.plugin, text: s(p.text) }));
|
|
158
208
|
screen.status(out);
|
|
159
209
|
},
|
|
160
210
|
queued: (items) => screen.queued(items.map(s)),
|
|
@@ -17,8 +17,6 @@ export interface TranscriptOptions {
|
|
|
17
17
|
readLog?(sessionId: string): Promise<LogEvent[]>;
|
|
18
18
|
/** 模型的上下文窗口(状态栏显示用) */
|
|
19
19
|
contextWindow(): number;
|
|
20
|
-
/** 自动压缩的阈值(状态栏显示用) */
|
|
21
|
-
compactAt?(): number;
|
|
22
20
|
/** 每次回复的输出上限(回复被截断时的提示用);没有时说是服务的默认值 */
|
|
23
21
|
maxTokens?(): number | undefined;
|
|
24
22
|
/** 上一轮失败后能否用 /retry 重新请求 */
|
|
@@ -55,6 +53,9 @@ export interface Transcript {
|
|
|
55
53
|
|
|
56
54
|
/** 工具结果折叠起来的完整内容最多这么多行 */
|
|
57
55
|
const MAX_DETAIL_LINES = 2000;
|
|
56
|
+
/** 用户的输入超过这么多行时只显示开头 ECHO_HEAD_LINES 行,其余折叠 */
|
|
57
|
+
const MAX_ECHO_LINES = 12;
|
|
58
|
+
const ECHO_HEAD_LINES = 6;
|
|
58
59
|
|
|
59
60
|
/** 插件事件里的用量:只取数字字段 */
|
|
60
61
|
function usageOf(u: unknown): Usage | undefined {
|
|
@@ -103,7 +104,7 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
103
104
|
const by = e.origin.by === "model" ? `${e.origin.provider}/${e.origin.model}` : "";
|
|
104
105
|
if (u.cacheReadTokens !== undefined) reportsCache = by;
|
|
105
106
|
screen.status({
|
|
106
|
-
context: { used: u.inputTokens + (u.outputTokens ?? 0), limit: opts.contextWindow()
|
|
107
|
+
context: { used: u.inputTokens + (u.outputTokens ?? 0), limit: opts.contextWindow() },
|
|
107
108
|
cache: reportsCache === by && u.inputTokens > 0 ? (u.cacheReadTokens ?? 0) / u.inputTokens : undefined,
|
|
108
109
|
});
|
|
109
110
|
}
|
|
@@ -215,7 +216,15 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
215
216
|
const p = await custom(c.name, (r) => r.preview?.(c.input));
|
|
216
217
|
return typeof p === "string" ? p : preview(c.input);
|
|
217
218
|
},
|
|
218
|
-
echo: (text) =>
|
|
219
|
+
echo: (text) => {
|
|
220
|
+
const shown = (t: string) => (t.startsWith("/") ? cyan(`› ${t}`) : `\n${bold(`› ${t.replace(/\n/g, "\n ")}`)}`);
|
|
221
|
+
// 很长的输入(粘贴的日志)只显示开头几行,其余折叠起来,点击或 ctrl+o 展开
|
|
222
|
+
const lines = text.split("\n");
|
|
223
|
+
if (lines.length <= MAX_ECHO_LINES) return screen.log(shown(text));
|
|
224
|
+
// 展开时接着显示其余的行
|
|
225
|
+
const rest = lines.slice(ECHO_HEAD_LINES);
|
|
226
|
+
screen.log(`${shown(lines.slice(0, ECHO_HEAD_LINES).join("\n"))}\n ${dim(`… +${rest.length} lines`)}`, { details: rest.map((l) => ` ${l}`).join("\n") });
|
|
227
|
+
},
|
|
219
228
|
reset() {
|
|
220
229
|
for (const k of Object.keys(usage) as (keyof Usage)[]) usage[k] = 0;
|
|
221
230
|
reportsCache = undefined;
|
|
@@ -405,13 +414,14 @@ export function transcript(opts: TranscriptOptions): Transcript {
|
|
|
405
414
|
for (const id of [...running]) doneProgress(id);
|
|
406
415
|
self.lastError = d.error;
|
|
407
416
|
self.turnFailed = d.reason === "error" || d.reason === "aborted";
|
|
408
|
-
|
|
417
|
+
// 停下它的插件自己说明原因(例如 jade/budget 的 notice)
|
|
418
|
+
if (d.reason === "stopped") screen.log(yellow("[stopped before the turn finished; send a message to continue]"));
|
|
409
419
|
else if (d.reason === "aborted") screen.log(yellow("[interrupted]"));
|
|
410
420
|
else if (d.reason === "max_tokens") {
|
|
411
|
-
// 不读 process.env:写在 $JADE_HOME/.env 里的只有 models
|
|
421
|
+
// 不读 process.env:写在 $JADE_HOME/.env 里的只有 models 插件知道;怎么调高也由它说
|
|
412
422
|
const max = opts.maxTokens?.();
|
|
413
423
|
const limit = max ? `${max} tokens` : "the provider's default";
|
|
414
|
-
screen.log(yellow(`[reply cut off at the output limit (${limit})
|
|
424
|
+
screen.log(yellow(`[reply cut off at the output limit (${limit})]`));
|
|
415
425
|
} else if (d.reason !== "end") screen.log(yellow(`[turn ended: ${d.reason}${d.error ? ` — ${d.error}` : ""}]`));
|
|
416
426
|
if (self.turnFailed && !replaying && opts.canRetry()) screen.log(dim("[send /retry to request again without adding a message]"));
|
|
417
427
|
return;
|