@uncarved/jade 0.5.1 → 0.5.2
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 +14 -11
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/install.js +5 -0
- package/dist/install.js.map +1 -1
- package/package.json +6 -6
- package/plugins/approval/index.ts +129 -13
- package/plugins/approval/plugin.json +4 -1
- package/plugins/approval/policy.ts +127 -7
- package/plugins/approval/review.ts +188 -45
- package/plugins/ask/index.ts +29 -1
- package/plugins/budget/index.ts +44 -6
- package/plugins/budget/plugin.json +1 -2
- package/plugins/compact/compact.ts +153 -39
- package/plugins/compact/index.ts +39 -5
- package/plugins/compact/plugin.json +5 -2
- package/plugins/cost/cache.ts +114 -0
- package/plugins/cost/index.ts +109 -51
- package/plugins/cost/plugin.json +3 -2
- package/plugins/memory/memory.ts +51 -28
- package/plugins/models/configure.ts +344 -125
- package/plugins/models/index.ts +44 -9
- package/plugins/models/price.ts +291 -0
- package/plugins/models/provider.ts +40 -8
- package/plugins/models/saved.ts +20 -4
- package/plugins/modes/index.ts +3 -4
- package/plugins/prompts/prompts.ts +5 -1
- package/plugins/task/index.ts +31 -10
- package/plugins/task/plugin.json +5 -2
- package/plugins/task/subagent.ts +21 -4
- package/plugins/todo/index.ts +62 -1
- package/plugins/todo/plugin.json +1 -1
- package/plugins/tui/frontend.ts +31 -5
- package/plugins/tui/index.ts +2 -1
- package/plugins/tui/plugin.json +1 -1
- package/plugins/tui/screen.ts +17 -5
- package/plugins/tui/transcript.ts +518 -507
- package/plugins/tui/tui.ts +212 -54
- package/plugins/withdraw/index.ts +111 -0
- package/plugins/withdraw/plugin.json +8 -0
- package/plugins-dist/approval/index.js +103 -9
- package/plugins-dist/approval/plugin.json +4 -1
- package/plugins-dist/approval/policy.js +112 -9
- package/plugins-dist/approval/review.js +141 -34
- package/plugins-dist/ask/index.js +28 -2
- package/plugins-dist/budget/index.js +30 -7
- package/plugins-dist/budget/plugin.json +1 -2
- package/plugins-dist/compact/compact.js +106 -32
- package/plugins-dist/compact/index.js +27 -3
- package/plugins-dist/compact/plugin.json +6 -2
- package/plugins-dist/cost/cache.js +100 -0
- package/plugins-dist/cost/index.js +87 -38
- package/plugins-dist/cost/plugin.json +5 -2
- package/plugins-dist/memory/memory.js +51 -32
- package/plugins-dist/models/configure.js +285 -105
- package/plugins-dist/models/index.js +33 -2
- package/plugins-dist/models/price.js +244 -0
- package/plugins-dist/models/provider.js +22 -4
- package/plugins-dist/models/saved.js +13 -3
- package/plugins-dist/modes/index.js +2 -3
- package/plugins-dist/prompts/prompts.js +5 -1
- package/plugins-dist/task/index.js +25 -7
- package/plugins-dist/task/plugin.json +5 -2
- package/plugins-dist/task/subagent.js +15 -6
- package/plugins-dist/todo/index.js +50 -0
- package/plugins-dist/todo/plugin.json +1 -1
- package/plugins-dist/tui/frontend.js +26 -4
- package/plugins-dist/tui/index.js +2 -1
- package/plugins-dist/tui/plugin.json +2 -1
- package/plugins-dist/tui/screen.js +7 -3
- package/plugins-dist/tui/transcript.js +13 -5
- package/plugins-dist/tui/tui.js +197 -50
- package/plugins-dist/tui/vendor.js +1388 -1088
- package/plugins-dist/withdraw/index.js +88 -0
- package/plugins-dist/withdraw/plugin.json +12 -0
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/src/api.ts +1 -1
- package/src/install.ts +5 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { definePlugin } from "@uncarved/jade-api";
|
|
2
|
+
const ID = "jade/withdraw";
|
|
3
|
+
const KEY = `${ID}/withdrawn`;
|
|
4
|
+
const sessions = new Map;
|
|
5
|
+
const dim = (text) => ({ text, style: "dim" });
|
|
6
|
+
const userText = (m) => m.content.flatMap((b) => b.kind === "text" && b.origin.by === "user" ? [b.text] : []).join(`
|
|
7
|
+
`);
|
|
8
|
+
export default definePlugin({
|
|
9
|
+
process(ctx) {
|
|
10
|
+
ctx.provide("withdraw@1", (caller) => ({
|
|
11
|
+
arm(session) {
|
|
12
|
+
if (caller.layer === "project")
|
|
13
|
+
throw new Error("withdraw.arm: project plugins cannot withdraw the user's messages");
|
|
14
|
+
const s = sessions.get(session);
|
|
15
|
+
if (!s?.running())
|
|
16
|
+
return false;
|
|
17
|
+
s.armed = true;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
ctx.service("renderers@1")?.event({
|
|
22
|
+
event: "withdrawn",
|
|
23
|
+
render: () => ({ line: dim("[withdrawn: the model will not see this message]") })
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
async session(ctx) {
|
|
27
|
+
if (ctx.session.parent)
|
|
28
|
+
return;
|
|
29
|
+
const id = ctx.session.id;
|
|
30
|
+
const entry = {
|
|
31
|
+
armed: false,
|
|
32
|
+
running() {
|
|
33
|
+
try {
|
|
34
|
+
const phase = ctx.session.phase();
|
|
35
|
+
return phase !== "new" && phase !== "idle" && phase !== "ended";
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
sessions.set(id, entry);
|
|
42
|
+
await ctx.effect(() => () => {
|
|
43
|
+
if (sessions.get(id) === entry)
|
|
44
|
+
sessions.delete(id);
|
|
45
|
+
});
|
|
46
|
+
ctx.kernel.hook({
|
|
47
|
+
kind: "observe",
|
|
48
|
+
point: "event",
|
|
49
|
+
fn: async (e, hook) => {
|
|
50
|
+
if (e.type !== "turn.ended")
|
|
51
|
+
return;
|
|
52
|
+
const armed = entry.armed;
|
|
53
|
+
entry.armed = false;
|
|
54
|
+
if (!armed || e.data.reason !== "aborted")
|
|
55
|
+
return;
|
|
56
|
+
const messages = ctx.session.state().messages;
|
|
57
|
+
const at = messages.length - 1;
|
|
58
|
+
const last = messages[at];
|
|
59
|
+
if (!last || last.role !== "user" || last.content.some((b) => b.kind === "tool_result"))
|
|
60
|
+
return;
|
|
61
|
+
const done = hook.derived[KEY] ?? [];
|
|
62
|
+
if (done.includes(at))
|
|
63
|
+
return;
|
|
64
|
+
const text = userText(last);
|
|
65
|
+
await hook.record(KEY, [...done, at]);
|
|
66
|
+
await hook.emit("withdrawn", { text });
|
|
67
|
+
const typed = ctx.input?.text() ?? "";
|
|
68
|
+
if (text)
|
|
69
|
+
ctx.input?.set(typed.trim() ? `${text}
|
|
70
|
+
${typed}` : text);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
ctx.kernel.hook({
|
|
74
|
+
kind: "transform",
|
|
75
|
+
point: "context.project",
|
|
76
|
+
order: -45,
|
|
77
|
+
fn: (messages, hook) => {
|
|
78
|
+
const done = hook.derived[KEY];
|
|
79
|
+
if (!done?.length)
|
|
80
|
+
return messages;
|
|
81
|
+
const drop = new Set(done);
|
|
82
|
+
if (drop.has(messages.length - 1))
|
|
83
|
+
throw new Error("nothing to send: your last message was withdrawn");
|
|
84
|
+
return messages.filter((_, i) => !drop.has(i));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
});
|
|
Binary file
|
package/src/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PluginLayer } from "@uncarved/jade-api";
|
|
|
5
5
|
export * from "@uncarved/jade-api";
|
|
6
6
|
|
|
7
7
|
/** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明。和 @uncarved/jade-api 的版本一致 */
|
|
8
|
-
export const API_VERSION = "1.
|
|
8
|
+
export const API_VERSION = "1.7.0";
|
|
9
9
|
|
|
10
10
|
/** 来源层级,后面的层级更高(3.3) */
|
|
11
11
|
export const LAYERS: readonly PluginLayer[] = ["bundled", "user", "project"];
|
package/src/install.ts
CHANGED
|
@@ -197,6 +197,11 @@ export async function updatePlugins(names: readonly string[], opts: UpdateOption
|
|
|
197
197
|
|
|
198
198
|
async function updateOne(root: string, rec: InstallRecord, opts: UpdateOptions): Promise<UpdateResult> {
|
|
199
199
|
const dir = path.join(root, rec.dir || path.basename(installDir(root, rec.id)));
|
|
200
|
+
// 记录文件坏了(或被改过)时,目录可能指到插件目录外面:更新会整个替换它,和 removePlugin 一样先确认
|
|
201
|
+
const rel = path.relative(root, dir);
|
|
202
|
+
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
203
|
+
return { id: rec.id, dir, status: "failed", error: `refusing to update ${dir}: it is not inside ${root}` };
|
|
204
|
+
}
|
|
200
205
|
if (rec.kind === "link") return { id: rec.id, dir, status: "linked" };
|
|
201
206
|
|
|
202
207
|
const exists = await lstat(dir).catch(() => undefined);
|