@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/vendor.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ink 和 react 只经这里导入。构建时 scripts/build-plugins.
|
|
1
|
+
// ink 和 react 只经这里导入。构建时 scripts/build-plugins.ts 把编译出的 vendor.js 连同依赖打成一个文件:
|
|
2
2
|
// 逐个解析 ink 和它拉进来的整个 es-toolkit/compat 要约 470ms,打包后约 120ms(docs/review.md #28)。
|
|
3
3
|
// 两者必须打在同一个文件里,否则 ink 和界面各用一份 react,hooks 会失效。
|
|
4
4
|
// 只用到类型的从 "ink"/"react" 直接 import type,不经这里。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// 文件快照:write_file / edit_file / multi_edit 执行前保存原内容,/undo 用它恢复。从旧 jade 的 tools/checkpoint.ts 移植。
|
|
2
2
|
//
|
|
3
|
-
// 快照放在 <dir>/<sessionId>/<toolUseId>.json
|
|
3
|
+
// 快照放在 <dir>/<sessionId>/<toolUseId>.json(子 Agent 写的放在根会话的目录里,via 是根会话里打开它的调用),不进日志:文件可能很大,而撤销是用户的操作,不影响插件决策。
|
|
4
4
|
// 哪些修改已经撤销记在同一个目录的 undone.json 里(命令拿不到会话日志),恢复会话后仍然有效。
|
|
5
5
|
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
@@ -19,6 +19,8 @@ export interface Checkpoint {
|
|
|
19
19
|
afterHash: string;
|
|
20
20
|
/** 写入完成的时间(毫秒,带小数),决定撤销顺序 */
|
|
21
21
|
at: number;
|
|
22
|
+
/** 子 Agent(子会话)写的:根会话里打开它的那次工具调用(例如 task)。/undo 按它找到是哪一轮 */
|
|
23
|
+
via?: string;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export const sha256 = (s: string) => createHash("sha256").update(s).digest("hex");
|
|
@@ -101,7 +103,7 @@ const UNDONE = "undone.json";
|
|
|
101
103
|
* 最近一轮还有没撤销的修改的快照(最新的在前)。一轮从一条用户自己写的消息开始;
|
|
102
104
|
* 只有工具结果、或者只有插件、宿主加的说明(例如自动续写的提示)的消息不算新的一轮。没有可撤销的返回空数组
|
|
103
105
|
*/
|
|
104
|
-
export function lastTurnChanges<T extends { toolUseId: string }>(messages: readonly Message[], checkpoints: readonly T[], undone: ReadonlySet<string>): T[] {
|
|
106
|
+
export function lastTurnChanges<T extends { toolUseId: string; via?: string }>(messages: readonly Message[], checkpoints: readonly T[], undone: ReadonlySet<string>): T[] {
|
|
105
107
|
const pending = checkpoints.filter((c) => !undone.has(c.toolUseId));
|
|
106
108
|
if (pending.length === 0) return [];
|
|
107
109
|
let ids = new Set<string>();
|
|
@@ -113,7 +115,7 @@ export function lastTurnChanges<T extends { toolUseId: string }>(messages: reado
|
|
|
113
115
|
}
|
|
114
116
|
const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user");
|
|
115
117
|
if (!startsTurn) continue;
|
|
116
|
-
const hits = pending.filter((c) => ids.has(c.toolUseId));
|
|
118
|
+
const hits = pending.filter((c) => ids.has(c.via ?? c.toolUseId));
|
|
117
119
|
if (hits.length > 0) return hits;
|
|
118
120
|
ids = new Set();
|
|
119
121
|
}
|
package/plugins/undo/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// jade/undo:/undo 把模型上一轮改过的文件恢复原样(再执行一次撤销更早的一轮)。
|
|
2
2
|
//
|
|
3
|
-
// jade/fs 不再保存检查点,这里自己观察:tool.before
|
|
3
|
+
// jade/fs 不再保存检查点,这里自己观察:tool.before 在写文件的工具(meta.writes,例如 write_file)执行前记下文件原来的内容,
|
|
4
4
|
// tool.after 在执行成功后记下新内容的哈希,存成快照(checkpoint.ts)。tool.before 在审批之前执行,
|
|
5
5
|
// 所以等用户批准期间别人对文件的改动会算进"原来的内容"。
|
|
6
|
-
// shell 命令改的文件:在 git
|
|
6
|
+
// shell 命令改的文件:在 git 仓库里,每轮第一次执行命令(meta.shell,例如 bash)之前给工作区拍一张快照(snapshot.ts),撤销时把之后变了的文件恢复回去。
|
|
7
|
+
// 认工具靠它注册时给的 meta,不认工具名:换掉提供文件工具的插件照样能撤销。
|
|
7
8
|
|
|
8
9
|
import { readFile } from "node:fs/promises";
|
|
9
10
|
import { realpathSync } from "node:fs";
|
|
@@ -12,10 +13,7 @@ import { definePlugin } from "@uncarved/jade-api";
|
|
|
12
13
|
import type { Commands, Prompts } from "@uncarved/jade-api/services";
|
|
13
14
|
import { Checkpoints, lastTurnChanges, safe, sha256, turnToolNames, type Checkpoint } from "./checkpoint.ts";
|
|
14
15
|
import { Snapshots, type Change, type Snapshot } from "./snapshot.ts";
|
|
15
|
-
import { dim,
|
|
16
|
-
|
|
17
|
-
/** 会改文件、参数里有 path 的工具 */
|
|
18
|
-
export const WRITE_TOOLS = new Set(["write_file", "edit_file", "multi_edit"]);
|
|
16
|
+
import { dim, ok } from "./style.ts";
|
|
19
17
|
|
|
20
18
|
/** 没有工作区快照(不在 git 仓库里、配置关掉了)时,shell 命令改了什么无从得知,撤销不了;这一轮跑过时提醒一句 */
|
|
21
19
|
const SHELL_NOTE = "This turn also ran shell commands; what they changed is not undone.";
|
|
@@ -45,6 +43,11 @@ function realPath(p: string): string {
|
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
46
|
+
/** 打开着的会话:会话 id → 它的 tool.decided 事件 id → toolUseId(子会话的 parent 只给事件 id) */
|
|
47
|
+
const decidedBy = new Map<string, Map<string, string>>();
|
|
48
|
+
/** 打开着的会话:会话 id → 它的改动记在哪个根会话、算作根会话里哪次调用的 */
|
|
49
|
+
const links = new Map<string, () => { root: string; via?: string }>();
|
|
50
|
+
|
|
48
51
|
/** 文件现在的内容;不存在时 null */
|
|
49
52
|
async function contentOf(file: string): Promise<string | null> {
|
|
50
53
|
try {
|
|
@@ -84,9 +87,10 @@ export default definePlugin({
|
|
|
84
87
|
await checkpoints.markUndone(s.id, [snap.toolUseId]);
|
|
85
88
|
}
|
|
86
89
|
// 这个会话里拍到过快照,说明命令的改动撤销得了,不用提醒
|
|
87
|
-
|
|
90
|
+
const ranShell = (names: Set<string>) => [...names].some((n) => s.tool(n)?.meta?.shell !== undefined);
|
|
91
|
+
if (cps.length === 0 && !snap) return dim(snaps.length === 0 && ranShell(turnToolNames(s.state.messages)) ? `Nothing to undo. ${SHELL_NOTE}` : "Nothing to undo.");
|
|
88
92
|
// 没拍到快照(不在 git 仓库里、配置关掉了)的那一轮跑过命令时提醒一句
|
|
89
|
-
const shellToo = !snap && turnToolNames(s.state.messages, cps[0]!.toolUseId)
|
|
93
|
+
const shellToo = !snap && ranShell(turnToolNames(s.state.messages, cps[0]!.toolUseId));
|
|
90
94
|
// 工作区快照覆盖到的文件按快照恢复(那是命令动它之前的内容):拍快照之后文件工具对它的修改不再单独恢复
|
|
91
95
|
const inTree = new Set(tree.map((c) => same(c.path)));
|
|
92
96
|
const fileCps = cps.filter((cp) => !(snap && cp.at > snap.at && inTree.has(same(cp.path))));
|
|
@@ -135,7 +139,7 @@ export default definePlugin({
|
|
|
135
139
|
if (plan.size > MAX_LISTED) what.push(`and ${plan.size - MAX_LISTED} more files`);
|
|
136
140
|
ctx.service<Prompts>("prompts@1")?.note(s.id, `The user undid your changes from your last turn: ${what.join("; ")}. Read these files again before changing them.`);
|
|
137
141
|
const title = snap ? `Undid the last turn (${plan.size} file${plan.size > 1 ? "s" : ""}):` : `Undid ${cps.length} change${cps.length > 1 ? "s" : ""} from the last turn:`;
|
|
138
|
-
return
|
|
142
|
+
return [ok(title), "\n", dim(list), ...(shellToo ? ["\n", dim(SHELL_NOTE)] : [])];
|
|
139
143
|
},
|
|
140
144
|
});
|
|
141
145
|
},
|
|
@@ -143,6 +147,25 @@ export default definePlugin({
|
|
|
143
147
|
session(ctx) {
|
|
144
148
|
const checkpoints = new Checkpoints(path.join(ctx.home, "checkpoints"));
|
|
145
149
|
const sessionId = ctx.session.id;
|
|
150
|
+
const decided = new Map<string, string>();
|
|
151
|
+
decidedBy.set(sessionId, decided);
|
|
152
|
+
/**
|
|
153
|
+
* 子会话(子 Agent)的改动记在根会话里,算作根会话里打开它的那次调用的:父会话 /undo 时和那一轮的改动一起撤销。
|
|
154
|
+
* 父会话的 tool.decided 在工具执行之前就记下了,所以子会话开好时查得到
|
|
155
|
+
*/
|
|
156
|
+
const link = (): { root: string; via?: string } => {
|
|
157
|
+
const p = ctx.session.parent;
|
|
158
|
+
if (!p) return { root: sessionId };
|
|
159
|
+
const up = links.get(p.sessionId)?.();
|
|
160
|
+
if (up?.via) return up;
|
|
161
|
+
const via = decidedBy.get(p.sessionId)?.get(p.eventId);
|
|
162
|
+
return { root: up?.root ?? p.sessionId, ...(via ? { via } : {}) };
|
|
163
|
+
};
|
|
164
|
+
links.set(sessionId, link);
|
|
165
|
+
void ctx.effect(() => () => {
|
|
166
|
+
if (decidedBy.get(sessionId) === decided) decidedBy.delete(sessionId);
|
|
167
|
+
if (links.get(sessionId) === link) links.delete(sessionId);
|
|
168
|
+
});
|
|
146
169
|
/** toolUseId → 执行前的内容,执行成功后存成快照 */
|
|
147
170
|
const before = new Map<string, { tool: string; path: string; before: string | null }>();
|
|
148
171
|
const snapshots = new Snapshots(path.join(ctx.home, "checkpoints", safe(sessionId)), ctx.cwd);
|
|
@@ -158,15 +181,17 @@ export default definePlugin({
|
|
|
158
181
|
// 第一次给大仓库拍快照要把每个文件算一遍哈希
|
|
159
182
|
timeoutMs: SNAPSHOT_TIMEOUT_MS,
|
|
160
183
|
fn: async (call) => {
|
|
161
|
-
|
|
162
|
-
|
|
184
|
+
const meta = ctx.session.tool(call.name)?.meta;
|
|
185
|
+
// 每轮第一次跑命令之前给工作区拍一张快照:命令改了什么,/undo 时和它一比就知道。
|
|
186
|
+
// 子会话不拍:并行的几个子 Agent 不能同时用根会话的影子仓库(子 Agent 的命令改的文件撤销不了)
|
|
187
|
+
if (meta?.shell !== undefined && ctx.config.shell !== false && !snapped && !ctx.session.parent) {
|
|
163
188
|
snapped = true;
|
|
164
189
|
const tree = await snapshots.take();
|
|
165
190
|
if (tree) await snapshots.save({ toolUseId: call.toolUseId, tree, at: performance.timeOrigin + performance.now() });
|
|
166
191
|
return;
|
|
167
192
|
}
|
|
168
|
-
if (
|
|
169
|
-
const p = (call.input as
|
|
193
|
+
if (meta?.writes === undefined) return;
|
|
194
|
+
const p = (call.input as Record<string, unknown> | null)?.[meta.writes];
|
|
170
195
|
if (typeof p !== "string") return;
|
|
171
196
|
const full = path.resolve(ctx.cwd, p);
|
|
172
197
|
before.set(call.toolUseId, { tool: call.name, path: full, before: await contentOf(full) });
|
|
@@ -184,7 +209,8 @@ export default definePlugin({
|
|
|
184
209
|
const after = await contentOf(snap.path);
|
|
185
210
|
// 内容没变(例如同样的内容重复写入)不算修改
|
|
186
211
|
if (after === snap.before) return;
|
|
187
|
-
|
|
212
|
+
const { root, via } = link();
|
|
213
|
+
await checkpoints.save(root, { toolUseId: out.call.toolUseId, ...snap, afterHash: sha256(after ?? ""), ...(via ? { via } : {}) });
|
|
188
214
|
},
|
|
189
215
|
});
|
|
190
216
|
// 被拒绝、被中断的调用不经过 tool.after:一轮结束时还留着的都不会再用到,不然整个文件的内容一直占着内存
|
|
@@ -192,8 +218,11 @@ export default definePlugin({
|
|
|
192
218
|
kind: "observe",
|
|
193
219
|
point: "event",
|
|
194
220
|
fn: (e) => {
|
|
221
|
+
if (e.type === "tool.decided") decided.set(e.id, (e.data as { toolUseId: string }).toolUseId);
|
|
195
222
|
if (e.type !== "turn.ended") return;
|
|
196
223
|
before.clear();
|
|
224
|
+
// 只有这一轮里开的子会话查它(子会话在打开它的那次调用里结束)
|
|
225
|
+
decided.clear();
|
|
197
226
|
snapped = false;
|
|
198
227
|
},
|
|
199
228
|
});
|
package/plugins/undo/style.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
//
|
|
1
|
+
// 显示用的小工具:截断,和带语义样式的文字(jade-api 的 Text)。插件只说这段是次要的、成功、警告……,
|
|
2
|
+
// 怎么画由前端决定(终端界面画成颜色,-p 只取文字)。插件之间不共享代码(只能共享类型),所以每个插件有一份。
|
|
3
|
+
|
|
4
|
+
import type { Span, Text, TextStyle } from "@uncarved/jade-api";
|
|
2
5
|
|
|
3
6
|
export const clip = (s: string, n: number) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
export const red = paint("31", "39");
|
|
15
|
-
export const green = paint("32", "39");
|
|
16
|
-
export const yellow = paint("33", "39");
|
|
17
|
-
export const bold = paint("1", "22");
|
|
8
|
+
const styled = (style: TextStyle) => (text: string): Span => ({ text, style });
|
|
9
|
+
export const dim = styled("dim");
|
|
10
|
+
export const bold = styled("bold");
|
|
11
|
+
export const ok = styled("ok");
|
|
12
|
+
export const warn = styled("warn");
|
|
13
|
+
export const error = styled("error");
|
|
14
|
+
|
|
15
|
+
/** 几行接成一段,行之间换行 */
|
|
16
|
+
export const lines = (rows: readonly Text[]): Text => rows.flatMap((r, i) => (i ? ["\n", r] : [r]));
|
package/plugins/web/index.ts
CHANGED
|
@@ -5,16 +5,15 @@
|
|
|
5
5
|
// 不用重开会话;会话的工具清单在创建时就定了。
|
|
6
6
|
|
|
7
7
|
import path from "node:path";
|
|
8
|
-
import { definePlugin, type ScopeContext, type UI } from "@uncarved/jade-api";
|
|
9
|
-
import type { Commands, Prompts, Renderers
|
|
8
|
+
import { definePlugin, type ScopeContext, type Span, type UI } from "@uncarved/jade-api";
|
|
9
|
+
import type { Commands, Prompts, Renderers } from "@uncarved/jade-api/services";
|
|
10
10
|
import { envWithFile, updateEnvFile, type Env } from "./env.ts";
|
|
11
11
|
import { webRenderers } from "./renderers.ts";
|
|
12
12
|
import { parseOrder, parseResults, SEARCH_PROVIDERS, webTools } from "./web.ts";
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const green = (s: string) => (colors ? `\x1b[32m${s}\x1b[39m` : s);
|
|
14
|
+
// 带语义样式的文字(jade-api 的 Text):怎么画由前端决定
|
|
15
|
+
const dim = (text: string): Span => ({ text, style: "dim" });
|
|
16
|
+
const ok = (text: string): Span => ({ text, style: "ok" });
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* API key 所在的环境:每次开会话时重新读,/search 改了之后原地更新。模块每个进程只加载一次,进程级的命令和会话级的工具共用
|
|
@@ -79,7 +78,7 @@ export default definePlugin({
|
|
|
79
78
|
await updateEnvFile(file, { [p.env]: key }, env);
|
|
80
79
|
offNote?.();
|
|
81
80
|
offNote = undefined;
|
|
82
|
-
return
|
|
81
|
+
return ok(`Web search is on with ${p.name}: web_search uses it, and web_fetch falls back to it when a page cannot be fetched directly.`);
|
|
83
82
|
},
|
|
84
83
|
});
|
|
85
84
|
},
|
|
@@ -98,17 +97,7 @@ export default definePlugin({
|
|
|
98
97
|
const web = webTools({ ...opts, env: () => keys ?? env });
|
|
99
98
|
for (const tool of web.tools) ctx.kernel.tool(tool);
|
|
100
99
|
|
|
101
|
-
// 子 Agent
|
|
102
|
-
// web_fetch 带 url 参数,子 Agent 每次都要问用户(URL 能把读到的内容带出去)。
|
|
103
|
-
// jade/task 被隔离时它的服务已失效:子 Agent 没有 web 工具,web 工具本身照常
|
|
104
|
-
try {
|
|
105
|
-
const task = ctx.service<Task>("task@1");
|
|
106
|
-
if (task) {
|
|
107
|
-
const sub = webTools({ ...opts, env: () => keys ?? env });
|
|
108
|
-
for (const tool of sub.tools) task.tool(tool, tool.name === "web_search" ? { when: () => sub.search().length > 0 } : {});
|
|
109
|
-
}
|
|
110
|
-
} catch {}
|
|
111
|
-
|
|
100
|
+
// 子 Agent 是核心开的子会话,本插件在里面另有一份,web_fetch 经过和主会话同一套审批
|
|
112
101
|
ctx.kernel.hook({
|
|
113
102
|
kind: "transform",
|
|
114
103
|
point: "context.build",
|
package/plugins/web/plugin.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"version": "0.3.0",
|
|
4
4
|
"api": "^1",
|
|
5
5
|
"entry": "./index.ts",
|
|
6
|
-
"optional": ["ui@1", "commands@1", "prompts@1", "renderers@1"
|
|
6
|
+
"optional": ["ui@1", "commands@1", "prompts@1", "renderers@1"],
|
|
7
7
|
"config": {
|
|
8
8
|
"search": {
|
|
9
9
|
"description": "search services to use, in order: a list or comma-separated names (tinyfish, anysearch, tavily, exa, firecrawl, jina); default: every service with an API key. Keys are read from the environment and $JADE_HOME/.env (/search sets them). $JADE_SEARCH still works"
|