@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
|
@@ -1,137 +1,114 @@
|
|
|
1
|
-
// 文件快照:write_file / edit_file / multi_edit 执行前保存原内容,/undo 用它恢复。从旧 jade 的 tools/checkpoint.ts 移植。
|
|
2
|
-
//
|
|
3
|
-
// 快照放在 <dir>/<sessionId>/<toolUseId>.json,不进日志:文件可能很大,而撤销是用户的操作,不影响插件决策。
|
|
4
|
-
// 哪些修改已经撤销记在同一个目录的 undone.json 里(命令拿不到会话日志),恢复会话后仍然有效。
|
|
5
1
|
import { createHash } from "node:crypto";
|
|
6
2
|
import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
7
3
|
import path from "node:path";
|
|
8
4
|
export const sha256 = (s) => createHash("sha256").update(s).digest("hex");
|
|
5
|
+
|
|
9
6
|
export class Checkpoints {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
#dir;
|
|
8
|
+
constructor(dir) {
|
|
9
|
+
this.#dir = dir;
|
|
10
|
+
}
|
|
11
|
+
async save(sessionId, cp) {
|
|
12
|
+
const dir = path.join(this.#dir, safe(sessionId));
|
|
13
|
+
await mkdir(dir, { recursive: true });
|
|
14
|
+
const full = { ...cp, at: performance.timeOrigin + performance.now() };
|
|
15
|
+
await writeFile(path.join(dir, `${safe(cp.toolUseId)}.json`), JSON.stringify(full));
|
|
16
|
+
}
|
|
17
|
+
async list(sessionId) {
|
|
18
|
+
const dir = path.join(this.#dir, safe(sessionId));
|
|
19
|
+
let names;
|
|
20
|
+
try {
|
|
21
|
+
names = await readdir(dir);
|
|
22
|
+
} catch {
|
|
23
|
+
return [];
|
|
13
24
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const n of names) {
|
|
27
|
+
if (!n.endsWith(".json") || n === UNDONE)
|
|
28
|
+
continue;
|
|
29
|
+
try {
|
|
30
|
+
out.push(JSON.parse(await readFile(path.join(dir, n), "utf8")));
|
|
31
|
+
} catch {}
|
|
19
32
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
const out = [];
|
|
31
|
-
for (const n of names) {
|
|
32
|
-
if (!n.endsWith(".json") || n === UNDONE)
|
|
33
|
-
continue;
|
|
34
|
-
try {
|
|
35
|
-
out.push(JSON.parse(await readFile(path.join(dir, n), "utf8")));
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// 写到一半的快照,忽略
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return out.sort((a, b) => b.at - a.at);
|
|
33
|
+
return out.sort((a, b) => b.at - a.at);
|
|
34
|
+
}
|
|
35
|
+
async undone(sessionId) {
|
|
36
|
+
try {
|
|
37
|
+
const ids = JSON.parse(await readFile(path.join(this.#dir, safe(sessionId), UNDONE), "utf8"));
|
|
38
|
+
return new Set(Array.isArray(ids) ? ids.filter((x) => typeof x === "string") : []);
|
|
39
|
+
} catch {
|
|
40
|
+
return new Set;
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
}
|
|
43
|
+
async markUndone(sessionId, ids) {
|
|
44
|
+
const all = await this.undone(sessionId);
|
|
45
|
+
for (const id of ids)
|
|
46
|
+
all.add(id);
|
|
47
|
+
const dir = path.join(this.#dir, safe(sessionId));
|
|
48
|
+
await mkdir(dir, { recursive: true });
|
|
49
|
+
await writeFile(path.join(dir, UNDONE), JSON.stringify([...all]));
|
|
50
|
+
}
|
|
51
|
+
async unchangedSince(cp) {
|
|
52
|
+
try {
|
|
53
|
+
return sha256(await readFile(cp.path, "utf8")) === cp.afterHash;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
/** 文件现在的内容是否还是这次写入的结果 */
|
|
62
|
-
async unchangedSince(cp) {
|
|
63
|
-
try {
|
|
64
|
-
return sha256(await readFile(cp.path, "utf8")) === cp.afterHash;
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/** 把文件恢复成写入前的样子;原本不存在的文件删掉 */
|
|
71
|
-
async restore(cp) {
|
|
72
|
-
if (cp.before === null)
|
|
73
|
-
await rm(cp.path, { force: true });
|
|
74
|
-
else {
|
|
75
|
-
await mkdir(path.dirname(cp.path), { recursive: true });
|
|
76
|
-
await writeFile(cp.path, cp.before);
|
|
77
|
-
}
|
|
57
|
+
}
|
|
58
|
+
async restore(cp) {
|
|
59
|
+
if (cp.before === null)
|
|
60
|
+
await rm(cp.path, { force: true });
|
|
61
|
+
else {
|
|
62
|
+
await mkdir(path.dirname(cp.path), { recursive: true });
|
|
63
|
+
await writeFile(cp.path, cp.before);
|
|
78
64
|
}
|
|
65
|
+
}
|
|
79
66
|
}
|
|
80
67
|
const UNDONE = "undone.json";
|
|
81
|
-
/**
|
|
82
|
-
* 最近一轮还有没撤销的修改的快照(最新的在前)。一轮从一条用户自己写的消息开始;
|
|
83
|
-
* 只有工具结果、或者只有插件、宿主加的说明(例如自动续写的提示)的消息不算新的一轮。没有可撤销的返回空数组
|
|
84
|
-
*/
|
|
85
68
|
export function lastTurnChanges(messages, checkpoints, undone) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user");
|
|
99
|
-
if (!startsTurn)
|
|
100
|
-
continue;
|
|
101
|
-
const hits = pending.filter((c) => ids.has(c.toolUseId));
|
|
102
|
-
if (hits.length > 0)
|
|
103
|
-
return hits;
|
|
104
|
-
ids = new Set();
|
|
69
|
+
const pending = checkpoints.filter((c) => !undone.has(c.toolUseId));
|
|
70
|
+
if (pending.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
let ids = new Set;
|
|
73
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
74
|
+
const m = messages[i];
|
|
75
|
+
if (m.role === "assistant") {
|
|
76
|
+
for (const b of m.content)
|
|
77
|
+
if (b.kind === "tool_use")
|
|
78
|
+
ids.add(b.id);
|
|
79
|
+
continue;
|
|
105
80
|
}
|
|
106
|
-
|
|
107
|
-
|
|
81
|
+
const startsTurn = m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user");
|
|
82
|
+
if (!startsTurn)
|
|
83
|
+
continue;
|
|
84
|
+
const hits = pending.filter((c) => ids.has(c.via ?? c.toolUseId));
|
|
85
|
+
if (hits.length > 0)
|
|
86
|
+
return hits;
|
|
87
|
+
ids = new Set;
|
|
88
|
+
}
|
|
89
|
+
return pending.slice(0, 1);
|
|
108
90
|
}
|
|
109
|
-
/**
|
|
110
|
-
* 一轮里调用过的工具名:含 toolUseId 的那一轮;不给时是最近一轮。
|
|
111
|
-
* 一轮从用户发的消息开始,到下一条用户消息之前(与 lastTurnChanges 的划分相同)
|
|
112
|
-
*/
|
|
113
91
|
export function turnToolNames(messages, toolUseId) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
if (!m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user"))
|
|
129
|
-
continue;
|
|
130
|
-
if (found)
|
|
131
|
-
return names;
|
|
132
|
-
names = new Set();
|
|
92
|
+
let names = new Set;
|
|
93
|
+
let found = toolUseId === undefined;
|
|
94
|
+
for (let i = messages.length - 1;i >= 0; i--) {
|
|
95
|
+
const m = messages[i];
|
|
96
|
+
if (m.role === "assistant") {
|
|
97
|
+
for (const b of m.content) {
|
|
98
|
+
if (b.kind !== "tool_use")
|
|
99
|
+
continue;
|
|
100
|
+
names.add(b.name);
|
|
101
|
+
if (b.id === toolUseId)
|
|
102
|
+
found = true;
|
|
103
|
+
}
|
|
104
|
+
continue;
|
|
133
105
|
}
|
|
134
|
-
|
|
106
|
+
if (!m.content.some((b) => b.kind !== "tool_result" && b.origin.by === "user"))
|
|
107
|
+
continue;
|
|
108
|
+
if (found)
|
|
109
|
+
return names;
|
|
110
|
+
names = new Set;
|
|
111
|
+
}
|
|
112
|
+
return found ? names : new Set;
|
|
135
113
|
}
|
|
136
|
-
/** 会话和工具调用的 id 用作文件名 */
|
|
137
114
|
export const safe = (id) => id.replace(/[^A-Za-z0-9_.-]/g, "_");
|