@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.
Files changed (78) hide show
  1. package/README.md +14 -11
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/install.js +5 -0
  5. package/dist/install.js.map +1 -1
  6. package/package.json +6 -6
  7. package/plugins/approval/index.ts +129 -13
  8. package/plugins/approval/plugin.json +4 -1
  9. package/plugins/approval/policy.ts +127 -7
  10. package/plugins/approval/review.ts +188 -45
  11. package/plugins/ask/index.ts +29 -1
  12. package/plugins/budget/index.ts +44 -6
  13. package/plugins/budget/plugin.json +1 -2
  14. package/plugins/compact/compact.ts +153 -39
  15. package/plugins/compact/index.ts +39 -5
  16. package/plugins/compact/plugin.json +5 -2
  17. package/plugins/cost/cache.ts +114 -0
  18. package/plugins/cost/index.ts +109 -51
  19. package/plugins/cost/plugin.json +3 -2
  20. package/plugins/memory/memory.ts +51 -28
  21. package/plugins/models/configure.ts +344 -125
  22. package/plugins/models/index.ts +44 -9
  23. package/plugins/models/price.ts +291 -0
  24. package/plugins/models/provider.ts +40 -8
  25. package/plugins/models/saved.ts +20 -4
  26. package/plugins/modes/index.ts +3 -4
  27. package/plugins/prompts/prompts.ts +5 -1
  28. package/plugins/task/index.ts +31 -10
  29. package/plugins/task/plugin.json +5 -2
  30. package/plugins/task/subagent.ts +21 -4
  31. package/plugins/todo/index.ts +62 -1
  32. package/plugins/todo/plugin.json +1 -1
  33. package/plugins/tui/frontend.ts +31 -5
  34. package/plugins/tui/index.ts +2 -1
  35. package/plugins/tui/plugin.json +1 -1
  36. package/plugins/tui/screen.ts +17 -5
  37. package/plugins/tui/transcript.ts +518 -507
  38. package/plugins/tui/tui.ts +212 -54
  39. package/plugins/withdraw/index.ts +111 -0
  40. package/plugins/withdraw/plugin.json +8 -0
  41. package/plugins-dist/approval/index.js +103 -9
  42. package/plugins-dist/approval/plugin.json +4 -1
  43. package/plugins-dist/approval/policy.js +112 -9
  44. package/plugins-dist/approval/review.js +141 -34
  45. package/plugins-dist/ask/index.js +28 -2
  46. package/plugins-dist/budget/index.js +30 -7
  47. package/plugins-dist/budget/plugin.json +1 -2
  48. package/plugins-dist/compact/compact.js +106 -32
  49. package/plugins-dist/compact/index.js +27 -3
  50. package/plugins-dist/compact/plugin.json +6 -2
  51. package/plugins-dist/cost/cache.js +100 -0
  52. package/plugins-dist/cost/index.js +87 -38
  53. package/plugins-dist/cost/plugin.json +5 -2
  54. package/plugins-dist/memory/memory.js +51 -32
  55. package/plugins-dist/models/configure.js +285 -105
  56. package/plugins-dist/models/index.js +33 -2
  57. package/plugins-dist/models/price.js +244 -0
  58. package/plugins-dist/models/provider.js +22 -4
  59. package/plugins-dist/models/saved.js +13 -3
  60. package/plugins-dist/modes/index.js +2 -3
  61. package/plugins-dist/prompts/prompts.js +5 -1
  62. package/plugins-dist/task/index.js +25 -7
  63. package/plugins-dist/task/plugin.json +5 -2
  64. package/plugins-dist/task/subagent.js +15 -6
  65. package/plugins-dist/todo/index.js +50 -0
  66. package/plugins-dist/todo/plugin.json +1 -1
  67. package/plugins-dist/tui/frontend.js +26 -4
  68. package/plugins-dist/tui/index.js +2 -1
  69. package/plugins-dist/tui/plugin.json +2 -1
  70. package/plugins-dist/tui/screen.js +7 -3
  71. package/plugins-dist/tui/transcript.js +13 -5
  72. package/plugins-dist/tui/tui.js +197 -50
  73. package/plugins-dist/tui/vendor.js +1388 -1088
  74. package/plugins-dist/withdraw/index.js +88 -0
  75. package/plugins-dist/withdraw/plugin.json +12 -0
  76. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  77. package/src/api.ts +1 -1
  78. 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
+ });
@@ -0,0 +1,12 @@
1
+ {
2
+ "id": "jade/withdraw",
3
+ "version": "0.1.0",
4
+ "api": "^1",
5
+ "entry": "./index.js",
6
+ "provides": [
7
+ "withdraw@1"
8
+ ],
9
+ "optional": [
10
+ "renderers@1"
11
+ ]
12
+ }
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.6.0";
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);