@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.
Files changed (207) hide show
  1. package/README.md +1 -0
  2. package/dist/api.d.ts +1 -1
  3. package/dist/api.js +1 -1
  4. package/dist/host.d.ts +2 -0
  5. package/dist/host.js +39 -5
  6. package/dist/host.js.map +1 -1
  7. package/dist/remote.js +5 -0
  8. package/dist/remote.js.map +1 -1
  9. package/dist/session.d.ts +7 -0
  10. package/dist/session.js +482 -27
  11. package/dist/session.js.map +1 -1
  12. package/package.json +4 -4
  13. package/plugins/approval/index.ts +49 -24
  14. package/plugins/approval/policy.ts +48 -25
  15. package/plugins/approval/review.ts +9 -5
  16. package/plugins/checks/checks.ts +10 -7
  17. package/plugins/checks/index.ts +13 -13
  18. package/plugins/checks/plugin.json +1 -1
  19. package/plugins/checks/project.ts +37 -38
  20. package/plugins/commands/index.ts +27 -3
  21. package/plugins/compact/compact.ts +13 -5
  22. package/plugins/compact/index.ts +20 -3
  23. package/plugins/compact/style.ts +13 -14
  24. package/plugins/completions/index.ts +35 -0
  25. package/plugins/completions/plugin.json +7 -0
  26. package/plugins/copy/index.ts +46 -0
  27. package/plugins/copy/plugin.json +7 -0
  28. package/plugins/editor/index.ts +10 -4
  29. package/plugins/fs/diff.ts +7 -6
  30. package/plugins/fs/fs.ts +8 -4
  31. package/plugins/fs/grep.ts +55 -12
  32. package/plugins/fs/index.ts +2 -7
  33. package/plugins/fs/plugin.json +1 -1
  34. package/plugins/fs/renderers.ts +16 -15
  35. package/plugins/fs/style.ts +16 -15
  36. package/plugins/hooks/index.ts +3 -2
  37. package/plugins/keys/index.ts +5 -1
  38. package/plugins/mcp/index.ts +197 -78
  39. package/plugins/mcp/install.ts +5 -3
  40. package/plugins/mcp/mcp.ts +163 -11
  41. package/plugins/mcp/plugin.json +2 -1
  42. package/plugins/mcp/project.ts +47 -50
  43. package/plugins/memory/index.ts +4 -4
  44. package/plugins/memory/style.ts +13 -14
  45. package/plugins/mentions/candidates.ts +67 -0
  46. package/plugins/mentions/index.ts +12 -5
  47. package/plugins/mentions/plugin.json +1 -1
  48. package/plugins/mentions/style.ts +13 -14
  49. package/plugins/models/configure.ts +10 -9
  50. package/plugins/models/index.ts +31 -4
  51. package/plugins/models/provider.ts +12 -1
  52. package/plugins/modes/index.ts +13 -2
  53. package/plugins/print/index.ts +7 -4
  54. package/plugins/prompts/index.ts +0 -0
  55. package/plugins/renderers/index.ts +10 -5
  56. package/plugins/repeats/index.ts +39 -9
  57. package/plugins/schedule/index.ts +2 -0
  58. package/plugins/screenshot/browser.ts +231 -0
  59. package/plugins/screenshot/index.ts +3 -2
  60. package/plugins/screenshot/tool.ts +27 -51
  61. package/plugins/sessions/index.ts +48 -2
  62. package/plugins/shell/index.ts +75 -22
  63. package/plugins/shell/plugin.json +1 -2
  64. package/plugins/shell/renderers.ts +9 -7
  65. package/plugins/shell/shell.ts +93 -34
  66. package/plugins/skills/index.ts +28 -19
  67. package/plugins/skills/project.ts +12 -7
  68. package/plugins/steer/index.ts +5 -4
  69. package/plugins/task/index.ts +81 -81
  70. package/plugins/task/plugin.json +5 -2
  71. package/plugins/task/style.ts +13 -14
  72. package/plugins/task/subagent.ts +67 -184
  73. package/plugins/todo/index.ts +39 -9
  74. package/plugins/tools/index.ts +57 -0
  75. package/plugins/tools/plugin.json +7 -0
  76. package/plugins/tui/frontend.ts +161 -87
  77. package/plugins/tui/index.ts +2 -3
  78. package/plugins/tui/mascot.ts +8 -7
  79. package/plugins/tui/mentions.ts +11 -80
  80. package/plugins/tui/plugin.json +1 -1
  81. package/plugins/tui/screen.ts +55 -5
  82. package/plugins/tui/transcript.ts +17 -7
  83. package/plugins/tui/tui.ts +356 -104
  84. package/plugins/tui/vendor.ts +1 -1
  85. package/plugins/undo/checkpoint.ts +5 -3
  86. package/plugins/undo/index.ts +43 -14
  87. package/plugins/undo/style.ts +13 -14
  88. package/plugins/web/index.ts +7 -18
  89. package/plugins/web/plugin.json +1 -1
  90. package/plugins-dist/approval/index.js +363 -414
  91. package/plugins-dist/approval/policy.js +395 -497
  92. package/plugins-dist/approval/review.js +132 -158
  93. package/plugins-dist/approval/schema.js +50 -55
  94. package/plugins-dist/ask/index.js +115 -129
  95. package/plugins-dist/budget/index.js +27 -31
  96. package/plugins-dist/checks/checks.js +293 -329
  97. package/plugins-dist/checks/index.js +119 -139
  98. package/plugins-dist/checks/plugin.json +2 -1
  99. package/plugins-dist/checks/project.js +57 -65
  100. package/plugins-dist/commands/index.js +47 -29
  101. package/plugins-dist/compact/compact.js +233 -249
  102. package/plugins-dist/compact/index.js +98 -95
  103. package/plugins-dist/compact/style.js +9 -14
  104. package/plugins-dist/completions/index.js +30 -0
  105. package/plugins-dist/completions/plugin.json +9 -0
  106. package/plugins-dist/continue/index.js +40 -52
  107. package/plugins-dist/copy/index.js +40 -0
  108. package/plugins-dist/copy/plugin.json +9 -0
  109. package/plugins-dist/cost/index.js +98 -115
  110. package/plugins-dist/custom-commands/index.js +55 -72
  111. package/plugins-dist/editor/index.js +64 -72
  112. package/plugins-dist/fs/diff.js +111 -124
  113. package/plugins-dist/fs/fs.js +426 -469
  114. package/plugins-dist/fs/grep.js +262 -244
  115. package/plugins-dist/fs/index.js +20 -34
  116. package/plugins-dist/fs/plugin.json +1 -2
  117. package/plugins-dist/fs/renderers.js +100 -112
  118. package/plugins-dist/fs/style.js +11 -15
  119. package/plugins-dist/fs/sys.js +31 -43
  120. package/plugins-dist/hooks/index.js +107 -127
  121. package/plugins-dist/keys/index.js +27 -31
  122. package/plugins-dist/mcp/index.js +271 -199
  123. package/plugins-dist/mcp/install.js +123 -137
  124. package/plugins-dist/mcp/mcp.js +638 -577
  125. package/plugins-dist/mcp/plugin.json +3 -1
  126. package/plugins-dist/mcp/project.js +98 -115
  127. package/plugins-dist/memory/index.js +83 -88
  128. package/plugins-dist/memory/memory.js +111 -128
  129. package/plugins-dist/memory/style.js +9 -14
  130. package/plugins-dist/mentions/attach.js +91 -99
  131. package/plugins-dist/mentions/candidates.js +49 -0
  132. package/plugins-dist/mentions/index.js +71 -81
  133. package/plugins-dist/mentions/plugin.json +2 -1
  134. package/plugins-dist/mentions/style.js +9 -14
  135. package/plugins-dist/models/config.js +29 -43
  136. package/plugins-dist/models/configure.js +392 -473
  137. package/plugins-dist/models/context.js +14 -22
  138. package/plugins-dist/models/index.js +182 -188
  139. package/plugins-dist/models/provider.js +243 -295
  140. package/plugins-dist/models/saved.js +59 -71
  141. package/plugins-dist/modes/index.js +138 -165
  142. package/plugins-dist/plugins/index.js +34 -34
  143. package/plugins-dist/print/index.js +192 -175
  144. package/plugins-dist/prompts/index.js +81 -89
  145. package/plugins-dist/prompts/notes.js +31 -37
  146. package/plugins-dist/prompts/prompts.js +155 -193
  147. package/plugins-dist/prompts/results.js +40 -53
  148. package/plugins-dist/prompts/sys.js +39 -50
  149. package/plugins-dist/renderers/index.js +32 -32
  150. package/plugins-dist/repeats/index.js +134 -151
  151. package/plugins-dist/schedule/cron.js +49 -56
  152. package/plugins-dist/schedule/index.js +229 -247
  153. package/plugins-dist/schedule/store.js +93 -109
  154. package/plugins-dist/scratch/index.js +12 -18
  155. package/plugins-dist/screenshot/browser.js +169 -0
  156. package/plugins-dist/screenshot/index.js +37 -45
  157. package/plugins-dist/screenshot/sys.js +53 -65
  158. package/plugins-dist/screenshot/tool.js +101 -151
  159. package/plugins-dist/sessions/index.js +149 -117
  160. package/plugins-dist/shell/index.js +117 -74
  161. package/plugins-dist/shell/plugin.json +1 -2
  162. package/plugins-dist/shell/renderers.js +28 -33
  163. package/plugins-dist/shell/service.js +17 -23
  164. package/plugins-dist/shell/shell.js +317 -320
  165. package/plugins-dist/shell/sys.js +64 -79
  166. package/plugins-dist/skills/index.js +193 -211
  167. package/plugins-dist/skills/install.js +122 -149
  168. package/plugins-dist/skills/project.js +65 -73
  169. package/plugins-dist/skills/skills.js +135 -171
  170. package/plugins-dist/steer/index.js +108 -125
  171. package/plugins-dist/suggest/index.js +235 -259
  172. package/plugins-dist/task/index.js +130 -148
  173. package/plugins-dist/task/plugin.json +5 -4
  174. package/plugins-dist/task/style.js +9 -14
  175. package/plugins-dist/task/subagent.js +156 -279
  176. package/plugins-dist/todo/index.js +79 -63
  177. package/plugins-dist/tools/index.js +43 -0
  178. package/plugins-dist/tools/plugin.json +9 -0
  179. package/plugins-dist/tui/editor.js +145 -160
  180. package/plugins-dist/tui/frontend.js +641 -655
  181. package/plugins-dist/tui/history.js +34 -37
  182. package/plugins-dist/tui/index.js +16 -18
  183. package/plugins-dist/tui/markdown.js +203 -247
  184. package/plugins-dist/tui/mascot.js +266 -353
  185. package/plugins-dist/tui/mentions.js +67 -144
  186. package/plugins-dist/tui/plugin.json +1 -2
  187. package/plugins-dist/tui/render.js +35 -45
  188. package/plugins-dist/tui/screen.js +197 -180
  189. package/plugins-dist/tui/transcript.js +436 -468
  190. package/plugins-dist/tui/tui.js +1554 -1645
  191. package/plugins-dist/tui/vendor.js +1388 -1088
  192. package/plugins-dist/undo/checkpoint.js +95 -118
  193. package/plugins-dist/undo/index.js +185 -192
  194. package/plugins-dist/undo/snapshot.js +83 -99
  195. package/plugins-dist/undo/style.js +9 -14
  196. package/plugins-dist/update/index.js +26 -28
  197. package/plugins-dist/web/env.js +55 -68
  198. package/plugins-dist/web/index.js +80 -110
  199. package/plugins-dist/web/plugin.json +1 -2
  200. package/plugins-dist/web/renderers.js +4 -5
  201. package/plugins-dist/web/web.js +514 -593
  202. package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
  203. package/sdk/python/jade_plugin.py +9 -2
  204. package/src/api.ts +1 -1
  205. package/src/host.ts +39 -4
  206. package/src/remote.ts +6 -1
  207. package/src/session.ts +489 -34
@@ -1,154 +1,136 @@
1
- // jade/task:task 工具,把调研交给只读的子 Agent(见 subagent.ts)。
2
- //
3
- // 子 Agent 用哪些工具:插件经 task@1 登记只读工具(jade/fs 登记 read_file、list_dir、glob、grep),
4
- // 登记随登记者的作用域撤销。主会话里的工具对象是各插件私有的,子 Agent 拿到的是登记者另给的一份。
5
1
  import { definePlugin } from "@uncarved/jade-api";
6
- import { taskTool } from "./subagent.js";
7
- import { clip, dim, red } from "./style.js";
2
+ import { CHARS_PER_TOKEN, FALLBACK_WINDOW, fitToolResults, READ_ONLY_REASON, REPORT_TOOL_SHARE, stepsThisTurn, subagentPrompt, taskTool, WRAP_UP_AT } from "./subagent.js";
3
+ import { clip, dim, error, lines as joinLines } from "./style.js";
8
4
  const DEFAULT_MAX_STEPS = 40;
9
5
  const MAX_DETAIL_LINES = 40;
10
- /** 登记的只读工具,按登记顺序 */
11
- const registry = [];
12
- /** 这次启动子 Agent 时给它的工具:同名的取最后登记的那个,when 返回 false 或出错的不给 */
13
- function available() {
14
- const latest = new Map();
15
- for (const r of registry) {
16
- latest.delete(r.tool.name);
17
- latest.set(r.tool.name, r);
18
- }
19
- return [...latest.values()].flatMap((r) => {
20
- try {
21
- return !r.when || r.when() ? [r.tool] : [];
22
- }
23
- catch {
24
- return [];
25
- }
26
- });
27
- }
28
- /** 子 Agent 的审批一次问一个:并行的几个子 Agent 不同时弹对话框 */
29
- let asking = Promise.resolve();
6
+ const controls = new Map;
30
7
  export default definePlugin({
31
- process(ctx) {
32
- ctx.provide("task@1", (caller) => ({
33
- tool(tool, opts) {
34
- if (typeof tool?.name !== "string" || typeof tool.execute !== "function")
35
- throw new Error("task.tool: a tool needs a name and execute");
36
- // 同一个插件重复登记是正常的:换会话时新会话先登记,旧会话随后撤销它的那份;取最后登记的
37
- const taken = registry.find((r) => r.tool.name === tool.name && r.plugin !== caller.plugin);
38
- if (taken)
39
- throw new Error(`task.tool: ${tool.name} is already registered by ${taken.plugin}`);
40
- if (opts?.when !== undefined && typeof opts.when !== "function")
41
- throw new Error("task.tool: when must be a function");
42
- const entry = { tool, plugin: caller.plugin, ...(opts?.when ? { when: opts.when } : {}) };
43
- registry.push(entry);
44
- const revoke = () => {
45
- const i = registry.indexOf(entry);
46
- if (i !== -1)
47
- registry.splice(i, 1);
48
- };
49
- caller.onDispose(revoke);
50
- return revoke;
51
- },
52
- }));
53
- const renderers = ctx.service("renderers@1");
54
- if (renderers) {
55
- // 运行中每个只有一行进度(标签、调用过几个工具、正在做什么),并行的几个靠标签分清;结束时把它调用过的工具放进结果的折叠内容里
56
- const labels = new Map();
57
- const steps = new Map();
58
- const line = (id, what) => {
59
- const n = steps.get(id)?.length ?? 0;
60
- return dim(` ↳ ${labels.get(id) ?? "sub-agent"}${n ? ` (${n} tool call${n > 1 ? "s" : ""})` : ""} · ${what}`);
61
- };
62
- renderers.tool({
63
- tool: "task",
64
- summary: (input) => String(input?.description ?? ""),
65
- progress(update, { toolUseId: id, summary }) {
66
- const p = update;
67
- if (p?.kind === "task-start") {
68
- labels.set(id, p.description);
69
- return line(id, "starting");
70
- }
71
- if (p?.kind === "task-model")
72
- return line(id, "thinking");
73
- if (p?.kind === "task-tool") {
74
- const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summary(p.name, p.input)})`;
75
- steps.set(id, [...(steps.get(id) ?? []), step]);
76
- return line(id, step);
77
- }
78
- return undefined;
79
- },
80
- result({ toolUseId: id, text, isError }) {
81
- const sub = steps.get(id) ?? [];
82
- steps.delete(id);
83
- labels.delete(id);
84
- // 没调用过工具时用默认的显示
85
- if (!sub.length)
86
- return undefined;
87
- const lines = text.split("\n");
88
- const shown = lines.slice(0, MAX_DETAIL_LINES).map((l) => (isError ? red(l) : l));
89
- if (lines.length > MAX_DETAIL_LINES)
90
- shown.push(dim(`… (${lines.length - MAX_DETAIL_LINES} more lines)`));
91
- return {
92
- line: isError ? red(clip(lines[0] ?? "", 200)) : dim(`${clip(lines[0] ?? "", 160)}${lines.length > 1 ? ` (+${lines.length - 1} lines)` : ""}`),
93
- details: [dim(`sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`)), ...shown].join("\n"),
94
- };
95
- },
96
- });
8
+ process(ctx) {
9
+ const renderers = ctx.service("renderers@1");
10
+ if (renderers) {
11
+ const labels = new Map;
12
+ const steps = new Map;
13
+ const line = (id, what) => {
14
+ const n = steps.get(id)?.length ?? 0;
15
+ return dim(` ↳ ${labels.get(id) ?? "sub-agent"}${n ? ` (${n} tool call${n > 1 ? "s" : ""})` : ""} · ${what}`);
16
+ };
17
+ renderers.tool({
18
+ tool: "task",
19
+ summary: (input) => String(input?.description ?? ""),
20
+ progress(update, { toolUseId: id, summary }) {
21
+ const p = update;
22
+ if (p?.kind === "task-start") {
23
+ labels.set(id, p.description);
24
+ return line(id, "starting");
25
+ }
26
+ if (p?.kind === "task-model")
27
+ return line(id, "thinking");
28
+ if (p?.kind === "task-tool") {
29
+ const step = `${p.decision === "deny" ? "✗" : "·"} ${p.name}(${summary(p.name, p.input)})`;
30
+ steps.set(id, [...steps.get(id) ?? [], step]);
31
+ return line(id, step);
32
+ }
33
+ return;
34
+ },
35
+ result({ toolUseId: id, text, isError }) {
36
+ const sub = steps.get(id) ?? [];
37
+ steps.delete(id);
38
+ labels.delete(id);
39
+ if (!sub.length)
40
+ return;
41
+ const lines = text.split(`
42
+ `);
43
+ const shown = lines.slice(0, MAX_DETAIL_LINES).map((l) => isError ? error(l) : l);
44
+ if (lines.length > MAX_DETAIL_LINES)
45
+ shown.push(dim(`… (${lines.length - MAX_DETAIL_LINES} more lines)`));
46
+ return {
47
+ line: isError ? error(clip(lines[0] ?? "", 200)) : dim(`${clip(lines[0] ?? "", 160)}${lines.length > 1 ? ` (+${lines.length - 1} lines)` : ""}`),
48
+ details: joinLines([dim(`sub-agent ran ${sub.length} tool call${sub.length > 1 ? "s" : ""}:`), ...sub.map((l) => dim(` ${l}`)), ...shown])
49
+ };
97
50
  }
98
- },
99
- session(ctx) {
100
- const models = ctx.require("models@1");
101
- /** 跑完、还没记进日志的子 Agent 用量,按 task 调用的 toolUseId */
102
- const usage = new Map();
103
- const configured = ctx.config.maxSteps;
104
- const maxSteps = typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_MAX_STEPS;
105
- // 子 Agent 用的模型:/model 保存过的名字,或当前服务上的另一个模型;不设时用会话的模型
106
- const model = typeof ctx.config.model === "string" && ctx.config.model ? ctx.config.model : undefined;
107
- const approve = (call, signal) => {
108
- const ui = ctx.service("ui@1");
109
- if (!ui?.interactive)
110
- return Promise.resolve({ approved: false, reason: "Nobody can approve this action for a sub-agent. Report what you need instead." });
111
- const ask = asking.then(async () => {
112
- const choice = await ui.select({
113
- title: `A sub-agent wants to ${call.why}. Allow it?`,
114
- detail: `${call.name} ${clip(JSON.stringify(call.input), 2000)}`,
115
- options: [
116
- { label: "Yes", value: "yes" },
117
- { label: "No", value: "no" },
118
- ],
119
- }, signal);
120
- return choice === "yes" ? { approved: true } : { approved: false, reason: "The user denied this action." };
121
- });
122
- asking = ask.catch(() => { });
123
- return ask;
124
- };
125
- ctx.kernel.tool(taskTool({
126
- cwd: ctx.cwd,
127
- provider: { id: ctx.plugin, complete: (req, o) => models.complete(req, model ? { ...o, model } : o) },
128
- tools: available,
129
- maxSteps,
130
- approve,
131
- allowed: (call) => ctx.service("approval@1")?.allows(ctx.session.id, call) ?? false,
132
- // 用到的时候再取:prompts@1 的提供者在自己的 session() 里才读指令文件,可能排在本插件后面
133
- ...(ctx.config.instructions === false ? {} : { instructions: () => ctx.service("prompts@1")?.instructions?.(ctx.session.id) ?? [] }),
134
- id: ctx.plugin,
135
- usage: (toolUseId, u) => void usage.set(toolUseId, u),
136
- contextWindow: () => models.current()?.contextWindow,
137
- }));
138
- // 子 Agent 的用量记成本插件的事件(和压缩、审查的用量一样),界面据此计入会话用量;只能在 hook 里记
139
- ctx.kernel.hook({
140
- kind: "transform",
141
- point: "tool.after",
142
- fn: async (outcome, hook) => {
143
- const u = usage.get(outcome.call.toolUseId);
144
- if (!u)
145
- return undefined;
146
- usage.delete(outcome.call.toolUseId);
147
- await hook.emit("subagent", { toolUseId: outcome.call.toolUseId, usage: u });
148
- return undefined;
149
- },
150
- });
151
- // 被中断的调用不经过 tool.after,一轮结束时还留着的不会再用到
152
- ctx.kernel.hook({ kind: "observe", point: "event", fn: (e) => void (e.type === "turn.ended" && usage.clear()) });
153
- },
51
+ });
52
+ }
53
+ },
54
+ session(ctx) {
55
+ const models = ctx.require("models@1");
56
+ const configured = ctx.config.maxSteps;
57
+ const maxSteps = typeof configured === "number" && Number.isInteger(configured) && configured > 0 ? configured : DEFAULT_MAX_STEPS;
58
+ const write = ctx.config.write === true;
59
+ const window = () => models.current()?.contextWindow ?? FALLBACK_WINDOW;
60
+ if (ctx.session.parent)
61
+ childHooks(ctx, () => controls.get(ctx.session.id), window);
62
+ if (!ctx.session.canSpawn)
63
+ return;
64
+ const usage = new Map;
65
+ const model = typeof ctx.config.model === "string" && ctx.config.model ? ctx.config.model : undefined;
66
+ const provider = model ? { id: ctx.plugin, complete: (req, o) => models.complete(req, { ...o, model }) } : undefined;
67
+ const system = subagentPrompt(maxSteps, write);
68
+ ctx.kernel.tool(taskTool({
69
+ maxSteps,
70
+ write,
71
+ spawn: (parent, description, signal) => ctx.session.spawn({
72
+ parent,
73
+ signal,
74
+ label: description,
75
+ system,
76
+ ...provider ? { provider } : {},
77
+ tools: (t) => t.name !== "ask_user" && (write || t.effect === "read" || t.meta?.shell !== undefined)
78
+ }),
79
+ register: (child, control) => {
80
+ controls.set(child, control);
81
+ return () => void controls.delete(child);
82
+ },
83
+ usage: (toolUseId, u) => void usage.set(toolUseId, u)
84
+ }));
85
+ ctx.kernel.hook({
86
+ kind: "transform",
87
+ point: "tool.after",
88
+ fn: async (outcome, hook) => {
89
+ const u = usage.get(outcome.call.toolUseId);
90
+ if (!u)
91
+ return;
92
+ usage.delete(outcome.call.toolUseId);
93
+ await hook.emit("subagent", { toolUseId: outcome.call.toolUseId, usage: u });
94
+ return;
95
+ }
96
+ });
97
+ ctx.kernel.hook({ kind: "observe", point: "event", fn: (e) => void (e.type === "turn.ended" && usage.clear()) });
98
+ }
154
99
  });
100
+ function childHooks(ctx, control, window) {
101
+ ctx.kernel.hook({
102
+ kind: "gate",
103
+ point: "turn.continue",
104
+ fn: (s) => {
105
+ const c = control();
106
+ if (!c)
107
+ return { decision: "abstain" };
108
+ return stepsThisTurn(s) >= (c.wrapUp ? 1 : c.maxSteps) || (c.lastTokens ?? 0) >= window() * WRAP_UP_AT ? { decision: "deny" } : { decision: "abstain" };
109
+ }
110
+ });
111
+ ctx.kernel.hook({
112
+ kind: "transform",
113
+ point: "context.project",
114
+ fn: (messages) => control()?.wrapUp ? fitToolResults(messages, window() * REPORT_TOOL_SHARE * CHARS_PER_TOKEN, ctx.plugin) : messages
115
+ });
116
+ ctx.kernel.hook({
117
+ kind: "gate",
118
+ point: "tool.gate",
119
+ fn: (call) => {
120
+ const c = control();
121
+ if (!c || c.write || call.tool.effect === "read")
122
+ return { decision: "abstain" };
123
+ if (ctx.service("approval@1")?.allows(ctx.session.id, call))
124
+ return { decision: "abstain" };
125
+ return { decision: "deny", reason: READ_ONLY_REASON(call.name) };
126
+ }
127
+ });
128
+ if (ctx.config.instructions === false) {
129
+ ctx.kernel.hook({
130
+ kind: "transform",
131
+ point: "context.build",
132
+ order: 100,
133
+ fn: (req) => control() ? { ...req, system: req.system.filter((seg) => !(seg.origin.by === "plugin" && seg.origin.id === "jade/prompts" && seg.origin.source)) } : req
134
+ });
135
+ }
136
+ }
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "id": "jade/task",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "api": "^1",
5
5
  "entry": "./index.js",
6
- "provides": [
7
- "task@1"
8
- ],
9
6
  "requires": [
10
7
  "models@1"
11
8
  ],
@@ -26,6 +23,10 @@
26
23
  },
27
24
  "model": {
28
25
  "description": "the model sub-agents use: a model saved by /model, or another model of the current service (for example a cheaper, faster one); default: the session's model"
26
+ },
27
+ "write": {
28
+ "default": false,
29
+ "description": "let sub-agents use every tool of the session, including ones that change files; their changes go through the same approval as the main agent's"
29
30
  }
30
31
  }
31
32
  }
@@ -1,14 +1,9 @@
1
- // 显示用的小工具:截断和 ANSI 颜色。插件之间不共享代码(只能共享类型),所以这里也有一份(同 jade/fs 的 style.ts)。
2
- export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
3
- // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
4
- const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
5
- /**
6
- * 每种样式用自己的关闭码,不用 \x1b[0m 全部重置:外面套着别的样式时,后面的文字仍保持外层样式。
7
- * 里面出现同一个关闭码(例如 dim 里套 bold,两者都用 22 关闭)时紧接着重新打开外层的样式
8
- */
9
- const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
10
- export const dim = paint("2", "22");
11
- export const red = paint("31", "39");
12
- export const green = paint("32", "39");
13
- export const yellow = paint("33", "39");
14
- export const bold = paint("1", "22");
1
+ export const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
2
+ const styled = (style) => (text) => ({ text, style });
3
+ export const dim = styled("dim");
4
+ export const bold = styled("bold");
5
+ export const ok = styled("ok");
6
+ export const warn = styled("warn");
7
+ export const error = styled("error");
8
+ export const lines = (rows) => rows.flatMap((r, i) => i ? [`
9
+ `, r] : [r]);