@ai-setting/roy-agent-core 1.4.12 → 1.4.14

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 (127) hide show
  1. package/dist/packages/core/src/config/index.js +32 -0
  2. package/dist/packages/core/src/env/agent/index.js +24 -0
  3. package/dist/packages/core/src/env/commands/index.js +14 -0
  4. package/dist/packages/core/src/env/debug/formatters/index.js +11 -0
  5. package/dist/packages/core/src/env/debug/index.js +26 -0
  6. package/dist/packages/core/src/env/hook/index.js +29 -0
  7. package/dist/packages/core/src/env/index.js +81 -0
  8. package/dist/packages/core/src/env/llm/index.js +40 -0
  9. package/dist/packages/core/src/env/log-trace/index.js +83 -0
  10. package/dist/packages/core/src/env/mcp/index.js +39 -0
  11. package/dist/packages/core/src/env/mcp/tool/index.js +14 -0
  12. package/dist/packages/core/src/env/memory/built-in/index.js +11 -0
  13. package/dist/packages/core/src/env/memory/index.js +56 -0
  14. package/dist/packages/core/src/env/memory/plugin/index.js +36 -0
  15. package/dist/packages/core/src/env/prompt/index.js +20 -0
  16. package/dist/packages/core/src/env/session/index.js +25 -0
  17. package/dist/packages/core/src/env/session/storage/index.js +18 -0
  18. package/dist/packages/core/src/env/skill/index.js +34 -0
  19. package/dist/packages/core/src/env/skill/tool/index.js +9 -0
  20. package/dist/packages/core/src/env/task/delegate/index.js +18 -0
  21. package/dist/packages/core/src/env/task/hooks/index.js +7 -0
  22. package/dist/packages/core/src/env/task/index.js +30 -0
  23. package/dist/packages/core/src/env/task/plugins/index.js +23 -0
  24. package/dist/packages/core/src/env/task/storage/index.js +14 -0
  25. package/dist/packages/core/src/env/task/tools/index.js +17 -0
  26. package/dist/packages/core/src/env/task/tools/operation/index.js +15 -0
  27. package/dist/packages/core/src/env/tool/built-in/index.js +25 -0
  28. package/dist/packages/core/src/env/tool/index.js +39 -0
  29. package/dist/packages/core/src/env/workflow/decorators/index.js +27 -0
  30. package/dist/packages/core/src/env/workflow/engine/index.js +28 -0
  31. package/dist/packages/core/src/env/workflow/index.js +132 -0
  32. package/dist/packages/core/src/env/workflow/nodes/index.js +19 -0
  33. package/dist/packages/core/src/env/workflow/service/index.js +13 -0
  34. package/dist/packages/core/src/env/workflow/storage/index.js +27 -0
  35. package/dist/packages/core/src/env/workflow/tools/index.js +159 -0
  36. package/dist/packages/core/src/env/workflow/types/index.js +94 -0
  37. package/dist/packages/core/src/env/workflow/utils/index.js +637 -0
  38. package/dist/packages/core/src/index.js +398 -0
  39. package/dist/shared/@ai-setting/roy-agent-core-04fm8177.js +393 -0
  40. package/dist/shared/@ai-setting/roy-agent-core-04qgbjbe.js +172 -0
  41. package/dist/shared/@ai-setting/roy-agent-core-084qqd7t.js +11 -0
  42. package/dist/shared/@ai-setting/roy-agent-core-0gekht4e.js +1130 -0
  43. package/dist/shared/@ai-setting/roy-agent-core-0hdry23r.js +419 -0
  44. package/dist/shared/@ai-setting/roy-agent-core-0sgn3de4.js +102 -0
  45. package/dist/{env/task/tools/index.js → shared/@ai-setting/roy-agent-core-12x57kf1.js} +1 -59
  46. package/dist/shared/@ai-setting/roy-agent-core-1f3xrrm6.js +393 -0
  47. package/dist/shared/@ai-setting/roy-agent-core-1k28kg7h.js +368 -0
  48. package/dist/shared/@ai-setting/roy-agent-core-1z1zv5g8.js +258 -0
  49. package/dist/shared/@ai-setting/roy-agent-core-2hqxnaf3.js +851 -0
  50. package/dist/shared/@ai-setting/roy-agent-core-3dfq8awb.js +587 -0
  51. package/dist/shared/@ai-setting/roy-agent-core-3takar0s.js +93 -0
  52. package/dist/shared/@ai-setting/roy-agent-core-3tnb2005.js +117 -0
  53. package/dist/shared/@ai-setting/roy-agent-core-4vmcvkav.js +14 -0
  54. package/dist/shared/@ai-setting/roy-agent-core-4ws8atva.js +107 -0
  55. package/dist/{env/workflow/nodes/index.js → shared/@ai-setting/roy-agent-core-5fbp24se.js} +8 -55
  56. package/dist/shared/@ai-setting/roy-agent-core-5my94ywp.js +66 -0
  57. package/dist/shared/@ai-setting/roy-agent-core-6j0zcmwk.js +2146 -0
  58. package/dist/shared/@ai-setting/roy-agent-core-6w4pmxc7.js +266 -0
  59. package/dist/shared/@ai-setting/roy-agent-core-7vrk3add.js +10 -0
  60. package/dist/shared/@ai-setting/roy-agent-core-8dvbn7tw.js +64 -0
  61. package/dist/{env/memory/built-in/index.js → shared/@ai-setting/roy-agent-core-8mbmrwzs.js} +22 -76
  62. package/dist/shared/@ai-setting/roy-agent-core-8wzz66qe.js +620 -0
  63. package/dist/shared/@ai-setting/roy-agent-core-9ykq91jc.js +762 -0
  64. package/dist/shared/@ai-setting/roy-agent-core-dde19zke.js +1305 -0
  65. package/dist/shared/@ai-setting/roy-agent-core-f7g67gce.js +913 -0
  66. package/dist/{env/workflow/types/index.js → shared/@ai-setting/roy-agent-core-fq5mtxsy.js} +16 -154
  67. package/dist/{env/task/hooks/index.js → shared/@ai-setting/roy-agent-core-fs0mn2jk.js} +3 -18
  68. package/dist/{config/index.js → shared/@ai-setting/roy-agent-core-fvd9g6k8.js} +140 -605
  69. package/dist/shared/@ai-setting/roy-agent-core-gv1hrn3x.js +378 -0
  70. package/dist/{env/task/tools/operation/index.js → shared/@ai-setting/roy-agent-core-gy0wp5h7.js} +1 -58
  71. package/dist/shared/@ai-setting/roy-agent-core-hyza1gm7.js +15 -0
  72. package/dist/shared/@ai-setting/roy-agent-core-j8zx62zr.js +154 -0
  73. package/dist/shared/@ai-setting/roy-agent-core-jb2exr0d.js +442 -0
  74. package/dist/shared/@ai-setting/roy-agent-core-jv3b7v9w.js +57 -0
  75. package/dist/shared/@ai-setting/roy-agent-core-k1rxf9ya.js +513 -0
  76. package/dist/shared/@ai-setting/roy-agent-core-kydc9nwb.js +60 -0
  77. package/dist/shared/@ai-setting/roy-agent-core-m2x48hw6.js +97 -0
  78. package/dist/shared/@ai-setting/roy-agent-core-m6y668cc.js +377 -0
  79. package/dist/shared/@ai-setting/roy-agent-core-nczzf0ms.js +15 -0
  80. package/dist/shared/@ai-setting/roy-agent-core-nfj6knp5.js +36 -0
  81. package/dist/shared/@ai-setting/roy-agent-core-ntrp979d.js +204 -0
  82. package/dist/shared/@ai-setting/roy-agent-core-pd7g8z5v.js +1387 -0
  83. package/dist/shared/@ai-setting/roy-agent-core-pzk1syce.js +14 -0
  84. package/dist/shared/@ai-setting/roy-agent-core-q50tg9m2.js +862 -0
  85. package/dist/shared/@ai-setting/roy-agent-core-qg9tcaph.js +11 -0
  86. package/dist/shared/@ai-setting/roy-agent-core-qhyerewk.js +20 -0
  87. package/dist/shared/@ai-setting/roy-agent-core-qxybm159.js +82 -0
  88. package/dist/shared/@ai-setting/roy-agent-core-rh9dpkpw.js +549 -0
  89. package/dist/shared/@ai-setting/roy-agent-core-rr9p1g43.js +205 -0
  90. package/dist/{env/workflow/decorators/index.js → shared/@ai-setting/roy-agent-core-sbzvpfn7.js} +8 -173
  91. package/dist/shared/@ai-setting/roy-agent-core-t22nqt4d.js +788 -0
  92. package/dist/shared/@ai-setting/roy-agent-core-tkr5ynkh.js +200 -0
  93. package/dist/shared/@ai-setting/roy-agent-core-v4aabsf0.js +303 -0
  94. package/dist/{env/hook/index.js → shared/@ai-setting/roy-agent-core-w75rafhy.js} +3 -74
  95. package/dist/{env/debug/formatters/index.js → shared/@ai-setting/roy-agent-core-w76hqkmg.js} +11 -66
  96. package/dist/shared/@ai-setting/roy-agent-core-yfbgwes2.js +408 -0
  97. package/dist/shared/@ai-setting/roy-agent-core-yn761yve.js +299 -0
  98. package/dist/shared/@ai-setting/roy-agent-core-yrzmn4m1.js +492 -0
  99. package/dist/{env/workflow/service/index.js → shared/@ai-setting/roy-agent-core-yt8wdh2w.js} +1 -57
  100. package/package.json +3 -2
  101. package/dist/env/agent/index.js +0 -3035
  102. package/dist/env/commands/index.js +0 -1685
  103. package/dist/env/debug/index.js +0 -2300
  104. package/dist/env/index.js +0 -12591
  105. package/dist/env/llm/index.js +0 -2736
  106. package/dist/env/log-trace/index.js +0 -1779
  107. package/dist/env/mcp/index.js +0 -2173
  108. package/dist/env/mcp/tool/index.js +0 -1149
  109. package/dist/env/memory/index.js +0 -2171
  110. package/dist/env/memory/plugin/index.js +0 -1263
  111. package/dist/env/prompt/index.js +0 -2107
  112. package/dist/env/session/index.js +0 -3594
  113. package/dist/env/session/storage/index.js +0 -2049
  114. package/dist/env/skill/index.js +0 -1635
  115. package/dist/env/skill/tool/index.js +0 -114
  116. package/dist/env/task/delegate/index.js +0 -1844
  117. package/dist/env/task/index.js +0 -3578
  118. package/dist/env/task/plugins/index.js +0 -1626
  119. package/dist/env/task/storage/index.js +0 -1464
  120. package/dist/env/tool/built-in/index.js +0 -1151
  121. package/dist/env/tool/index.js +0 -2284
  122. package/dist/env/workflow/engine/index.js +0 -4391
  123. package/dist/env/workflow/index.js +0 -6214
  124. package/dist/env/workflow/storage/index.js +0 -1236
  125. package/dist/env/workflow/tools/index.js +0 -1081
  126. package/dist/env/workflow/utils/index.js +0 -1631
  127. package/dist/index.js +0 -22778
@@ -0,0 +1,11 @@
1
+ import {
2
+ AgentComponentAdapter,
3
+ init_agent_component_adapter
4
+ } from "./roy-agent-core-rr9p1g43.js";
5
+ import"./roy-agent-core-8dvbn7tw.js";
6
+ import"./roy-agent-core-fs0mn2jk.js";
7
+ init_agent_component_adapter();
8
+
9
+ export {
10
+ AgentComponentAdapter
11
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ closeDatabase,
3
+ getDatabase,
4
+ getDatabasePath,
5
+ initDatabase,
6
+ initializeTables,
7
+ resetDatabase
8
+ } from "./roy-agent-core-qxybm159.js";
9
+ import"./roy-agent-core-yn761yve.js";
10
+ import"./roy-agent-core-1k28kg7h.js";
11
+ import"./roy-agent-core-j8zx62zr.js";
12
+ import"./roy-agent-core-fs0mn2jk.js";
13
+ export {
14
+ resetDatabase,
15
+ initializeTables,
16
+ initDatabase,
17
+ getDatabasePath,
18
+ getDatabase,
19
+ closeDatabase
20
+ };
@@ -0,0 +1,82 @@
1
+ import {
2
+ createLogger,
3
+ init_logger
4
+ } from "./roy-agent-core-yn761yve.js";
5
+ import {
6
+ __require
7
+ } from "./roy-agent-core-fs0mn2jk.js";
8
+
9
+ // packages/core/src/env/workflow/storage/sqlite.ts
10
+ init_logger();
11
+ import { join } from "path";
12
+ var logger = createLogger("workflow:sqlite");
13
+ function getDefaultDataDir() {
14
+ const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
15
+ return join(home, ".local", "share", "roy-agent");
16
+ }
17
+ function getDatabasePath() {
18
+ return join(getDefaultDataDir(), "workflows.db");
19
+ }
20
+ var dbInstance = null;
21
+ function getDatabase(path) {
22
+ if (!dbInstance) {
23
+ const dbPath = path ?? getDatabasePath();
24
+ const dbDir = dbPath.substring(0, dbPath.lastIndexOf("/"));
25
+ if (dbDir && dbDir !== "/") {
26
+ try {
27
+ const { mkdirSync } = __require("fs");
28
+ mkdirSync(dbDir, { recursive: true });
29
+ } catch {}
30
+ }
31
+ const { Database } = __require("bun:sqlite");
32
+ dbInstance = new Database(dbPath);
33
+ try {
34
+ if (typeof dbInstance.pragma === "function") {
35
+ dbInstance.pragma("journal_mode = WAL");
36
+ }
37
+ } catch {
38
+ logger?.debug("WAL mode not available, using default journal mode");
39
+ }
40
+ }
41
+ return dbInstance;
42
+ }
43
+ function closeDatabase() {
44
+ if (dbInstance) {
45
+ dbInstance.close();
46
+ dbInstance = null;
47
+ }
48
+ }
49
+ function initializeTables() {
50
+ const db = getDatabase();
51
+ db.exec(`
52
+ CREATE TABLE IF NOT EXISTS workflows (
53
+ id TEXT PRIMARY KEY,
54
+ name TEXT NOT NULL UNIQUE,
55
+ version TEXT NOT NULL DEFAULT '1.0',
56
+ description TEXT,
57
+ definition TEXT NOT NULL,
58
+ config TEXT NOT NULL DEFAULT '{}',
59
+ metadata TEXT NOT NULL DEFAULT '{}',
60
+ tags TEXT NOT NULL DEFAULT '[]',
61
+ task_id INTEGER,
62
+ created_at TEXT NOT NULL,
63
+ updated_at TEXT NOT NULL
64
+ )
65
+ `);
66
+ db.exec(`
67
+ CREATE INDEX IF NOT EXISTS idx_workflows_name ON workflows(name);
68
+ CREATE INDEX IF NOT EXISTS idx_workflows_tags ON workflows(tags);
69
+ CREATE INDEX IF NOT EXISTS idx_workflows_task_id ON workflows(task_id);
70
+ `);
71
+ }
72
+ function resetDatabase() {
73
+ closeDatabase();
74
+ dbInstance = null;
75
+ }
76
+ function initDatabase(path) {
77
+ const db = getDatabase(path);
78
+ initializeTables();
79
+ return db;
80
+ }
81
+
82
+ export { getDatabasePath, getDatabase, closeDatabase, initializeTables, resetDatabase, initDatabase };
@@ -0,0 +1,549 @@
1
+ import {
2
+ exports_tracer_provider,
3
+ init_propagation,
4
+ init_tracer_provider,
5
+ propagation
6
+ } from "./roy-agent-core-1k28kg7h.js";
7
+ import {
8
+ __toCommonJS
9
+ } from "./roy-agent-core-fs0mn2jk.js";
10
+
11
+ // packages/core/src/env/tool/built-in/bash.ts
12
+ init_propagation();
13
+ import { z } from "zod";
14
+ import { exec } from "child_process";
15
+ import { promisify } from "util";
16
+ var execAsync = promisify(exec);
17
+ function getCurrentSpanContext() {
18
+ try {
19
+ const { getTracerProvider } = (init_tracer_provider(), __toCommonJS(exports_tracer_provider));
20
+ const provider = getTracerProvider();
21
+ if (!provider.isInitialized()) {
22
+ throw new Error("Provider not initialized");
23
+ }
24
+ const tracer = provider.getTracer("roy-tracer");
25
+ const ctx = tracer.getCurrentContext();
26
+ if (ctx && ctx.traceId && ctx.spanId) {
27
+ return ctx;
28
+ }
29
+ } catch {}
30
+ return;
31
+ }
32
+ function getCurrentTraceId() {
33
+ const ctx = getCurrentSpanContext();
34
+ if (ctx) {
35
+ return ctx.traceId;
36
+ }
37
+ return process.env.TRACE_ID;
38
+ }
39
+ var bashTool = {
40
+ name: "bash",
41
+ description: "Execute shell commands in the terminal. Use this to run system commands, scripts, or interact with the file system.",
42
+ parameters: z.object({
43
+ command: z.string().describe("The shell command to execute"),
44
+ workdir: z.string().optional().describe("Working directory for the command"),
45
+ timeout: z.number().int().positive().optional().describe("Timeout in milliseconds"),
46
+ env: z.record(z.string()).optional().describe("Additional environment variables")
47
+ }),
48
+ sandbox: {
49
+ enabled: true,
50
+ config: {
51
+ filesystem: {
52
+ denyRead: ["/etc/shadow", "/etc/sudoers", "/etc/sudoers.d/*"],
53
+ denyWrite: ["/etc", "/usr/bin", "/usr/sbin", "/bin", "/sbin"]
54
+ }
55
+ }
56
+ },
57
+ permission: {
58
+ requireConfirmation: true,
59
+ level: "dangerous"
60
+ },
61
+ metadata: {
62
+ category: "system",
63
+ tags: ["shell", "command", "terminal", "exec"],
64
+ version: "1.2.0"
65
+ },
66
+ execute: async (args, ctx) => {
67
+ const startTime = Date.now();
68
+ const { command, workdir, timeout = 60000, env } = args;
69
+ const currentSpanCtx = getCurrentSpanContext();
70
+ const traceId = currentSpanCtx?.traceId || getCurrentTraceId();
71
+ const options = {
72
+ timeout
73
+ };
74
+ if (workdir || ctx.workdir) {
75
+ options.cwd = workdir || ctx.workdir;
76
+ }
77
+ const childEnv = {};
78
+ for (const [key, value] of Object.entries(process.env)) {
79
+ if (value !== undefined) {
80
+ childEnv[key] = value;
81
+ }
82
+ }
83
+ if (currentSpanCtx) {
84
+ const carrier = {};
85
+ propagation.inject(carrier, currentSpanCtx);
86
+ if (carrier["TRACEPARENT"]) {
87
+ childEnv["TRACEPARENT"] = carrier["TRACEPARENT"];
88
+ }
89
+ childEnv["TRACE_ID"] = currentSpanCtx.traceId;
90
+ childEnv["PARENT_SPAN_ID"] = currentSpanCtx.spanId;
91
+ } else if (traceId) {
92
+ const spanId2 = Math.floor(Math.random() * 18446744073709552000).toString(16).padStart(16, "0");
93
+ childEnv["TRACEPARENT"] = `00-${traceId}-${spanId2}-01`;
94
+ childEnv["TRACE_ID"] = traceId;
95
+ }
96
+ if (env) {
97
+ Object.assign(childEnv, env);
98
+ }
99
+ options.env = childEnv;
100
+ let otelSpan = undefined;
101
+ try {
102
+ const { getTracerProvider } = (init_tracer_provider(), __toCommonJS(exports_tracer_provider));
103
+ const provider = getTracerProvider();
104
+ const tracer = provider.getTracer("roy-tracer");
105
+ otelSpan = tracer.startSpan(`bash: ${command.slice(0, 50)}${command.length > 50 ? "..." : ""}`, {
106
+ attributes: {
107
+ "bash.command": command.slice(0, 200),
108
+ "bash.workdir": workdir || ctx.workdir || "",
109
+ "bash.timeout": timeout
110
+ }
111
+ });
112
+ } catch {}
113
+ const spanId = otelSpan?.spanContext?.spanId;
114
+ try {
115
+ const { stdout, stderr } = await execAsync(command, options);
116
+ if (otelSpan) {
117
+ otelSpan.end({ stdout, stderr });
118
+ }
119
+ return {
120
+ success: true,
121
+ output: stdout || "(no output)",
122
+ metadata: {
123
+ execution_time_ms: Date.now() - startTime,
124
+ stdout,
125
+ stderr,
126
+ exit_code: 0,
127
+ trace_id: traceId,
128
+ parent_span_id: currentSpanCtx?.spanId,
129
+ span_id: spanId
130
+ }
131
+ };
132
+ } catch (error) {
133
+ const exitCode = error.code || 1;
134
+ const stdout = error.stdout || "";
135
+ const stderr = error.stderr || error.message;
136
+ const execError = new Error(stderr);
137
+ execError.name = "BashExecutionError";
138
+ if (otelSpan) {
139
+ otelSpan.end(undefined, execError);
140
+ }
141
+ return {
142
+ success: exitCode === 0,
143
+ output: stdout || "(no output)",
144
+ error: stderr,
145
+ metadata: {
146
+ execution_time_ms: Date.now() - startTime,
147
+ stdout,
148
+ stderr,
149
+ exit_code: exitCode,
150
+ trace_id: traceId,
151
+ parent_span_id: currentSpanCtx?.spanId,
152
+ span_id: spanId
153
+ }
154
+ };
155
+ }
156
+ }
157
+ };
158
+
159
+ // packages/core/src/env/tool/built-in/echo.ts
160
+ var echoTool = {
161
+ name: "echo",
162
+ description: "Echo a message to the console. Useful for logging in workflows.",
163
+ parameters: {
164
+ name: "message",
165
+ schema: {
166
+ type: "string",
167
+ description: "The message to echo"
168
+ }
169
+ },
170
+ execute: async (args, _ctx) => {
171
+ const message = args?.message || "(no message)";
172
+ return {
173
+ success: true,
174
+ output: message,
175
+ metadata: {
176
+ execution_time_ms: 0
177
+ }
178
+ };
179
+ }
180
+ };
181
+
182
+ // packages/core/src/env/tool/built-in/glob.ts
183
+ import { z as z2 } from "zod";
184
+ import { glob as globAsync } from "glob";
185
+ var globTool = {
186
+ name: "glob",
187
+ description: "Search for files matching a glob pattern. Use this to find files by name patterns like **/*.ts or **/*.md.",
188
+ parameters: z2.object({
189
+ pattern: z2.string().describe("Glob pattern to match (e.g., **/*.ts, **/*.md)"),
190
+ cwd: z2.string().optional().describe("Working directory to search in"),
191
+ maxResults: z2.number().int().positive().optional().describe("Maximum number of results to return"),
192
+ ignore: z2.array(z2.string()).optional().describe("Patterns to ignore")
193
+ }),
194
+ sandbox: {
195
+ enabled: true
196
+ },
197
+ metadata: {
198
+ category: "file",
199
+ tags: ["search", "file", "glob", "pattern"],
200
+ version: "1.0.0"
201
+ },
202
+ execute: async (args, ctx) => {
203
+ const startTime = Date.now();
204
+ const { pattern, cwd, maxResults = 100, ignore } = args;
205
+ const searchDir = cwd || ctx.workdir || process.cwd();
206
+ try {
207
+ const files = await globAsync(pattern, {
208
+ cwd: searchDir,
209
+ ignore: ignore || ["**/node_modules/**", "**/.git/**"],
210
+ maxDepth: 20
211
+ });
212
+ const limitedFiles = files.slice(0, maxResults);
213
+ const output = limitedFiles.join(`
214
+ `);
215
+ return {
216
+ success: true,
217
+ output,
218
+ metadata: {
219
+ execution_time_ms: Date.now() - startTime,
220
+ output_size: output.length,
221
+ total_matches: files.length,
222
+ returned_matches: limitedFiles.length
223
+ }
224
+ };
225
+ } catch (error) {
226
+ return {
227
+ success: false,
228
+ output: "",
229
+ error: error instanceof Error ? error.message : String(error),
230
+ metadata: {
231
+ execution_time_ms: Date.now() - startTime
232
+ }
233
+ };
234
+ }
235
+ }
236
+ };
237
+
238
+ // packages/core/src/env/tool/built-in/read-file.ts
239
+ import { z as z3 } from "zod";
240
+ import { readFile } from "fs/promises";
241
+ var readFileTool = {
242
+ name: "read_file",
243
+ description: "Read the contents of a file. Use this to read source code, configuration files, or any text files.",
244
+ parameters: z3.object({
245
+ path: z3.string().describe("The file path to read"),
246
+ offset: z3.number().int().nonnegative().optional().describe("Line offset to start reading from"),
247
+ limit: z3.number().int().positive().optional().describe("Number of lines to read"),
248
+ encoding: z3.enum(["utf-8", "base64"]).default("utf-8").optional().describe("File encoding")
249
+ }),
250
+ sandbox: {
251
+ enabled: true,
252
+ config: {
253
+ filesystem: {
254
+ denyRead: ["/etc/shadow", "/etc/sudoers", "/root/.ssh"]
255
+ }
256
+ }
257
+ },
258
+ permission: {
259
+ level: "safe"
260
+ },
261
+ metadata: {
262
+ category: "file",
263
+ tags: ["read", "file", "io"],
264
+ version: "1.0.0"
265
+ },
266
+ execute: async (args, ctx) => {
267
+ const startTime = Date.now();
268
+ const { path: filePath, offset, limit, encoding = "utf-8" } = args;
269
+ try {
270
+ const content = await readFile(filePath, encoding);
271
+ let output;
272
+ const contentBuffer = content;
273
+ const contentStr = typeof contentBuffer === "string" ? contentBuffer : contentBuffer.toString(encoding);
274
+ if (offset !== undefined || limit !== undefined) {
275
+ const lines = contentStr.split(`
276
+ `);
277
+ const startLine = offset || 0;
278
+ const endLine = limit ? startLine + limit : lines.length;
279
+ output = lines.slice(startLine, endLine).join(`
280
+ `);
281
+ } else {
282
+ output = contentStr;
283
+ }
284
+ return {
285
+ success: true,
286
+ output,
287
+ metadata: {
288
+ execution_time_ms: Date.now() - startTime,
289
+ output_size: output.length,
290
+ file_path: filePath
291
+ }
292
+ };
293
+ } catch (error) {
294
+ return {
295
+ success: false,
296
+ output: "",
297
+ error: error instanceof Error ? error.message : String(error),
298
+ metadata: {
299
+ execution_time_ms: Date.now() - startTime
300
+ }
301
+ };
302
+ }
303
+ }
304
+ };
305
+
306
+ // packages/core/src/env/tool/built-in/write-file.ts
307
+ import { z as z4 } from "zod";
308
+ import { writeFile, mkdir } from "fs/promises";
309
+ import { dirname } from "path";
310
+ var writeFileTool = {
311
+ name: "write_file",
312
+ description: "Write content to a file. Use this to create new files or overwrite existing ones.",
313
+ parameters: z4.object({
314
+ path: z4.string().describe("The file path to write to"),
315
+ content: z4.string().describe("The content to write"),
316
+ createDirs: z4.boolean().default(false).optional().describe("Create parent directories if they don't exist"),
317
+ append: z4.boolean().default(false).optional().describe("Append to file instead of overwrite")
318
+ }),
319
+ sandbox: {
320
+ enabled: true,
321
+ config: {
322
+ filesystem: {
323
+ denyWrite: ["/etc", "/usr", "/bin", "/sbin", "/boot", "/sys"]
324
+ }
325
+ }
326
+ },
327
+ permission: {
328
+ requireConfirmation: true,
329
+ level: "dangerous"
330
+ },
331
+ metadata: {
332
+ category: "file",
333
+ tags: ["write", "file", "io", "create"],
334
+ version: "1.0.0"
335
+ },
336
+ execute: async (args, ctx) => {
337
+ const startTime = Date.now();
338
+ const { path: filePath, content, createDirs = false, append = false } = args;
339
+ try {
340
+ if (createDirs) {
341
+ await mkdir(dirname(filePath), { recursive: true });
342
+ }
343
+ const flags = append ? "a" : "w";
344
+ await writeFile(filePath, content, { flag: flags });
345
+ return {
346
+ success: true,
347
+ output: append ? `Content appended to: ${filePath}` : `File written: ${filePath}`,
348
+ metadata: {
349
+ execution_time_ms: Date.now() - startTime,
350
+ output_size: content.length,
351
+ file_path: filePath
352
+ }
353
+ };
354
+ } catch (error) {
355
+ return {
356
+ success: false,
357
+ output: "",
358
+ error: error instanceof Error ? error.message : String(error),
359
+ metadata: {
360
+ execution_time_ms: Date.now() - startTime
361
+ }
362
+ };
363
+ }
364
+ }
365
+ };
366
+
367
+ // packages/core/src/env/tool/built-in/edit-file.ts
368
+ import { z as z5 } from "zod";
369
+ import { readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
370
+ var editFileTool = {
371
+ name: "edit_file",
372
+ description: "Edit a file by replacing specific text. Use this to make targeted changes to files by specifying what to find and what to replace.",
373
+ parameters: z5.object({
374
+ path: z5.string().describe("The file path to edit"),
375
+ oldString: z5.string().describe("The text to find and replace"),
376
+ newString: z5.string().describe("The replacement text"),
377
+ replaceAll: z5.boolean().default(false).optional().describe("Replace all occurrences instead of just the first")
378
+ }),
379
+ sandbox: {
380
+ enabled: true,
381
+ config: {
382
+ filesystem: {
383
+ denyWrite: ["/etc", "/usr/bin", "/usr/sbin", "/bin", "/sbin"]
384
+ }
385
+ }
386
+ },
387
+ permission: {
388
+ requireConfirmation: true,
389
+ level: "dangerous"
390
+ },
391
+ metadata: {
392
+ category: "file",
393
+ tags: ["edit", "file", "replace", "modify"],
394
+ version: "1.0.0"
395
+ },
396
+ execute: async (args, ctx) => {
397
+ const startTime = Date.now();
398
+ const { path: filePath, oldString, newString, replaceAll = false } = args;
399
+ try {
400
+ const content = await readFile2(filePath, "utf-8");
401
+ const searchPattern = replaceAll ? new RegExp(escapeRegExp(oldString), "g") : new RegExp(escapeRegExp(oldString));
402
+ if (!searchPattern.test(content)) {
403
+ return {
404
+ success: false,
405
+ output: "",
406
+ error: `Could not find "${oldString}" in file ${filePath}`,
407
+ metadata: {
408
+ execution_time_ms: Date.now() - startTime
409
+ }
410
+ };
411
+ }
412
+ const newContent = replaceAll ? content.replace(new RegExp(escapeRegExp(oldString), "g"), newString) : content.replace(oldString, newString);
413
+ await writeFile2(filePath, newContent, "utf-8");
414
+ return {
415
+ success: true,
416
+ output: replaceAll ? `Replaced all occurrences in: ${filePath}` : `Replaced text in: ${filePath}`,
417
+ metadata: {
418
+ execution_time_ms: Date.now() - startTime,
419
+ file_path: filePath
420
+ }
421
+ };
422
+ } catch (error) {
423
+ return {
424
+ success: false,
425
+ output: "",
426
+ error: error instanceof Error ? error.message : String(error),
427
+ metadata: {
428
+ execution_time_ms: Date.now() - startTime
429
+ }
430
+ };
431
+ }
432
+ }
433
+ };
434
+ function escapeRegExp(string) {
435
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
436
+ }
437
+
438
+ // packages/core/src/env/tool/built-in/grep.ts
439
+ import { z as z6 } from "zod";
440
+ import { readFile as readFile3 } from "fs/promises";
441
+ import { glob as globAsync2 } from "glob";
442
+ var grepTool = {
443
+ name: "grep",
444
+ description: "Search for text patterns in files. Use this to find specific strings, code patterns, or content across multiple files.",
445
+ parameters: z6.object({
446
+ pattern: z6.string().describe("The pattern to search for"),
447
+ path: z6.string().optional().describe("File or directory path to search in"),
448
+ include: z6.string().optional().describe("Glob pattern for files to include (e.g., *.ts, *.js)"),
449
+ caseSensitive: z6.boolean().default(true).optional().describe("Whether the search should be case sensitive"),
450
+ maxResults: z6.number().int().positive().default(50).optional().describe("Maximum number of results"),
451
+ showLineNumbers: z6.boolean().default(true).optional().describe("Show line numbers in results")
452
+ }),
453
+ sandbox: {
454
+ enabled: true
455
+ },
456
+ metadata: {
457
+ category: "file",
458
+ tags: ["search", "grep", "find", "pattern"],
459
+ version: "1.0.0"
460
+ },
461
+ execute: async (args, ctx) => {
462
+ const startTime = Date.now();
463
+ const {
464
+ pattern,
465
+ path: searchPath,
466
+ include,
467
+ caseSensitive = true,
468
+ maxResults = 50,
469
+ showLineNumbers = true
470
+ } = args;
471
+ const basePath = searchPath || ctx.workdir || process.cwd();
472
+ try {
473
+ let files = [];
474
+ if (include) {
475
+ files = await globAsync2(include, {
476
+ cwd: basePath,
477
+ ignore: ["**/node_modules/**", "**/.git/**"],
478
+ maxDepth: 10
479
+ });
480
+ } else {
481
+ files = await globAsync2("**/*", {
482
+ cwd: basePath,
483
+ ignore: ["**/node_modules/**", "**/.git/**"],
484
+ maxDepth: 10
485
+ });
486
+ }
487
+ const results = [];
488
+ const regexFlags = caseSensitive ? "" : "i";
489
+ const regex = new RegExp(pattern, regexFlags);
490
+ for (const file of files) {
491
+ if (results.length >= maxResults)
492
+ break;
493
+ try {
494
+ const content = await readFile3(`${basePath}/${file}`, "utf-8");
495
+ const lines = content.split(`
496
+ `);
497
+ for (let i = 0;i < lines.length; i++) {
498
+ if (regex.test(lines[i])) {
499
+ const lineNum = showLineNumbers ? `${i + 1}:` : "";
500
+ results.push(`${file}:${lineNum}${lines[i]}`);
501
+ if (results.length >= maxResults)
502
+ break;
503
+ }
504
+ }
505
+ } catch {}
506
+ }
507
+ const output = results.join(`
508
+ `) || "(no matches found)";
509
+ return {
510
+ success: true,
511
+ output,
512
+ metadata: {
513
+ execution_time_ms: Date.now() - startTime,
514
+ output_size: output.length,
515
+ matches_count: results.length,
516
+ files_searched: files.length
517
+ }
518
+ };
519
+ } catch (error) {
520
+ return {
521
+ success: false,
522
+ output: "",
523
+ error: error instanceof Error ? error.message : String(error),
524
+ metadata: {
525
+ execution_time_ms: Date.now() - startTime
526
+ }
527
+ };
528
+ }
529
+ }
530
+ };
531
+
532
+ // packages/core/src/env/tool/built-in/index.ts
533
+ function getAllBuiltInTools() {
534
+ return [
535
+ bashTool,
536
+ echoTool,
537
+ globTool,
538
+ readFileTool,
539
+ writeFileTool,
540
+ editFileTool,
541
+ grepTool
542
+ ];
543
+ }
544
+ function getBuiltInTool(name) {
545
+ const tools = getAllBuiltInTools();
546
+ return tools.find((t) => t.name === name);
547
+ }
548
+
549
+ export { bashTool, echoTool, globTool, readFileTool, writeFileTool, editFileTool, grepTool, getAllBuiltInTools, getBuiltInTool };