@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,85 +1,128 @@
1
- // jade/shell:bash 工具,以及后台命令的 bash_output、kill_shell;shell@1 给其他插件执行命令。
2
- // 后台命令自己结束时告诉用户,并给模型留一句说明(不用它一直轮询);/shells 给用户看和停掉后台命令。
3
1
  import { definePlugin } from "@uncarved/jade-api";
4
2
  import { shellRenderers } from "./renderers.js";
5
3
  import { shellService } from "./service.js";
6
4
  import { shellTools } from "./shell.js";
7
- /** 打开着的会话 → 它的后台命令(/shells 用) */
8
- const sessions = new Map();
5
+ const sessions = new Map;
9
6
  const firstLine = (command) => {
10
- const line = command.split("\n")[0];
11
- return line.length > 80 ? `${line.slice(0, 80)}…` : line;
7
+ const line = command.split(`
8
+ `)[0];
9
+ return line.length > 80 ? `${line.slice(0, 80)}…` : line;
12
10
  };
11
+ const SH_TIMEOUT_MS = 600000;
12
+ const SH_LIVE_CHARS = 4000;
13
+ const SH_SUMMARY = 160;
14
+ const shade = (failed, text) => ({ text, style: failed ? "error" : "dim" });
13
15
  export default definePlugin({
14
- process(ctx) {
15
- // 显示方式和会话无关,登记一次留到进程结束;没有 renderers@1(例如 print)时用前端的默认显示
16
- const renderers = ctx.service("renderers@1");
17
- if (renderers)
18
- for (const r of shellRenderers)
19
- renderers.tool(r);
20
- // shell@1:找 shell 和杀进程树只有一份(见 service.ts)
21
- ctx.provide("shell@1", shellService(typeof ctx.config.shell === "string" ? { shell: ctx.config.shell } : {}));
22
- ctx.service("commands@1")?.register({
23
- name: "shells",
24
- args: "[kill <id>]",
25
- description: "list the background commands the agent started, or stop one",
26
- instant: true,
27
- async run(args, { sessions: manager }) {
28
- const shells = manager.current && sessions.get(manager.current.id);
29
- const [verb, id] = args.trim().split(/\s+/);
30
- if (verb === "kill" && id)
31
- return shells && (await shells.kill(id)) ? `Stopped ${id}.` : `There is no background command ${id}.`;
32
- const all = shells?.list() ?? [];
33
- if (all.length === 0)
34
- return "No background commands.";
35
- return all.map((b) => `${b.id} ${b.status} ${firstLine(b.command)}`).join("\n");
36
- },
37
- });
38
- },
39
- async session(ctx) {
40
- const shell = typeof ctx.config.shell === "string" ? ctx.config.shell : undefined;
41
- const id = ctx.session.id;
42
- const { tools, executable, unavailable, shutdown, list, kill } = shellTools({
43
- cwd: ctx.cwd,
44
- ...(shell ? { shell } : {}),
45
- onExit(bg) {
46
- const what = `Background shell ${bg.id} (${firstLine(bg.command)}) exited with code ${bg.exitCode}`;
47
- ctx.service("ui@1")?.notify(what, bg.exitCode === 0 ? "info" : "warning");
48
- ctx.service("prompts@1")?.note(id, `${what}. Read its remaining output with bash_output.`);
49
- },
50
- });
51
- sessions.set(id, { list, kill });
52
- // 子 Agent(jade/task)的 bash:只收命令和时限,不能在后台跑;哪些命令能执行由 jade/task 按审批规则把关(只读的才行)
53
- const bash = tools.find((t) => t.name === "bash");
16
+ process(ctx) {
17
+ const renderers = ctx.service("renderers@1");
18
+ if (renderers)
19
+ for (const r of shellRenderers)
20
+ renderers.tool(r);
21
+ const shell = shellService(typeof ctx.config.shell === "string" ? { shell: ctx.config.shell } : {});
22
+ ctx.provide("shell@1", shell);
23
+ const commands = ctx.service("commands@1");
24
+ commands?.register({
25
+ name: "sh",
26
+ args: "<command>",
27
+ description: "run a shell command yourself (short form: !<command>); then the agent continues with its output",
28
+ prefix: "!",
29
+ prefixHint: "shell command · you run it, not the agent",
30
+ async run(args, { sessions: manager, signal, print, progress }) {
31
+ const command = args.trim();
32
+ if (!command)
33
+ return "Usage: /sh <command>, or !<command>";
34
+ if (!shell.executable)
35
+ return shell.unavailable;
36
+ let live = "";
37
+ let r;
38
+ let stopped = false;
54
39
  try {
55
- if (bash) {
56
- ctx.service("task@1")?.tool({
57
- ...bash,
58
- description: "Run a read-only shell command in the working directory (for example git log, git diff, git status, ls, rg) and return its exit code and output. " +
59
- "Commands that could change anything, or that touch paths outside the working directory, are refused.",
60
- inputSchema: { type: "object", properties: { command: { type: "string" }, timeout_ms: { type: "integer" } }, required: ["command"], additionalProperties: false },
61
- execute: (input, c) => bash.execute({ command: input.command, timeout_ms: input.timeout_ms }, c),
62
- });
40
+ r = await shell.run(command, {
41
+ cwd: ctx.cwd,
42
+ timeoutMs: SH_TIMEOUT_MS,
43
+ signal,
44
+ onOutput(text) {
45
+ live = (live + text).slice(-SH_LIVE_CHARS);
46
+ progress?.(live);
63
47
  }
48
+ });
49
+ } catch (e) {
50
+ if (!signal.aborted)
51
+ throw e;
52
+ stopped = true;
53
+ r = { code: null, output: live.trimEnd(), timedOut: false };
64
54
  }
65
- catch {
66
- // jade/task 被隔离时它的服务已失效:子 Agent 没有 bash,主会话的照常
67
- }
68
- if (unavailable)
69
- ctx.service("ui@1")?.notify(unavailable, "warning");
70
- for (const tool of tools)
71
- ctx.kernel.tool(tool);
72
- if (executable) {
73
- const lines = [`- Shell for the bash tool: ${executable} (POSIX syntax, also on Windows)`];
74
- // 模型常用 xdg-open、open 打开文件,Git Bash 里没有;start 是 Git 自带的 /usr/bin/start
75
- if (process.platform === "win32")
76
- lines.push('- To open a file or URL for the user, run: start "" <path-or-url> (xdg-open and open do not exist)');
77
- ctx.service("prompts@1")?.add({ text: lines.join("\n") });
78
- }
79
- // 会话关闭(换会话、退出)时杀掉还在运行的后台命令
80
- await ctx.effect(() => () => {
81
- sessions.delete(id);
82
- shutdown();
83
- });
84
- },
55
+ const status = stopped ? "stopped by the user" : r.timedOut ? `timed out after ${SH_TIMEOUT_MS / 1000}s` : `exit code ${r.code}`;
56
+ const lines = r.output ? r.output.split(`
57
+ `) : [];
58
+ const failed = r.code !== 0;
59
+ const first = failed ? `${status}${lines.length ? ` · ${lines[0]}` : ""}` : lines[0] ?? "(no output)";
60
+ const more = lines.length > 1 ? ` (+${lines.length - 1} lines)` : "";
61
+ const folded = lines.length > 1 || first.length > SH_SUMMARY;
62
+ print(shade(failed, `⎿ ${first.length > SH_SUMMARY ? `${first.slice(0, SH_SUMMARY)}…` : first}${more}`), folded ? { details: r.output.replace(/^/gm, " ") } : undefined);
63
+ const session = manager.current;
64
+ if (!stopped && session && session.state.messages.length > 0)
65
+ return { prompt: `I ran this shell command myself (${status}):
66
+ $ ${command}
67
+ ${r.output}` };
68
+ if (session)
69
+ ctx.service("prompts@1")?.note(session.id, `The user ran this shell command themselves (${status}):
70
+ $ ${command}
71
+ ${r.output}`);
72
+ }
73
+ });
74
+ commands?.register({
75
+ name: "shells",
76
+ args: "[kill <id>]",
77
+ description: "list the background commands the agent started, or stop one",
78
+ instant: true,
79
+ async run(args, { sessions: manager }) {
80
+ const shells = manager.current && sessions.get(manager.current.id);
81
+ const [verb, id] = args.trim().split(/\s+/);
82
+ if (verb === "kill" && id)
83
+ return shells && await shells.kill(id) ? `Stopped ${id}.` : `There is no background command ${id}.`;
84
+ const all = shells?.list() ?? [];
85
+ if (all.length === 0)
86
+ return "No background commands.";
87
+ return all.map((b) => `${b.id} ${b.status} ${firstLine(b.command)}`).join(`
88
+ `);
89
+ }
90
+ });
91
+ },
92
+ async session(ctx) {
93
+ const shell = typeof ctx.config.shell === "string" ? ctx.config.shell : undefined;
94
+ const id = ctx.session.id;
95
+ const { tools, executable, unavailable, shutdown, list, kill } = shellTools({
96
+ cwd: ctx.cwd,
97
+ ...shell ? { shell } : {},
98
+ onExit(bg) {
99
+ const what = `Background shell ${bg.id} (${firstLine(bg.command)}) exited with code ${bg.exitCode}`;
100
+ ctx.service("ui@1")?.notify(what, bg.exitCode === 0 ? "info" : "warning");
101
+ ctx.service("prompts@1")?.note(id, `${what}. Read its remaining output with bash_output.`);
102
+ }
103
+ });
104
+ sessions.set(id, { list, kill });
105
+ const child = ctx.session.parent !== undefined;
106
+ const foreground = (t) => t.name !== "bash" ? t : {
107
+ ...t,
108
+ inputSchema: { type: "object", properties: { command: { type: "string" }, timeout_ms: { type: "integer" } }, required: ["command"], additionalProperties: false },
109
+ execute: (input, c) => t.execute({ command: input.command, timeout_ms: input.timeout_ms }, c)
110
+ };
111
+ if (unavailable && !child)
112
+ ctx.service("ui@1")?.notify(unavailable, "warning");
113
+ for (const tool of tools)
114
+ if (!(child && (tool.name === "bash_output" || tool.name === "kill_shell")))
115
+ ctx.kernel.tool(child ? foreground(tool) : tool);
116
+ if (executable) {
117
+ const lines = [`- Shell for the bash tool: ${executable} (POSIX syntax, also on Windows)`];
118
+ if (process.platform === "win32")
119
+ lines.push('- To open a file or URL for the user, run: start "" <path-or-url> (xdg-open and open do not exist)');
120
+ ctx.service("prompts@1")?.add({ text: lines.join(`
121
+ `) });
122
+ }
123
+ await ctx.effect(() => () => {
124
+ sessions.delete(id);
125
+ shutdown();
126
+ });
127
+ }
85
128
  });
@@ -10,8 +10,7 @@
10
10
  "ui@1",
11
11
  "prompts@1",
12
12
  "renderers@1",
13
- "commands@1",
14
- "task@1"
13
+ "commands@1"
15
14
  ],
16
15
  "config": {
17
16
  "shell": {
@@ -1,40 +1,35 @@
1
- // bash、bash_output、kill_shell 在对话和审批里怎么显示(登记到 renderers@1)。从旧 jade 的 ui/renderers.ts 移植。
2
- //
3
- // 运行中的输出不登记 progress:bash 推送的是 { kind, stream, text },前端对 { text } 形式的进度默认逐行显示,
4
- // 正是想要的;自己写 progress 反而只能把一次推送(可能是好几行、半行)显示成一行。
5
- // 截断和颜色从旧 jade 的 ui/render.ts、ui/screen.ts 复制:插件之间不共享代码,fs 插件也有一份
6
- const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
7
- // 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
8
- const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
9
- const dim = (s) => (colors ? `\x1b[2m${s.replaceAll("\x1b[22m", "\x1b[22m\x1b[2m")}\x1b[22m` : s);
10
- const args = (input) => (input !== null && typeof input === "object" ? input : {});
1
+ const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
2
+ const dim = (text) => ({ text, style: "dim" });
3
+ const joinLines = (rows) => rows.flatMap((r, i) => i ? [`
4
+ `, r] : [r]);
5
+ const args = (input) => input !== null && typeof input === "object" ? input : {};
11
6
  const command = (input) => String(args(input).command ?? "");
12
- /** 摘要最多这么多个字符 */
13
7
  const MAX_SUMMARY = 120;
14
- /** 预览里的多行文字:每行前面加上标记,最多 max 行 */
15
8
  function marked(s, mark, max = 30) {
16
- const all = s.split("\n");
17
- const shown = all.slice(0, max).map((l) => `${mark} ${l}`);
18
- if (all.length > max)
19
- shown.push(dim(` … ${all.length - max} more lines`));
20
- return shown.join("\n");
9
+ const all = s.split(`
10
+ `);
11
+ const shown = all.slice(0, max).map((l) => `${mark} ${l}`);
12
+ if (all.length > max)
13
+ shown.push(dim(` … ${all.length - max} more lines`));
14
+ return joinLines(shown);
21
15
  }
22
16
  export const shellRenderers = [
23
- {
24
- tool: "bash",
25
- summary: (input) => clip(command(input).split("\n")[0], MAX_SUMMARY),
26
- // 摘要省略了内容时(多行或很长的命令),展开后先显示完整的命令
27
- details: (input) => {
28
- const lines = command(input).split("\n");
29
- if (lines.length === 1 && lines[0].length <= MAX_SUMMARY)
30
- return undefined;
31
- const shown = lines.slice(0, 200).map((l, i) => dim(`${i === 0 ? "$" : " "} ${l}`));
32
- if (lines.length > 200)
33
- shown.push(dim(`… ${lines.length - 200} more lines`));
34
- return shown.join("\n");
35
- },
36
- preview: (input) => marked(command(input), "$"),
17
+ {
18
+ tool: "bash",
19
+ summary: (input) => clip(command(input).split(`
20
+ `)[0], MAX_SUMMARY),
21
+ details: (input) => {
22
+ const lines = command(input).split(`
23
+ `);
24
+ if (lines.length === 1 && lines[0].length <= MAX_SUMMARY)
25
+ return;
26
+ const shown = lines.slice(0, 200).map((l, i) => dim(`${i === 0 ? "$" : " "} ${l}`));
27
+ if (lines.length > 200)
28
+ shown.push(dim(`… ${lines.length - 200} more lines`));
29
+ return joinLines(shown);
37
30
  },
38
- { tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
39
- { tool: "kill_shell", summary: (input) => String(args(input).id ?? "") },
31
+ preview: (input) => marked(command(input), "$")
32
+ },
33
+ { tool: "bash_output", summary: (input) => String(args(input).id ?? "") },
34
+ { tool: "kill_shell", summary: (input) => String(args(input).id ?? "") }
40
35
  ];
@@ -1,29 +1,23 @@
1
- // shell@1:给其他插件执行命令的入口(例如 jade/checks 跑项目的检查)。
2
- //
3
- // 找 shell、补 Git Bash 的 PATH、杀进程树这些只有一份,在 shell.ts 里;这里只把它包成服务。
4
- // 和 bash 工具不同,这里的命令不经过模型和审批:调用方(插件)自己决定要不要问用户。
5
- // 没有 shell 时 executable 是 undefined,run 会抛错;调用方据此说明"在这台机器上做不了"。
6
1
  import { capture, findShell, shellEnv } from "./shell.js";
7
2
  import { which } from "./sys.js";
8
- /** 默认的 shell:JADE_SHELL,否则 bash(Windows 上是 Git Bash) */
9
- export const shellName = (configured) => (typeof configured === "string" && configured.trim() ? configured : (process.env.JADE_SHELL ?? "bash"));
3
+ export const shellName = (configured) => typeof configured === "string" && configured.trim() ? configured : process.env.JADE_SHELL ?? "bash";
10
4
  export function shellService(opts = {}) {
11
- const name = shellName(opts.shell);
12
- const executable = findShell(name);
13
- if (!executable) {
14
- const hint = process.platform === "win32" ? "install Git for Windows, or set JADE_SHELL to the path of a bash executable" : "set JADE_SHELL to the path of a shell";
15
- const unavailable = `${name} was not found; ${hint}`;
16
- return {
17
- executable: undefined,
18
- unavailable,
19
- run: () => Promise.reject(new Error(unavailable)),
20
- which,
21
- };
22
- }
23
- const env = shellEnv(executable);
5
+ const name = shellName(opts.shell);
6
+ const executable = findShell(name);
7
+ if (!executable) {
8
+ const hint = process.platform === "win32" ? "install Git for Windows, or set JADE_SHELL to the path of a bash executable" : "set JADE_SHELL to the path of a shell";
9
+ const unavailable = `${name} was not found; ${hint}`;
24
10
  return {
25
- executable,
26
- run: (command, o) => capture(executable, env, command, o),
27
- which,
11
+ executable: undefined,
12
+ unavailable,
13
+ run: () => Promise.reject(new Error(unavailable)),
14
+ which
28
15
  };
16
+ }
17
+ const env = shellEnv(executable);
18
+ return {
19
+ executable,
20
+ run: (command, o) => capture(executable, env, command, o),
21
+ which
22
+ };
29
23
  }