@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,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
|
-
|
|
8
|
-
const sessions = new Map();
|
|
5
|
+
const sessions = new Map;
|
|
9
6
|
const firstLine = (command) => {
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
});
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
}
|