@zqagent/core 0.2.16 → 0.3.6

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 (238) hide show
  1. package/README.md +1 -1
  2. package/README.oss.en.md +15 -2
  3. package/README.oss.md +18 -2
  4. package/README.oss.zh-TW.md +13 -2
  5. package/dist/McpClient-CEQBUPuC.d.cts +145 -0
  6. package/dist/McpClient-CEQBUPuC.d.ts +145 -0
  7. package/dist/{ToolRegistry-C3pTFiaJ.d.cts → ToolRegistry-Cy0fQxrb.d.ts} +2 -111
  8. package/dist/{ToolRegistry-C3pTFiaJ.d.ts → ToolRegistry-DouDvn9E.d.cts} +2 -111
  9. package/dist/{explore-RtZtb-V6.d.ts → TurnEngine-BPKhWuSI.d.cts} +108 -73
  10. package/dist/{explore-BgRhj6SP.d.cts → TurnEngine-DtGEuVLT.d.ts} +108 -73
  11. package/dist/conflictGuard-BBOOIxxK.d.cts +42 -0
  12. package/dist/conflictGuard-BBOOIxxK.d.ts +42 -0
  13. package/dist/index.cjs +5477 -1140
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +577 -195
  16. package/dist/index.d.ts +577 -195
  17. package/dist/index.js +5305 -1002
  18. package/dist/index.js.map +1 -1
  19. package/dist/internal/crypto/secrets.cjs +25 -0
  20. package/dist/internal/crypto/secrets.cjs.map +1 -0
  21. package/dist/internal/crypto/secrets.d.cts +2 -0
  22. package/dist/internal/crypto/secrets.d.ts +2 -0
  23. package/dist/internal/crypto/secrets.js +3 -0
  24. package/dist/internal/crypto/secrets.js.map +1 -0
  25. package/dist/internal/engine/FileLogHook.cjs +179 -0
  26. package/dist/internal/engine/FileLogHook.cjs.map +1 -0
  27. package/dist/internal/engine/FileLogHook.d.cts +67 -0
  28. package/dist/internal/engine/FileLogHook.d.ts +67 -0
  29. package/dist/internal/engine/FileLogHook.js +144 -0
  30. package/dist/internal/engine/FileLogHook.js.map +1 -0
  31. package/dist/internal/engine/approvalView.cjs +25 -0
  32. package/dist/internal/engine/approvalView.cjs.map +1 -0
  33. package/dist/internal/engine/approvalView.d.cts +1 -0
  34. package/dist/internal/engine/approvalView.d.ts +1 -0
  35. package/dist/internal/engine/approvalView.js +3 -0
  36. package/dist/internal/engine/approvalView.js.map +1 -0
  37. package/dist/internal/engine/limits.cjs +59 -0
  38. package/dist/internal/engine/limits.cjs.map +1 -0
  39. package/dist/internal/engine/limits.d.cts +32 -0
  40. package/dist/internal/engine/limits.d.ts +32 -0
  41. package/dist/internal/engine/limits.js +31 -0
  42. package/dist/internal/engine/limits.js.map +1 -0
  43. package/dist/internal/engine/sessionNaming.cjs +47 -0
  44. package/dist/internal/engine/sessionNaming.cjs.map +1 -0
  45. package/dist/internal/engine/sessionNaming.d.cts +25 -0
  46. package/dist/internal/engine/sessionNaming.d.ts +25 -0
  47. package/dist/internal/engine/sessionNaming.js +20 -0
  48. package/dist/internal/engine/sessionNaming.js.map +1 -0
  49. package/dist/internal/llmConfig.cjs +561 -0
  50. package/dist/internal/llmConfig.cjs.map +1 -0
  51. package/dist/internal/llmConfig.d.cts +75 -0
  52. package/dist/internal/llmConfig.d.ts +75 -0
  53. package/dist/internal/llmConfig.js +535 -0
  54. package/dist/internal/llmConfig.js.map +1 -0
  55. package/dist/internal/mcp/builtin/index.cjs +685 -0
  56. package/dist/internal/mcp/builtin/index.cjs.map +1 -0
  57. package/dist/internal/mcp/builtin/index.d.cts +21 -0
  58. package/dist/internal/mcp/builtin/index.d.ts +21 -0
  59. package/dist/internal/mcp/builtin/index.js +652 -0
  60. package/dist/internal/mcp/builtin/index.js.map +1 -0
  61. package/dist/internal/mcp/config.cjs +278 -0
  62. package/dist/internal/mcp/config.cjs.map +1 -0
  63. package/dist/internal/mcp/config.d.cts +61 -0
  64. package/dist/internal/mcp/config.d.ts +61 -0
  65. package/dist/internal/mcp/config.js +235 -0
  66. package/dist/internal/mcp/config.js.map +1 -0
  67. package/dist/internal/mcp/presets.cjs +184 -0
  68. package/dist/internal/mcp/presets.cjs.map +1 -0
  69. package/dist/internal/mcp/presets.d.cts +39 -0
  70. package/dist/internal/mcp/presets.d.ts +39 -0
  71. package/dist/internal/mcp/presets.js +158 -0
  72. package/dist/internal/mcp/presets.js.map +1 -0
  73. package/dist/internal/node-name.cjs +45 -0
  74. package/dist/internal/node-name.cjs.map +1 -0
  75. package/dist/internal/node-name.d.cts +3 -0
  76. package/dist/internal/node-name.d.ts +3 -0
  77. package/dist/internal/node-name.js +10 -0
  78. package/dist/internal/node-name.js.map +1 -0
  79. package/dist/internal/paths.cjs +63 -0
  80. package/dist/internal/paths.cjs.map +1 -0
  81. package/dist/internal/paths.d.cts +17 -0
  82. package/dist/internal/paths.d.ts +17 -0
  83. package/dist/internal/paths.js +25 -0
  84. package/dist/internal/paths.js.map +1 -0
  85. package/dist/internal/providers/diagnostics.cjs +288 -0
  86. package/dist/internal/providers/diagnostics.cjs.map +1 -0
  87. package/dist/internal/providers/diagnostics.d.cts +103 -0
  88. package/dist/internal/providers/diagnostics.d.ts +103 -0
  89. package/dist/internal/providers/diagnostics.js +250 -0
  90. package/dist/internal/providers/diagnostics.js.map +1 -0
  91. package/dist/internal/providers/models.cjs +699 -0
  92. package/dist/internal/providers/models.cjs.map +1 -0
  93. package/dist/internal/providers/models.d.cts +136 -0
  94. package/dist/internal/providers/models.d.ts +136 -0
  95. package/dist/internal/providers/models.js +654 -0
  96. package/dist/internal/providers/models.js.map +1 -0
  97. package/dist/internal/terminal.cjs +161 -0
  98. package/dist/internal/terminal.cjs.map +1 -0
  99. package/dist/internal/terminal.d.cts +58 -0
  100. package/dist/internal/terminal.d.ts +58 -0
  101. package/dist/internal/terminal.js +128 -0
  102. package/dist/internal/terminal.js.map +1 -0
  103. package/dist/internal/tools/execAsync.cjs +187 -0
  104. package/dist/internal/tools/execAsync.cjs.map +1 -0
  105. package/dist/internal/tools/execAsync.d.cts +30 -0
  106. package/dist/internal/tools/execAsync.d.ts +30 -0
  107. package/dist/internal/tools/execAsync.js +162 -0
  108. package/dist/internal/tools/execAsync.js.map +1 -0
  109. package/dist/internal/tools/git.cjs +935 -0
  110. package/dist/internal/tools/git.cjs.map +1 -0
  111. package/dist/internal/tools/git.d.cts +206 -0
  112. package/dist/internal/tools/git.d.ts +206 -0
  113. package/dist/internal/tools/git.js +883 -0
  114. package/dist/internal/tools/git.js.map +1 -0
  115. package/dist/internal/tools/pathSafety.cjs +99 -0
  116. package/dist/internal/tools/pathSafety.cjs.map +1 -0
  117. package/dist/internal/tools/pathSafety.d.cts +44 -0
  118. package/dist/internal/tools/pathSafety.d.ts +44 -0
  119. package/dist/internal/tools/pathSafety.js +61 -0
  120. package/dist/internal/tools/pathSafety.js.map +1 -0
  121. package/dist/internal/tools/plan.cjs +146 -0
  122. package/dist/internal/tools/plan.cjs.map +1 -0
  123. package/dist/internal/tools/plan.d.cts +48 -0
  124. package/dist/internal/tools/plan.d.ts +48 -0
  125. package/dist/internal/tools/plan.js +117 -0
  126. package/dist/internal/tools/plan.js.map +1 -0
  127. package/dist/internal/tools/ripgrep.cjs +118 -0
  128. package/dist/internal/tools/ripgrep.cjs.map +1 -0
  129. package/dist/internal/tools/ripgrep.d.cts +6 -0
  130. package/dist/internal/tools/ripgrep.d.ts +6 -0
  131. package/dist/internal/tools/ripgrep.js +89 -0
  132. package/dist/internal/tools/ripgrep.js.map +1 -0
  133. package/dist/internal/tools/sandbox.cjs +253 -0
  134. package/dist/internal/tools/sandbox.cjs.map +1 -0
  135. package/dist/internal/tools/sandbox.d.cts +67 -0
  136. package/dist/internal/tools/sandbox.d.ts +67 -0
  137. package/dist/internal/tools/sandbox.js +213 -0
  138. package/dist/internal/tools/sandbox.js.map +1 -0
  139. package/dist/internal/tools/shell.cjs +771 -0
  140. package/dist/internal/tools/shell.cjs.map +1 -0
  141. package/dist/internal/tools/shell.d.cts +47 -0
  142. package/dist/internal/tools/shell.d.ts +47 -0
  143. package/dist/internal/tools/shell.js +731 -0
  144. package/dist/internal/tools/shell.js.map +1 -0
  145. package/dist/internal/tools/shellRuntime.cjs +220 -0
  146. package/dist/internal/tools/shellRuntime.cjs.map +1 -0
  147. package/dist/internal/tools/shellRuntime.d.cts +67 -0
  148. package/dist/internal/tools/shellRuntime.d.ts +67 -0
  149. package/dist/internal/tools/shellRuntime.js +181 -0
  150. package/dist/internal/tools/shellRuntime.js.map +1 -0
  151. package/dist/internal/update/controller.cjs +1035 -0
  152. package/dist/internal/update/controller.cjs.map +1 -0
  153. package/dist/internal/update/controller.d.cts +150 -0
  154. package/dist/internal/update/controller.d.ts +150 -0
  155. package/dist/internal/update/controller.js +991 -0
  156. package/dist/internal/update/controller.js.map +1 -0
  157. package/dist/internal/update/platform.cjs +234 -0
  158. package/dist/internal/update/platform.cjs.map +1 -0
  159. package/dist/internal/update/platform.d.cts +77 -0
  160. package/dist/internal/update/platform.d.ts +77 -0
  161. package/dist/internal/update/platform.js +184 -0
  162. package/dist/internal/update/platform.js.map +1 -0
  163. package/dist/tools/ask.d.cts +3 -1
  164. package/dist/tools/ask.d.ts +3 -1
  165. package/dist/tools/diff.cjs +17 -6
  166. package/dist/tools/diff.cjs.map +1 -1
  167. package/dist/tools/diff.d.cts +5 -2
  168. package/dist/tools/diff.d.ts +5 -2
  169. package/dist/tools/diff.js +17 -6
  170. package/dist/tools/diff.js.map +1 -1
  171. package/dist/tools/directories.d.cts +3 -1
  172. package/dist/tools/directories.d.ts +3 -1
  173. package/dist/tools/explore.cjs +1778 -204
  174. package/dist/tools/explore.cjs.map +1 -1
  175. package/dist/tools/explore.d.cts +82 -2
  176. package/dist/tools/explore.d.ts +82 -2
  177. package/dist/tools/explore.js +1780 -204
  178. package/dist/tools/explore.js.map +1 -1
  179. package/dist/tools/files.cjs +56 -21
  180. package/dist/tools/files.cjs.map +1 -1
  181. package/dist/tools/files.d.cts +6 -3
  182. package/dist/tools/files.d.ts +6 -3
  183. package/dist/tools/files.js +56 -21
  184. package/dist/tools/files.js.map +1 -1
  185. package/dist/tools/git.cjs +34 -25
  186. package/dist/tools/git.cjs.map +1 -1
  187. package/dist/tools/git.d.cts +4 -204
  188. package/dist/tools/git.d.ts +4 -204
  189. package/dist/tools/git.js +34 -25
  190. package/dist/tools/git.js.map +1 -1
  191. package/dist/tools/media.cjs +280 -3
  192. package/dist/tools/media.cjs.map +1 -1
  193. package/dist/tools/media.d.cts +3 -1
  194. package/dist/tools/media.d.ts +3 -1
  195. package/dist/tools/media.js +278 -1
  196. package/dist/tools/media.js.map +1 -1
  197. package/dist/tools/plan.cjs +62 -0
  198. package/dist/tools/plan.cjs.map +1 -1
  199. package/dist/tools/plan.d.cts +4 -17
  200. package/dist/tools/plan.d.ts +4 -17
  201. package/dist/tools/plan.js +59 -0
  202. package/dist/tools/plan.js.map +1 -1
  203. package/dist/tools/search.cjs +3 -0
  204. package/dist/tools/search.cjs.map +1 -1
  205. package/dist/tools/search.d.cts +3 -1
  206. package/dist/tools/search.d.ts +3 -1
  207. package/dist/tools/search.js +3 -0
  208. package/dist/tools/search.js.map +1 -1
  209. package/dist/tools/shell.cjs +76 -11
  210. package/dist/tools/shell.cjs.map +1 -1
  211. package/dist/tools/shell.d.cts +5 -39
  212. package/dist/tools/shell.d.ts +5 -39
  213. package/dist/tools/shell.js +75 -11
  214. package/dist/tools/shell.js.map +1 -1
  215. package/dist/tools/todo.d.cts +3 -1
  216. package/dist/tools/todo.d.ts +3 -1
  217. package/dist/tools/web.cjs +279 -5
  218. package/dist/tools/web.cjs.map +1 -1
  219. package/dist/tools/web.d.cts +3 -1
  220. package/dist/tools/web.d.ts +3 -1
  221. package/dist/tools/web.js +275 -3
  222. package/dist/tools/web.js.map +1 -1
  223. package/dist/types-BYyXWWPW.d.cts +237 -0
  224. package/dist/types-BYyXWWPW.d.ts +237 -0
  225. package/package.json +26 -37
  226. package/bin/zqagent +0 -2
  227. package/dist/cli/index.cjs +0 -24507
  228. package/dist/cli/index.cjs.map +0 -1
  229. package/dist/cli/index.d.cts +0 -2
  230. package/dist/cli/index.d.ts +0 -2
  231. package/dist/cli/index.js +0 -24490
  232. package/dist/cli/index.js.map +0 -1
  233. package/dist/server/index.cjs +0 -19824
  234. package/dist/server/index.cjs.map +0 -1
  235. package/dist/server/index.d.cts +0 -2
  236. package/dist/server/index.d.ts +0 -2
  237. package/dist/server/index.js +0 -19807
  238. package/dist/server/index.js.map +0 -1
@@ -0,0 +1,771 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/tools/shell.ts
31
+ var shell_exports = {};
32
+ __export(shell_exports, {
33
+ decodeOutput: () => decodeOutput,
34
+ getShellCwd: () => getShellCwd,
35
+ killShellTask: () => killShellTask,
36
+ listShellTasks: () => listShellTasks,
37
+ registerShellTool: () => registerShellTool,
38
+ resetShellSession: () => resetShellSession
39
+ });
40
+ module.exports = __toCommonJS(shell_exports);
41
+ var fs2 = __toESM(require("fs"), 1);
42
+ var path2 = __toESM(require("path"), 1);
43
+
44
+ // src/tools/execAsync.ts
45
+ var import_node_child_process2 = require("child_process");
46
+
47
+ // src/tools/killTree.ts
48
+ var import_node_child_process = require("child_process");
49
+ function killTree(pid) {
50
+ if (!pid) return;
51
+ if (process.platform === "win32") {
52
+ try {
53
+ (0, import_node_child_process.spawnSync)("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true });
54
+ } catch {
55
+ }
56
+ return;
57
+ }
58
+ try {
59
+ process.kill(-pid, "SIGKILL");
60
+ } catch {
61
+ try {
62
+ process.kill(pid, "SIGKILL");
63
+ } catch {
64
+ }
65
+ }
66
+ }
67
+
68
+ // src/tools/execAsync.ts
69
+ var liveChildren = /* @__PURE__ */ new Set();
70
+ var exitCleanupInstalled = false;
71
+ function trackChild(pid) {
72
+ if (!pid) return;
73
+ liveChildren.add(pid);
74
+ if (exitCleanupInstalled) return;
75
+ exitCleanupInstalled = true;
76
+ process.once("exit", () => {
77
+ for (const p of liveChildren) killTree(p);
78
+ });
79
+ }
80
+ var DEFAULT_MAX_BUFFER = 1024 * 1024 * 5;
81
+ var KILL_GRACE_MS = 1e3;
82
+ function makeSink(maxBuffer) {
83
+ const chunks = [];
84
+ let len = 0;
85
+ let over = false;
86
+ return {
87
+ push(chunk) {
88
+ if (len >= maxBuffer) {
89
+ over = true;
90
+ return;
91
+ }
92
+ const room = maxBuffer - len;
93
+ if (chunk.length > room) {
94
+ chunks.push(chunk.subarray(0, room));
95
+ len = maxBuffer;
96
+ over = true;
97
+ return;
98
+ }
99
+ chunks.push(chunk);
100
+ len += chunk.length;
101
+ },
102
+ done: () => Buffer.concat(chunks),
103
+ over: () => over
104
+ };
105
+ }
106
+ function execAsync(file, argv, opts = {}) {
107
+ return new Promise((resolve2) => {
108
+ const maxBuffer = opts.maxBuffer ?? DEFAULT_MAX_BUFFER;
109
+ const out = makeSink(maxBuffer);
110
+ const err = makeSink(maxBuffer);
111
+ if (opts.signal?.aborted) {
112
+ resolve2({
113
+ status: null,
114
+ stdout: Buffer.alloc(0),
115
+ stderr: Buffer.alloc(0),
116
+ timedOut: false,
117
+ truncated: false,
118
+ aborted: true
119
+ });
120
+ return;
121
+ }
122
+ let child;
123
+ try {
124
+ child = (0, import_node_child_process2.spawn)(file, argv, {
125
+ ...opts.cwd !== void 0 ? { cwd: opts.cwd } : {},
126
+ ...opts.env !== void 0 ? { env: opts.env } : {},
127
+ // 自成进程组(POSIX):超时/中断时用 killTree 一次收掉整棵进程树
128
+ detached: process.platform !== "win32",
129
+ stdio: [opts.input === void 0 ? "ignore" : "pipe", "pipe", "pipe"],
130
+ windowsHide: true
131
+ });
132
+ } catch (e) {
133
+ resolve2({
134
+ status: null,
135
+ stdout: Buffer.alloc(0),
136
+ stderr: Buffer.alloc(0),
137
+ error: e,
138
+ timedOut: false,
139
+ truncated: false
140
+ });
141
+ return;
142
+ }
143
+ trackChild(child.pid);
144
+ let settled = false;
145
+ let timedOut = false;
146
+ let aborted = false;
147
+ let spawnError;
148
+ let timer = null;
149
+ let graceTimer = null;
150
+ const onAbort = () => {
151
+ aborted = true;
152
+ killAndSettle();
153
+ };
154
+ const finish = (status) => {
155
+ if (settled) return;
156
+ settled = true;
157
+ if (timer) clearTimeout(timer);
158
+ if (graceTimer) clearTimeout(graceTimer);
159
+ if (child.pid !== void 0) liveChildren.delete(child.pid);
160
+ opts.signal?.removeEventListener("abort", onAbort);
161
+ const result = {
162
+ status,
163
+ stdout: out.done(),
164
+ stderr: err.done(),
165
+ timedOut,
166
+ truncated: out.over() || err.over()
167
+ };
168
+ if (aborted) result.aborted = true;
169
+ if (spawnError) result.error = spawnError;
170
+ resolve2(result);
171
+ };
172
+ const killAndSettle = () => {
173
+ killTree(child.pid);
174
+ if (settled || graceTimer) return;
175
+ graceTimer = setTimeout(() => {
176
+ child.stdout?.destroy();
177
+ child.stderr?.destroy();
178
+ finish(null);
179
+ }, KILL_GRACE_MS);
180
+ };
181
+ if (opts.timeoutMs !== void 0 && opts.timeoutMs > 0) {
182
+ timer = setTimeout(() => {
183
+ timedOut = true;
184
+ killAndSettle();
185
+ }, opts.timeoutMs);
186
+ }
187
+ opts.signal?.addEventListener("abort", onAbort, { once: true });
188
+ child.stdout?.on("data", (c) => out.push(c));
189
+ child.stderr?.on("data", (c) => err.push(c));
190
+ child.on("error", (e) => {
191
+ spawnError = e;
192
+ if (child.pid === void 0) finish(null);
193
+ });
194
+ if (opts.input !== void 0 && child.stdin) {
195
+ child.stdin.on("error", () => {
196
+ });
197
+ child.stdin.end(opts.input);
198
+ }
199
+ child.on("close", (code) => finish(code));
200
+ });
201
+ }
202
+
203
+ // src/tools/shellRuntime.ts
204
+ var fs = __toESM(require("fs"), 1);
205
+ var path = __toESM(require("path"), 1);
206
+ var WINDOWS_SUFFIXES = [".exe", ".cmd", ".bat", ".com", ""];
207
+ function pathApi(platform) {
208
+ return platform === "win32" ? path.win32 : path.posix;
209
+ }
210
+ function defaultFileExists(p) {
211
+ try {
212
+ return fs.statSync(p).isFile();
213
+ } catch {
214
+ return false;
215
+ }
216
+ }
217
+ function joinPath(platform, ...parts) {
218
+ return pathApi(platform).join(...parts);
219
+ }
220
+ function findExecutable(name, ctx) {
221
+ if (name.includes("/") || name.includes("\\")) {
222
+ return ctx.fileExists(name) ? name : null;
223
+ }
224
+ const suffixes = ctx.platform === "win32" ? WINDOWS_SUFFIXES : [""];
225
+ const delimiter = ctx.platform === "win32" ? ";" : ":";
226
+ const dirs = (ctx.env.PATH ?? "").split(delimiter).filter((d) => d.length > 0);
227
+ for (const dir of dirs) {
228
+ for (const suffix of suffixes) {
229
+ const candidate = joinPath(ctx.platform, dir, name + suffix);
230
+ if (ctx.fileExists(candidate)) return candidate;
231
+ }
232
+ }
233
+ return null;
234
+ }
235
+ function kindFromBasename(base) {
236
+ const b = base.toLowerCase().replace(/\.(exe|cmd|bat|com)$/, "");
237
+ if (b === "busybox") return "busybox";
238
+ if (b === "powershell" || b === "pwsh") return "powershell";
239
+ if (b === "cmd") return "cmd";
240
+ return "sh";
241
+ }
242
+ function busyboxArgs(file, command) {
243
+ const base = (file ? path.win32.basename(file) : "busybox").toLowerCase().replace(/\.(exe|cmd|bat|com)$/, "");
244
+ return base === "busybox" ? ["sh", "-c", command] : ["-c", command];
245
+ }
246
+ function argsFor(kind, command) {
247
+ switch (kind) {
248
+ case "busybox":
249
+ return ["sh", "-c", command];
250
+ case "powershell":
251
+ return ["-NoProfile", "-NonInteractive", "-Command", command];
252
+ case "cmd":
253
+ return ["/d", "/s", "/c", command];
254
+ default:
255
+ return ["-c", command];
256
+ }
257
+ }
258
+ function makeSpec(kind, file, label) {
259
+ return {
260
+ kind,
261
+ file,
262
+ label,
263
+ buildArgs: (command) => kind === "busybox" ? busyboxArgs(file, command) : argsFor(kind, command)
264
+ };
265
+ }
266
+ function defaultLabelFor(kind) {
267
+ switch (kind) {
268
+ case "busybox":
269
+ return "busybox ash";
270
+ case "powershell":
271
+ return "PowerShell";
272
+ case "cmd":
273
+ return "cmd.exe";
274
+ case "default":
275
+ return "\u7CFB\u7EDF\u9ED8\u8BA4 shell";
276
+ default:
277
+ return "sh";
278
+ }
279
+ }
280
+ function findBusybox(ctx, execPath) {
281
+ const explicit = (ctx.env.ZQAGENT_BUSYBOX ?? "").trim();
282
+ if (explicit) return ctx.fileExists(explicit) ? explicit : null;
283
+ const exeDir = pathApi(ctx.platform).dirname(execPath);
284
+ const candidates = [
285
+ joinPath(ctx.platform, exeDir, "busybox.exe"),
286
+ joinPath(ctx.platform, exeDir, "sh.exe"),
287
+ joinPath(ctx.platform, exeDir, "bin", "busybox.exe"),
288
+ joinPath(ctx.platform, exeDir, "bin", "sh.exe")
289
+ ];
290
+ for (const candidate of candidates) {
291
+ if (ctx.fileExists(candidate)) return candidate;
292
+ }
293
+ return null;
294
+ }
295
+ function resolveRequested(requested, ctx, execPath) {
296
+ const lower = requested.toLowerCase();
297
+ if (lower === "cmd") {
298
+ const file = findExecutable("cmd", ctx) ?? ctx.env.ComSpec ?? ctx.env.COMSPEC ?? "cmd.exe";
299
+ return makeSpec("cmd", file, "cmd.exe");
300
+ }
301
+ if (lower === "powershell" || lower === "pwsh") {
302
+ const file = findExecutable(lower, ctx) ?? findExecutable("powershell", ctx) ?? `${lower}.exe`;
303
+ return makeSpec("powershell", file, "PowerShell");
304
+ }
305
+ if (lower === "busybox") {
306
+ const found = findBusybox(ctx, execPath) ?? findExecutable("busybox", ctx);
307
+ return makeSpec("busybox", found ?? requested, "busybox ash");
308
+ }
309
+ if (["sh", "bash", "dash", "zsh", "ash"].includes(lower)) {
310
+ return makeSpec("sh", findExecutable(lower, ctx) ?? lower, lower);
311
+ }
312
+ const base = pathApi(ctx.platform).basename(requested);
313
+ const kind = kindFromBasename(base);
314
+ return makeSpec(kind, requested, base || defaultLabelFor(kind));
315
+ }
316
+ function resolveShellSpec(opts = {}) {
317
+ const platform = opts.platform ?? process.platform;
318
+ const env = opts.env ?? process.env;
319
+ const execPath = opts.execPath ?? process.execPath;
320
+ const ctx = {
321
+ platform,
322
+ env,
323
+ fileExists: opts.fileExists ?? defaultFileExists
324
+ };
325
+ const requested = (env.ZQAGENT_SHELL ?? "").trim();
326
+ if (requested && requested.toLowerCase() !== "auto") {
327
+ return resolveRequested(requested, ctx, execPath);
328
+ }
329
+ if (platform !== "win32") {
330
+ return makeSpec("default", null, "/bin/sh");
331
+ }
332
+ const busybox = findBusybox(ctx, execPath);
333
+ if (busybox) return makeSpec("busybox", busybox, "busybox ash (POSIX)");
334
+ const bash = findExecutable("bash", ctx);
335
+ if (bash) return makeSpec("sh", bash, "bash (Git for Windows)");
336
+ const shell = findExecutable("pwsh", ctx) ?? findExecutable("powershell", ctx);
337
+ if (shell) return makeSpec("powershell", shell, "PowerShell");
338
+ return makeSpec("default", null, env.ComSpec ?? env.COMSPEC ?? "cmd.exe");
339
+ }
340
+ function wrapCommand(kind, command, platform = process.platform) {
341
+ if (kind === "powershell") {
342
+ return "$OutputEncoding = [Console]::OutputEncoding = [Text.Encoding]::UTF8; " + command + "\nif ($null -ne $LASTEXITCODE) { exit $LASTEXITCODE }";
343
+ }
344
+ if (kind === "cmd" || kind === "default" && platform === "win32") {
345
+ return `chcp 65001>nul & ${command}`;
346
+ }
347
+ return command;
348
+ }
349
+ function describeShell(spec, platform) {
350
+ if (spec.kind === "sh" || spec.kind === "busybox") {
351
+ return `\u5F53\u524D\u5E73\u53F0 ${platform}\uFF0Cshell=${spec.label}\uFF1A\u8BF7\u4F7F\u7528 POSIX \u98CE\u683C\u547D\u4EE4\u3002`;
352
+ }
353
+ if (spec.kind === "powershell") {
354
+ return `\u5F53\u524D\u5E73\u53F0 ${platform}\uFF0Cshell=PowerShell\uFF1Als/cat/rm/cp/mv/pwd \u7B49\u522B\u540D\u53EF\u7528\uFF0C\u4E5F\u53EF\u7528 cmdlet\uFF1B\u8DEF\u5F84\u5206\u9694\u7B26\u4E3A "\\"\u3002`;
355
+ }
356
+ if (spec.kind === "default" && platform !== "win32") {
357
+ return `\u5F53\u524D\u5E73\u53F0 ${platform}\uFF0Cshell=${spec.label}\uFF1A\u8BF7\u4F7F\u7528 POSIX \u98CE\u683C\u547D\u4EE4\u3002`;
358
+ }
359
+ return `\u5F53\u524D\u5E73\u53F0 ${platform}\uFF0Cshell=${spec.label}\uFF1A\u8BF7\u4F7F\u7528 Windows \u547D\u4EE4\uFF08dir/type/del/copy/move/findstr\uFF09\uFF0C\u591A\u6761\u547D\u4EE4\u7528 & \u6216 && \u8FDE\u63A5\uFF1B\u4E0D\u8981\u4F7F\u7528 ls/cat/rm/grep \u7B49 POSIX \u547D\u4EE4\u3002`;
360
+ }
361
+ function parseCdChain(command, opts = {}) {
362
+ const platform = opts.platform ?? process.platform;
363
+ const trimmed = command.trim();
364
+ const chain = /^([\s\S]*?)\s*&&\s*([\s\S]+)$/.exec(trimmed);
365
+ const head = (chain ? chain[1] : trimmed).trim();
366
+ const rest = chain ? chain[2].trim() : null;
367
+ const m = /^(?:cd|set-location|sl|pushd|push-location)\b\s*([\s\S]*)$/i.exec(head);
368
+ if (!m) return { target: null, rest: null };
369
+ let target = m[1].trim();
370
+ target = target.replace(/^-(?:path|literalpath)\s+/i, "");
371
+ if (platform === "win32") target = target.replace(/^\/d\s+/i, "");
372
+ target = target.replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1").trim();
373
+ if (!target || target === "-") return { target: null, rest: null };
374
+ return { target, rest };
375
+ }
376
+
377
+ // src/tools/shellBackground.ts
378
+ var import_node_child_process3 = require("child_process");
379
+ var DEFAULT_BUFFER_LIMIT = 64 * 1024;
380
+ var RingBuffer = class {
381
+ constructor(limit = DEFAULT_BUFFER_LIMIT) {
382
+ this.limit = limit;
383
+ }
384
+ limit;
385
+ chunks = [];
386
+ size = 0;
387
+ add(chunk) {
388
+ if (!chunk) return;
389
+ this.chunks.push(chunk);
390
+ this.size += chunk.length;
391
+ while (this.size > this.limit && this.chunks.length > 1) {
392
+ this.size -= this.chunks.shift().length;
393
+ }
394
+ if (this.size > this.limit) {
395
+ const joined = this.chunks.join("");
396
+ this.chunks = [joined.slice(-this.limit)];
397
+ this.size = this.chunks[0].length;
398
+ }
399
+ }
400
+ get() {
401
+ const joined = this.chunks.join("");
402
+ return joined.length > this.limit ? joined.slice(-this.limit) : joined;
403
+ }
404
+ };
405
+ var ShellTaskManager = class {
406
+ tasks = /* @__PURE__ */ new Map();
407
+ seq = 0;
408
+ cleanupInstalled = false;
409
+ /** 启动一个后台任务,立即返回快照(不等退出) */
410
+ start(opts) {
411
+ this.installCleanup();
412
+ const id = `shell-${++this.seq}-${Date.now().toString(36)}`;
413
+ const child = (0, import_node_child_process3.spawn)(opts.file, opts.argv, {
414
+ cwd: opts.cwd,
415
+ env: opts.env,
416
+ detached: process.platform !== "win32",
417
+ windowsHide: true,
418
+ stdio: ["ignore", "pipe", "pipe"]
419
+ });
420
+ const task = {
421
+ id,
422
+ command: opts.command,
423
+ scope: opts.scope ?? null,
424
+ child,
425
+ stdout: new RingBuffer(),
426
+ stderr: new RingBuffer(),
427
+ status: "running",
428
+ exitCode: null,
429
+ signal: null,
430
+ startedAt: Date.now(),
431
+ endedAt: null
432
+ };
433
+ this.tasks.set(id, task);
434
+ child.stdout?.on("data", (d) => task.stdout.add(d.toString("utf-8")));
435
+ child.stderr?.on("data", (d) => task.stderr.add(d.toString("utf-8")));
436
+ child.on("error", (err) => task.stderr.add(`[spawn error] ${err.message}
437
+ `));
438
+ child.on("exit", (code, signal) => {
439
+ task.exitCode = code;
440
+ task.signal = signal;
441
+ task.endedAt = Date.now();
442
+ if (task.status !== "killed") task.status = "exited";
443
+ });
444
+ child.unref();
445
+ return this.snapshot(task);
446
+ }
447
+ /** 读取任务输出与状态 */
448
+ output(taskId) {
449
+ const task = this.tasks.get(taskId);
450
+ if (!task) return { error: `\u672A\u77E5\u7684\u540E\u53F0\u4EFB\u52A1: ${taskId}` };
451
+ return this.snapshot(task);
452
+ }
453
+ /** 终止任务(进程树)并返回快照;传 scope 时只允许终止该归属下的任务 */
454
+ kill(taskId, scope) {
455
+ const task = this.tasks.get(taskId);
456
+ if (!task) return { error: `\u672A\u77E5\u7684\u540E\u53F0\u4EFB\u52A1: ${taskId}` };
457
+ if (scope !== void 0 && task.scope !== scope) {
458
+ return { error: `\u672A\u77E5\u7684\u540E\u53F0\u4EFB\u52A1: ${taskId}` };
459
+ }
460
+ if (task.status === "running") {
461
+ task.status = "killed";
462
+ task.endedAt = Date.now();
463
+ killTree(task.child.pid);
464
+ }
465
+ return this.snapshot(task);
466
+ }
467
+ /** 列出任务快照(调试/展示用);传 scope 时只返回该归属下的任务 */
468
+ list(scope) {
469
+ const all = [...this.tasks.values()];
470
+ return (scope === void 0 ? all : all.filter((t) => t.scope === scope)).map(
471
+ (t) => this.snapshot(t)
472
+ );
473
+ }
474
+ /** 终止全部任务(进程退出时调用) */
475
+ disposeAll() {
476
+ for (const task of this.tasks.values()) {
477
+ if (task.status === "running") {
478
+ task.status = "killed";
479
+ killTree(task.child.pid);
480
+ }
481
+ }
482
+ }
483
+ snapshot(task) {
484
+ return {
485
+ task_id: task.id,
486
+ command: task.command,
487
+ status: task.status,
488
+ running: task.status === "running",
489
+ exit_code: task.exitCode,
490
+ signal: task.signal,
491
+ stdout: task.stdout.get(),
492
+ stderr: task.stderr.get(),
493
+ duration_ms: (task.endedAt ?? Date.now()) - task.startedAt
494
+ };
495
+ }
496
+ installCleanup() {
497
+ if (this.cleanupInstalled) return;
498
+ this.cleanupInstalled = true;
499
+ process.once("exit", () => this.disposeAll());
500
+ }
501
+ };
502
+
503
+ // src/tools/sandbox.ts
504
+ var import_node_child_process4 = require("child_process");
505
+ function sbplString(value) {
506
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
507
+ }
508
+ function buildMacProfile(writable) {
509
+ const rules = writable.map((p) => ` (subpath ${sbplString(p)})`).join("\n");
510
+ return [
511
+ "(version 1)",
512
+ "(allow default)",
513
+ "(deny file-write*)",
514
+ "(allow file-write*",
515
+ rules,
516
+ ")"
517
+ ].join("\n");
518
+ }
519
+ function buildBwrapArgs(writable, cwd) {
520
+ const args = ["--ro-bind", "/", "/", "--dev-bind", "/dev", "/dev"];
521
+ if (!writable.includes("/tmp")) args.push("--tmpfs", "/tmp");
522
+ for (const dir of writable) {
523
+ if (dir === "/dev" || dir === "/proc") continue;
524
+ args.push("--bind", dir, dir);
525
+ }
526
+ args.push("--chdir", cwd, "--die-with-parent");
527
+ return args;
528
+ }
529
+ function wrapWithSandbox(plan, invocation, ctx) {
530
+ if (!plan || !plan.enforced || !plan.bin) return invocation;
531
+ if (plan.backend === "sandbox-exec") {
532
+ return {
533
+ file: plan.bin,
534
+ argv: ["-p", buildMacProfile(plan.writable), invocation.file, ...invocation.argv]
535
+ };
536
+ }
537
+ return {
538
+ file: plan.bin,
539
+ argv: [...buildBwrapArgs(plan.writable, ctx.cwd), "--", invocation.file, ...invocation.argv]
540
+ };
541
+ }
542
+ function describeSandbox(plan) {
543
+ if (!plan) return "\u672A\u914D\u7F6E";
544
+ return plan.enforced ? plan.reason : `\u672A\u542F\u7528\uFF08${plan.reason}\uFF09`;
545
+ }
546
+
547
+ // src/tools/shell.ts
548
+ var MAX_STDOUT = 1e4;
549
+ var MAX_STDERR = 5e3;
550
+ var MAX_BUFFER = 1024 * 1024 * 5;
551
+ var shellSessions = /* @__PURE__ */ new Map();
552
+ function shellKey(workspace, owner) {
553
+ const root = path2.resolve(workspace);
554
+ const o = String(owner ?? "").trim();
555
+ return o ? `${root}\0${o}` : root;
556
+ }
557
+ function sessionFor(workspace, owner) {
558
+ const key = shellKey(workspace, owner);
559
+ let s = shellSessions.get(key);
560
+ if (!s) {
561
+ s = { cwd: path2.resolve(workspace) };
562
+ shellSessions.set(key, s);
563
+ }
564
+ return s;
565
+ }
566
+ function resetShellSession(workspace, owner) {
567
+ shellSessions.delete(shellKey(workspace, owner));
568
+ }
569
+ function getShellCwd(workspace, owner) {
570
+ return sessionFor(workspace, owner).cwd;
571
+ }
572
+ function resolveInvocation(spec, prepared) {
573
+ if (spec.file !== null) {
574
+ return { file: spec.file, argv: spec.buildArgs(prepared) };
575
+ }
576
+ if (process.platform === "win32") {
577
+ const comspec = process.env.ComSpec ?? process.env.COMSPEC ?? "cmd.exe";
578
+ return { file: comspec, argv: ["/d", "/s", "/c", prepared] };
579
+ }
580
+ return { file: "/bin/sh", argv: ["-c", prepared] };
581
+ }
582
+ function shellEnv() {
583
+ return {
584
+ ...process.env,
585
+ GIT_TERMINAL_PROMPT: "0",
586
+ PYTHONUNBUFFERED: "1",
587
+ PYTHONUTF8: "1",
588
+ PYTHONIOENCODING: "utf-8"
589
+ };
590
+ }
591
+ function decodeOutput(buf) {
592
+ if (!buf || buf.length === 0) return "";
593
+ try {
594
+ return new TextDecoder("utf-8", { fatal: true }).decode(buf);
595
+ } catch {
596
+ for (const enc of ["gbk", "big5", "shift_jis", "latin1"]) {
597
+ try {
598
+ return new TextDecoder(enc).decode(buf);
599
+ } catch {
600
+ }
601
+ }
602
+ return buf.toString("latin1");
603
+ }
604
+ }
605
+ function makeRunShell(workspace, spec, tasks, scope, sandbox, sessionKey) {
606
+ const session = sessionFor(workspace, sessionKey);
607
+ return async function run_shell(args, ctx) {
608
+ const command = String(args.command ?? "");
609
+ const description = String(args.description ?? "").slice(0, 100);
610
+ const background = args.run_in_background === true;
611
+ const rawTimeout = Number(args.timeout_seconds ?? 120);
612
+ const timeoutSec = Number.isFinite(rawTimeout) ? rawTimeout : 120;
613
+ const timeout = Math.min(Math.max(timeoutSec, 1), 600) * 1e3;
614
+ if (!command.trim()) {
615
+ return { error: "\u547D\u4EE4\u4E0D\u80FD\u4E3A\u7A7A" };
616
+ }
617
+ const { target, rest } = parseCdChain(command);
618
+ let toRun = command;
619
+ if (target) {
620
+ try {
621
+ const resolved = path2.resolve(session.cwd, target);
622
+ if (fs2.existsSync(resolved) && fs2.statSync(resolved).isDirectory()) {
623
+ session.cwd = resolved;
624
+ }
625
+ } catch {
626
+ }
627
+ if (rest) toRun = rest;
628
+ }
629
+ const prepared = wrapCommand(spec.kind, toRun);
630
+ const { file, argv } = wrapWithSandbox(
631
+ sandbox,
632
+ resolveInvocation(spec, prepared),
633
+ { cwd: session.cwd }
634
+ );
635
+ const env = shellEnv();
636
+ if (background) {
637
+ const snap = tasks.start({ command, file, argv, cwd: session.cwd, env, scope });
638
+ return {
639
+ task_id: snap.task_id,
640
+ status: snap.status,
641
+ cwd: session.cwd,
642
+ note: "\u5DF2\u5728\u540E\u53F0\u542F\u52A8\u3002\u7528 shell_task_output \u67E5\u770B\u8F93\u51FA\uFF0Cshell_task_kill \u7EC8\u6B62\u3002"
643
+ };
644
+ }
645
+ const result = await execAsync(file, argv, {
646
+ cwd: session.cwd,
647
+ timeoutMs: timeout,
648
+ maxBuffer: MAX_BUFFER,
649
+ env,
650
+ signal: ctx?.signal
651
+ });
652
+ const stdout = decodeOutput(result.stdout).slice(-MAX_STDOUT);
653
+ const stderr = decodeOutput(result.stderr).slice(-MAX_STDERR);
654
+ if (result.aborted) {
655
+ return {
656
+ stdout,
657
+ stderr,
658
+ exit_code: result.status ?? 1,
659
+ cwd: session.cwd,
660
+ interrupted: true,
661
+ error: "\u547D\u4EE4\u5DF2\u88AB\u7528\u6237\u4E2D\u65AD"
662
+ };
663
+ }
664
+ if (result.error && !result.timedOut) {
665
+ const message = result.error.message;
666
+ return {
667
+ stdout,
668
+ stderr: stderr || message,
669
+ exit_code: 1,
670
+ cwd: session.cwd,
671
+ error: message.slice(0, 200)
672
+ };
673
+ }
674
+ return {
675
+ stdout,
676
+ stderr,
677
+ exit_code: result.status ?? 1,
678
+ cwd: session.cwd,
679
+ ...result.timedOut ? { timed_out: true, error: `\u547D\u4EE4\u8D85\u65F6\uFF08${timeoutSec}s\uFF09\u540E\u5DF2\u7EC8\u6B62` } : {}
680
+ };
681
+ };
682
+ }
683
+ var shellTasks = new ShellTaskManager();
684
+ function listShellTasks(scope) {
685
+ return shellTasks.list(scope);
686
+ }
687
+ function killShellTask(taskId, scope) {
688
+ return shellTasks.kill(taskId, scope);
689
+ }
690
+ function registerShellTool(registry, workspace, scope, sandbox, sessionKey) {
691
+ const spec = resolveShellSpec();
692
+ const tasks = shellTasks;
693
+ const shell = makeRunShell(
694
+ workspace,
695
+ spec,
696
+ tasks,
697
+ scope ?? null,
698
+ sandbox ?? null,
699
+ sessionKey ?? null
700
+ );
701
+ registry.register(
702
+ (args, ctx) => shell(args, ctx),
703
+ { category: "shell", riskLevel: "high", capabilities: ["run_shell"], requiresApproval: true },
704
+ {
705
+ type: "function",
706
+ function: {
707
+ name: "run_shell",
708
+ description: `\u5728\u6301\u4E45\u5316 shell \u4F1A\u8BDD\u4E2D\u8FD0\u884C\u547D\u4EE4 (cwd \u548C\u73AF\u5883\u53D8\u91CF\u5728\u591A\u6B21\u8C03\u7528\u4E4B\u95F4\u4FDD\u6301)\u3002\u8F93\u51FA\u622A\u65AD\u5230\u6700\u540E\u90E8\u5206\uFF0Cstdout \u4E0E stderr \u90FD\u4F1A\u8FD4\u56DE\u3002\u4F20\u9012 description \u8BF4\u660E\u547D\u4EE4\u7528\u9014 (\u663E\u793A\u5728\u5BA1\u6279\u63D0\u793A\u4E2D)\uFF0C\u4F20\u9012 timeout_seconds \u63A7\u5236\u8D85\u65F6\u3002\u5BF9\u4E8E\u5F00\u53D1\u670D\u52A1\u5668 / watch \u7B49\u957F\u9A7B\u8FDB\u7A0B\uFF0C\u8BBE\u7F6E run_in_background=true\uFF0C\u968F\u540E\u7528 shell_task_output \u8F6E\u8BE2\u8F93\u51FA\u3001shell_task_kill \u7EC8\u6B62\u3002\u8FD0\u884C\u73AF\u5883\uFF1A${describeShell(spec, process.platform)}` + (sandbox?.enforced ? `\u6C99\u7BB1\uFF1A${describeSandbox(sandbox)}\uFF1B\u5DE5\u4F5C\u533A\u5916\u7684\u5199\u5165\u4F1A\u88AB\u7CFB\u7EDF\u62D2\u7EDD\u3002` : ""),
709
+ parameters: {
710
+ type: "object",
711
+ properties: {
712
+ command: { type: "string", description: "\u8981\u6267\u884C\u7684 shell \u547D\u4EE4" },
713
+ description: { type: "string", description: "\u547D\u4EE4\u7528\u9014\u7684\u7B80\u77ED\u63CF\u8FF0 (\u663E\u793A\u5728\u5BA1\u6279\u4E2D)" },
714
+ timeout_seconds: { type: "integer", description: "\u8D85\u65F6\u79D2\u6570 (\u9ED8\u8BA4 120\uFF0C\u6700\u5927 600)" },
715
+ run_in_background: {
716
+ type: "boolean",
717
+ description: "\u662F\u5426\u540E\u53F0\u8FD0\u884C (\u9ED8\u8BA4 false)\u3002\u9002\u5408\u5F00\u53D1\u670D\u52A1\u5668\u7B49\u957F\u9A7B\u8FDB\u7A0B\u3002"
718
+ }
719
+ },
720
+ required: ["command"]
721
+ }
722
+ }
723
+ }
724
+ );
725
+ registry.register(
726
+ (args) => tasks.output(String(args.task_id ?? "")),
727
+ { category: "shell", riskLevel: "low", capabilities: ["run_shell"], requiresApproval: false },
728
+ {
729
+ type: "function",
730
+ function: {
731
+ name: "shell_task_output",
732
+ description: "\u67E5\u770B run_shell(run_in_background=true) \u542F\u52A8\u7684\u540E\u53F0\u4EFB\u52A1\u7684\u7D2F\u8BA1\u8F93\u51FA\u4E0E\u72B6\u6001\u3002\u8FD4\u56DE status (running/exited/killed)\u3001exit_code\u3001stdout\u3001stderr\u3002",
733
+ parameters: {
734
+ type: "object",
735
+ properties: {
736
+ task_id: { type: "string", description: "run_shell \u8FD4\u56DE\u7684 task_id" }
737
+ },
738
+ required: ["task_id"]
739
+ }
740
+ }
741
+ }
742
+ );
743
+ registry.register(
744
+ (args) => tasks.kill(String(args.task_id ?? ""), scope ?? null),
745
+ { category: "shell", riskLevel: "medium", capabilities: ["run_shell"], requiresApproval: false },
746
+ {
747
+ type: "function",
748
+ function: {
749
+ name: "shell_task_kill",
750
+ description: "\u7EC8\u6B62\u540E\u53F0\u4EFB\u52A1\uFF08\u8FDE\u540C\u5176\u5B50\u8FDB\u7A0B\u6811\uFF09\u3002\u8FD4\u56DE\u4EFB\u52A1\u7684\u6700\u7EC8\u72B6\u6001\u3002",
751
+ parameters: {
752
+ type: "object",
753
+ properties: {
754
+ task_id: { type: "string", description: "run_shell \u8FD4\u56DE\u7684 task_id" }
755
+ },
756
+ required: ["task_id"]
757
+ }
758
+ }
759
+ }
760
+ );
761
+ }
762
+ // Annotate the CommonJS export names for ESM import in node:
763
+ 0 && (module.exports = {
764
+ decodeOutput,
765
+ getShellCwd,
766
+ killShellTask,
767
+ listShellTasks,
768
+ registerShellTool,
769
+ resetShellSession
770
+ });
771
+ //# sourceMappingURL=shell.cjs.map