@ai-setting/roy-agent-core 1.5.33 → 1.5.34

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.
@@ -8,7 +8,7 @@ import {
8
8
  grepTool,
9
9
  readFileTool,
10
10
  writeFileTool
11
- } from "../../../shared/@ai-setting/roy-agent-core-p46v1kr2.js";
11
+ } from "../../../shared/@ai-setting/roy-agent-core-wzbeqtmc.js";
12
12
  import"../../../shared/@ai-setting/roy-agent-core-xs5rsgat.js";
13
13
  import"../../../shared/@ai-setting/roy-agent-core-psv4v63c.js";
14
14
  import"../../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  ToolComponent,
3
3
  ToolRegistry,
4
- ToolValidator
5
- } from "../../shared/@ai-setting/roy-agent-core-q27e6dhw.js";
4
+ ToolValidator,
5
+ getMaxOutputSize,
6
+ setToolConfigComponent
7
+ } from "../../shared/@ai-setting/roy-agent-core-c1q5pw77.js";
6
8
  import {
7
9
  bashTool,
8
10
  echoTool,
@@ -13,7 +15,7 @@ import {
13
15
  grepTool,
14
16
  readFileTool,
15
17
  writeFileTool
16
- } from "../../shared/@ai-setting/roy-agent-core-p46v1kr2.js";
18
+ } from "../../shared/@ai-setting/roy-agent-core-wzbeqtmc.js";
17
19
  import"../../shared/@ai-setting/roy-agent-core-e25xkv53.js";
18
20
  import"../../shared/@ai-setting/roy-agent-core-qxhq8ven.js";
19
21
  import"../../shared/@ai-setting/roy-agent-core-kkbwepqb.js";
@@ -25,9 +27,11 @@ import"../../shared/@ai-setting/roy-agent-core-psv4v63c.js";
25
27
  import"../../shared/@ai-setting/roy-agent-core-fs0mn2jk.js";
26
28
  export {
27
29
  writeFileTool,
30
+ setToolConfigComponent,
28
31
  readFileTool,
29
32
  grepTool,
30
33
  globTool,
34
+ getMaxOutputSize,
31
35
  getBuiltInTool,
32
36
  getAllBuiltInTools,
33
37
  editFileTool,
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  ToolComponent,
10
10
  ToolRegistry,
11
11
  ToolValidator
12
- } from "./shared/@ai-setting/roy-agent-core-q27e6dhw.js";
12
+ } from "./shared/@ai-setting/roy-agent-core-c1q5pw77.js";
13
13
  import {
14
14
  bashTool,
15
15
  editFileTool,
@@ -19,7 +19,7 @@ import {
19
19
  grepTool,
20
20
  readFileTool,
21
21
  writeFileTool
22
- } from "./shared/@ai-setting/roy-agent-core-p46v1kr2.js";
22
+ } from "./shared/@ai-setting/roy-agent-core-wzbeqtmc.js";
23
23
  import {
24
24
  PromptComponent,
25
25
  getBuiltInPrompt,
@@ -149,7 +149,8 @@ var TOOL_DEFAULTS = {
149
149
  "tool.sandbox.enabled": false,
150
150
  "tool.sandbox.type": "native",
151
151
  "tool.execution.timeout": 30000,
152
- "tool.execution.maxConcurrency": 5
152
+ "tool.execution.maxConcurrency": 5,
153
+ "tool.execution.maxOutputSize": 5120
153
154
  };
154
155
  var TOOL_CONFIG_REGISTRATION = {
155
156
  name: "tool",
@@ -163,13 +164,47 @@ var TOOL_CONFIG_REGISTRATION = {
163
164
  { key: "tool.sandbox.enabled", sources: ["env", "file"] },
164
165
  { key: "tool.sandbox.type", sources: ["env", "file"] },
165
166
  { key: "tool.execution.timeout", sources: ["env", "file"] },
166
- { key: "tool.execution.maxConcurrency", sources: ["env", "file"] }
167
+ { key: "tool.execution.maxConcurrency", sources: ["env", "file"] },
168
+ { key: "tool.execution.maxOutputSize", sources: ["env", "file"] }
167
169
  ]
168
170
  };
169
171
 
170
172
  // src/env/tool/tool-component.ts
171
173
  init_workflow_hil();
172
174
  var logger = createLogger("tool");
175
+ var configComponentInstance = null;
176
+ function setToolConfigComponent(component) {
177
+ configComponentInstance = component;
178
+ }
179
+ function getMaxOutputSize() {
180
+ if (configComponentInstance) {
181
+ const maxOutputSize = configComponentInstance.get("tool.execution.maxOutputSize");
182
+ if (typeof maxOutputSize === "number" && maxOutputSize >= 0) {
183
+ return maxOutputSize;
184
+ }
185
+ }
186
+ return 5120;
187
+ }
188
+ function truncateOutput(output, maxSize) {
189
+ if (maxSize <= 0 || output.length <= maxSize) {
190
+ return {
191
+ output,
192
+ metadata: {}
193
+ };
194
+ }
195
+ const truncatedOutput = output.substring(0, maxSize);
196
+ const truncationNotice = `
197
+
198
+ [OUTPUT TRUNCATED: ${output.length} → ${maxSize} characters. Use offset/limit parameters or pipe to file for full content.]`;
199
+ return {
200
+ output: truncatedOutput + truncationNotice,
201
+ metadata: {
202
+ output_truncated: true,
203
+ original_output_size: output.length,
204
+ truncated_output_size: maxSize
205
+ }
206
+ };
207
+ }
173
208
 
174
209
  class ToolComponent extends BaseComponent {
175
210
  name = "tool";
@@ -191,6 +226,7 @@ class ToolComponent extends BaseComponent {
191
226
  throw new Error("ConfigComponent is required for ToolComponent initialization");
192
227
  }
193
228
  this.configComponent = options.configComponent;
229
+ setToolConfigComponent(options.configComponent);
194
230
  await this.registerConfig(options);
195
231
  if (this.config?.builtInTools?.enabled !== false) {
196
232
  await this.loadBuiltInTools();
@@ -377,6 +413,17 @@ class ToolComponent extends BaseComponent {
377
413
  } else {
378
414
  result.metadata.execution_time_ms = Date.now() - startTime;
379
415
  }
416
+ if (typeof result.output === "string") {
417
+ const maxOutputSize = getMaxOutputSize();
418
+ if (maxOutputSize > 0) {
419
+ const { output: truncatedOutput, metadata: truncationMeta } = truncateOutput(result.output, maxOutputSize);
420
+ result.output = truncatedOutput;
421
+ result.metadata = {
422
+ ...result.metadata,
423
+ ...truncationMeta
424
+ };
425
+ }
426
+ }
380
427
  if (!skipHooks) {
381
428
  await globalHookManager.execute(ToolHookPoints.AFTER_EXECUTE, { tool, args, context, result }, { toolName: tool.name });
382
429
  }
@@ -439,4 +486,4 @@ var ToolComponentConfigSchema = z.object({
439
486
  maxConcurrency: z.number().int().positive().default(4)
440
487
  }).default({})
441
488
  });
442
- export { ToolRegistry, ToolValidator, ToolComponent };
489
+ export { ToolRegistry, ToolValidator, setToolConfigComponent, getMaxOutputSize, ToolComponent };
@@ -13,23 +13,34 @@ init_propagation();
13
13
  import { z } from "zod";
14
14
  import { spawn } from "child_process";
15
15
  import path from "path";
16
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
16
17
  function getPlatform() {
17
18
  return process.platform;
18
19
  }
19
20
  function isWindows() {
20
21
  return getPlatform() === "win32";
21
22
  }
22
- function getShellCommand(command) {
23
+ async function killProcessTree(pid) {
23
24
  if (isWindows()) {
24
- return {
25
- shell: "cmd.exe",
26
- args: ["/c", command]
27
- };
25
+ await new Promise((resolve) => {
26
+ const killer = spawn("taskkill", ["/pid", String(pid), "/f", "/t"], {
27
+ stdio: "ignore",
28
+ windowsHide: true
29
+ });
30
+ killer.on("exit", () => resolve());
31
+ killer.on("error", () => resolve());
32
+ });
33
+ return;
28
34
  }
29
- return {
30
- shell: "/bin/sh",
31
- args: ["-c", command]
32
- };
35
+ try {
36
+ process.kill(-pid, "SIGTERM");
37
+ await sleep(200);
38
+ try {
39
+ process.kill(-pid, 0);
40
+ process.kill(-pid, "SIGKILL");
41
+ await sleep(100);
42
+ } catch {}
43
+ } catch {}
33
44
  }
34
45
  function normalizeCwd(cwd) {
35
46
  if (!cwd)
@@ -38,46 +49,100 @@ function normalizeCwd(cwd) {
38
49
  }
39
50
  function executeCommand(command, options) {
40
51
  return new Promise((resolve) => {
41
- const { shell, args } = getShellCommand(command);
42
52
  let stdout = "";
43
53
  let stderr = "";
44
54
  let timedOut = false;
45
55
  let resolved = false;
46
56
  let timer = null;
47
- let forceKillTimer = null;
48
- const child = spawn(shell, args, {
49
- cwd: normalizeCwd(options.cwd),
57
+ let childPid;
58
+ let processGroupId;
59
+ const cwd = normalizeCwd(options.cwd);
60
+ if (isWindows()) {
61
+ const child2 = spawn("cmd.exe", ["/c", command], {
62
+ cwd,
63
+ env: options.env,
64
+ stdio: ["ignore", "pipe", "pipe"],
65
+ windowsHide: true,
66
+ detached: true
67
+ });
68
+ childPid = child2.pid;
69
+ child2.unref();
70
+ const cleanup2 = () => {
71
+ if (timer)
72
+ clearTimeout(timer);
73
+ };
74
+ const doResolve2 = (exitCode, timedOutFlag) => {
75
+ if (!resolved) {
76
+ resolved = true;
77
+ cleanup2();
78
+ resolve({
79
+ stdout: stdout.trim(),
80
+ stderr: stderr.trim(),
81
+ exitCode: timedOutFlag ? -1 : exitCode,
82
+ timedOut: timedOutFlag
83
+ });
84
+ }
85
+ };
86
+ if (options.timeout) {
87
+ timer = setTimeout(async () => {
88
+ timedOut = true;
89
+ if (childPid) {
90
+ await killProcessTree(childPid);
91
+ } else {
92
+ child2.kill("SIGKILL");
93
+ }
94
+ }, options.timeout);
95
+ }
96
+ child2.stdout?.on("data", (data) => {
97
+ stdout += data.toString();
98
+ });
99
+ child2.stderr?.on("data", (data) => {
100
+ stderr += data.toString();
101
+ });
102
+ child2.on("exit", (code) => {
103
+ doResolve2(code ?? 0, timedOut);
104
+ });
105
+ child2.on("error", () => {
106
+ doResolve2(1, false);
107
+ });
108
+ return;
109
+ }
110
+ const child = spawn(command, [], {
111
+ shell: true,
112
+ cwd,
50
113
  env: options.env,
51
114
  stdio: ["ignore", "pipe", "pipe"],
52
- windowsHide: true
115
+ windowsHide: true,
116
+ detached: true
53
117
  });
118
+ childPid = child.pid;
119
+ processGroupId = childPid;
54
120
  const cleanup = () => {
55
121
  if (timer)
56
122
  clearTimeout(timer);
57
- if (forceKillTimer)
58
- clearTimeout(forceKillTimer);
59
123
  };
60
- const doResolve = (result) => {
124
+ const doResolve = (exitCode, timedOutFlag) => {
61
125
  if (!resolved) {
62
126
  resolved = true;
63
127
  cleanup();
64
- resolve(result);
128
+ resolve({
129
+ stdout: stdout.trim(),
130
+ stderr: stderr.trim(),
131
+ exitCode: timedOutFlag ? -1 : exitCode,
132
+ timedOut: timedOutFlag
133
+ });
65
134
  }
66
135
  };
67
136
  if (options.timeout) {
68
- timer = setTimeout(() => {
137
+ timer = setTimeout(async () => {
69
138
  timedOut = true;
70
- if (isWindows()) {
71
- child.kill("SIGTERM");
72
- forceKillTimer = setTimeout(() => {
73
- if (!child.killed) {
74
- try {
75
- process.kill(child.pid, "SIGKILL");
76
- } catch {}
77
- }
78
- }, 500);
79
- } else {
80
- child.kill("SIGKILL");
139
+ if (processGroupId) {
140
+ await killProcessTree(processGroupId);
141
+ }
142
+ if (childPid) {
143
+ try {
144
+ process.kill(childPid, "SIGKILL");
145
+ } catch {}
81
146
  }
82
147
  }, options.timeout);
83
148
  }
@@ -87,21 +152,11 @@ function executeCommand(command, options) {
87
152
  child.stderr?.on("data", (data) => {
88
153
  stderr += data.toString();
89
154
  });
90
- child.on("close", (code) => {
91
- doResolve({
92
- stdout: stdout.trim(),
93
- stderr: stderr.trim(),
94
- exitCode: timedOut ? -1 : code ?? 0,
95
- timedOut
96
- });
155
+ child.on("exit", (code, signal) => {
156
+ doResolve(code ?? (signal ? 1 : 0), timedOut);
97
157
  });
98
- child.on("error", (err) => {
99
- doResolve({
100
- stdout: stdout.trim(),
101
- stderr: err.message,
102
- exitCode: 1,
103
- timedOut: false
104
- });
158
+ child.on("error", () => {
159
+ doResolve(1, false);
105
160
  });
106
161
  });
107
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-core",
3
- "version": "1.5.33",
3
+ "version": "1.5.34",
4
4
  "type": "module",
5
5
  "description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
6
6
  "main": "./dist/index.js",