@amical/aiagent-sdk 0.1.8 → 0.1.9

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.
@@ -550,7 +550,7 @@ var ClineAgent = class {
550
550
  }
551
551
  }
552
552
  /**
553
- * 获取当前 Agent 的系统提示词
553
+ * 获取当前 Agent 的系统提示词
554
554
  * 如果 force 为 true,则强制重新获取系统提示词
555
555
  */
556
556
  async getPrompt(force = false) {
@@ -825,15 +825,20 @@ STDERR: ${result.stderr}` });
825
825
  const path2 = tool.params.path || this.runtime.env.cwd();
826
826
  const regexStr = tool.params.regex;
827
827
  const filePattern = tool.params.file_pattern;
828
- if (regexStr && this.runtime.fs.searchFiles) {
828
+ if (regexStr && path2) {
829
829
  try {
830
- const result = await this.runtime.fs.searchFiles(path2, regexStr, filePattern);
830
+ let result;
831
+ if (typeof this.runtime.fs.searchFiles === "function") {
832
+ result = await this.runtime.fs.searchFiles(path2, regexStr, filePattern);
833
+ } else {
834
+ result = await this.searchFiles(path2, regexStr, filePattern);
835
+ }
831
836
  toolResults.push({ tool, result: `${result}` });
832
837
  } catch (e) {
833
838
  toolResults.push({ tool, result: `Error: ${e.message}` });
834
839
  }
835
840
  } else {
836
- toolResults.push({ tool, result: `Error: searchFiles not supported by runtime or missing regex.` });
841
+ toolResults.push({ tool, result: `Error: miss path or regex params` });
837
842
  }
838
843
  } else if (tool.name === "agent_use_mcp_tool" /* MCP_USE */) {
839
844
  const serverName = tool.params.server_name;
@@ -938,9 +943,14 @@ IMPORTANT: The skill is now loaded. Do NOT call agent_load_skill again for this
938
943
  }
939
944
  }
940
945
  if (this.state === "thinking" /* THINKING */ && toolResults.length > 0) {
941
- const toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
946
+ let toolResultsContext = toolResults.map((tr) => `<${TOOL_RESULT_BLOCK} tool_name="${tr.tool.name}">
942
947
  ${typeof tr.result === "string" ? tr.result.trim() : JSON.stringify(tr.result)}
943
948
  </${TOOL_RESULT_BLOCK}>`).join("\n\n");
949
+ const lastResult = toolResults[toolResults.length - 1];
950
+ if (lastResult && lastResult.tool.name !== "agent_attempt_completion" /* ATTEMPT */) {
951
+ toolResultsContext += `
952
+ ${this.promptManager.getUsedToolResultInstructions()}`;
953
+ }
944
954
  if (this.onStreamChunk) {
945
955
  this.onStreamChunk({ type: "text", text: toolResultsContext });
946
956
  }
@@ -998,6 +1008,47 @@ ${searchBlock.substring(0, 100)}...`);
998
1008
  async getHistory() {
999
1009
  return this.memory.getHistory();
1000
1010
  }
1011
+ async searchFiles(dirpath, regex, filePattern) {
1012
+ const matches = [];
1013
+ const contentRe = new RegExp(regex);
1014
+ const nameRe = filePattern ? new RegExp(filePattern.replace(/\./g, "\\.").replace(/\*/g, ".*")) : null;
1015
+ const SKIP_DIRS = /* @__PURE__ */ new Set([".git", "dist", ".agent", ".turbopack"]);
1016
+ const walk = async (dir, depth) => {
1017
+ if (depth > 8 || matches.length >= 100) {
1018
+ return;
1019
+ }
1020
+ let entries;
1021
+ try {
1022
+ entries = await this.runtime.fs.readDir(dir, { recursive: false });
1023
+ } catch {
1024
+ return;
1025
+ }
1026
+ for (const entry of entries) {
1027
+ if (matches.length >= 100) {
1028
+ break;
1029
+ }
1030
+ const child = dir === "." ? entry.name : `${dir}/${entry.name}`;
1031
+ if (entry.isDirectory()) {
1032
+ if (!SKIP_DIRS.has(entry.name)) {
1033
+ await walk(child, depth + 1);
1034
+ }
1035
+ } else if (entry.isFile()) {
1036
+ if (nameRe && !nameRe.test(entry.name)) {
1037
+ continue;
1038
+ }
1039
+ try {
1040
+ const content = (await this.runtime.fs.readFile(child, "utf8")).toString();
1041
+ if (contentRe.test(content)) {
1042
+ matches.push(child);
1043
+ }
1044
+ } catch {
1045
+ }
1046
+ }
1047
+ }
1048
+ };
1049
+ await walk(dirpath, 0);
1050
+ return matches.join("\n");
1051
+ }
1001
1052
  };
1002
1053
  var WebApiHandler = class {
1003
1054
  config;
@@ -1372,6 +1423,21 @@ Otherwise, if you have not completed the task and do not need additional informa
1372
1423
  (This is an automated message, so do not respond to it conversationally.)
1373
1424
  ${this?.getEnvironmentInfoPrompt?.(context)}`;
1374
1425
  }
1426
+ getUsedToolResultInstructions() {
1427
+ return `The above are the results of the tool call. Please continue to complete the remaining tasks.
1428
+
1429
+ # TODO LIST UPDATE REQUIRED - You MUST include the task_progress parameter in your NEXT tool call.
1430
+
1431
+ 1. To create or update a todo list, include the task_progress parameter in the next tool call
1432
+ 2. Review each item and update its status:
1433
+ - Mark completed items with: - [x]
1434
+ - Keep incomplete items as: - [ ]
1435
+ - Add new items if you discover additional steps
1436
+ 3. Modify the list as needed:
1437
+ - Add any new steps you've discovered
1438
+ - Reorder if the sequence has changed
1439
+ 4. Ensure the list accurately reflects the current state`;
1440
+ }
1375
1441
  };
1376
1442
 
1377
1443
  // src/memory/WebMemoryManager.ts
@@ -1477,8 +1543,8 @@ var DefaultWebRuntime = class {
1477
1543
  vol = new Volume();
1478
1544
  memfs = createFsFromVolume(this.vol).promises;
1479
1545
  fs = {
1480
- readFile: async (filepath) => {
1481
- const content = await this.memfs.readFile(filepath, "utf-8");
1546
+ readFile: async (filepath, options = "utf8") => {
1547
+ const content = await this.memfs.readFile(filepath, options);
1482
1548
  return content.toString();
1483
1549
  },
1484
1550
  writeFile: async (filepath, content) => {
@@ -1498,8 +1564,8 @@ var DefaultWebRuntime = class {
1498
1564
  return false;
1499
1565
  }
1500
1566
  },
1501
- readDir: (dirpath) => {
1502
- return this.memfs.readdir(dirpath, { withFileTypes: true });
1567
+ readDir: (dirpath, options) => {
1568
+ return this.memfs.readdir(dirpath, { withFileTypes: true, ...options || {} });
1503
1569
  },
1504
1570
  mkdir: async (dirpath) => {
1505
1571
  await this.memfs.mkdir(dirpath, { recursive: true });