@amical/aiagent-sdk 0.1.11 → 0.1.12

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/dist/index.mjs CHANGED
@@ -130,9 +130,11 @@ return (
130
130
  },
131
131
  {
132
132
  name: "agent_read_file" /* FILE_READ */,
133
- description: "Read the contents of a specific file.",
133
+ description: "Read the contents of a specific file. The returned content includes line numbers (e.g. '10|const x = 1;') so you can reference exact lines when editing.",
134
134
  params: {
135
- path: "(required) The absolute or relative file path to read."
135
+ path: "(required) The absolute or relative file path to read.",
136
+ start_line: "(optional) The 1-based line number to start reading from (inclusive). Defaults to 1.",
137
+ end_line: "(optional) The 1-based line number to stop reading at (inclusive). Defaults to the last line."
136
138
  }
137
139
  },
138
140
  {
@@ -575,7 +577,17 @@ var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
575
577
  "dockerfile",
576
578
  "makefile",
577
579
  "properties",
578
- "lock"
580
+ "lock",
581
+ "node-version",
582
+ "nvmrc",
583
+ "editorconfig",
584
+ "prettierrc",
585
+ "eslintrc",
586
+ "babelrc",
587
+ "stylelintrc",
588
+ "huskyrc",
589
+ "commitlintrc",
590
+ "lintstagedrc"
579
591
  ]);
580
592
  var AgentState = /* @__PURE__ */ ((AgentState2) => {
581
593
  AgentState2["IDLE"] = "idle";
@@ -666,6 +678,13 @@ var ClineAgent = class {
666
678
  }
667
679
  this.skillDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/skills");
668
680
  this.rulesDir = this.runtime.path.join(this.runtime.env.cwd(), ".agents/rules");
681
+ const originalOnCondense = this.memory.onCondense;
682
+ this.memory.onCondense = async () => {
683
+ this.api.clearConversationId();
684
+ if (originalOnCondense) {
685
+ await originalOnCondense();
686
+ }
687
+ };
669
688
  }
670
689
  setState(newState) {
671
690
  this.state = newState;
@@ -723,16 +742,6 @@ var ClineAgent = class {
723
742
  async getAgentRules() {
724
743
  const cwd = this.runtime.env.cwd();
725
744
  const rules = [];
726
- const agentsMdPath = this.runtime.path.join(cwd, "Agents.md");
727
- try {
728
- if (await this.runtime.fs.fileExists(agentsMdPath)) {
729
- const content = await this.runtime.fs.readFile(agentsMdPath);
730
- if (content && content.trim()) {
731
- rules.push(content.trim());
732
- }
733
- }
734
- } catch (e) {
735
- }
736
745
  try {
737
746
  if (await this.runtime.fs.fileExists(this.rulesDir)) {
738
747
  const files = await this.runtime.fs.readDir(this.rulesDir);
@@ -758,6 +767,28 @@ ${content.trim()}\`\`\``);
758
767
  }
759
768
  } catch (e) {
760
769
  }
770
+ try {
771
+ const getAgentsMdPath = async () => {
772
+ const agentsMdPathList = [
773
+ this.runtime.path.join(cwd, "AGENTS.md"),
774
+ this.runtime.path.join(cwd, "Agents.md"),
775
+ this.runtime.path.join(cwd, "agents.md")
776
+ ];
777
+ for (const item of agentsMdPathList) {
778
+ if (await this.runtime.fs.fileExists(item)) {
779
+ return item;
780
+ }
781
+ }
782
+ };
783
+ const agentsMdPath = await getAgentsMdPath();
784
+ if (agentsMdPath) {
785
+ const content = await this.runtime.fs.readFile(agentsMdPath);
786
+ if (content && content.trim()) {
787
+ rules.push(content.trim());
788
+ }
789
+ }
790
+ } catch (e) {
791
+ }
761
792
  return rules.join("\n---\n");
762
793
  }
763
794
  async getSkills() {
@@ -895,7 +926,8 @@ ${finalPrompt}` : finalPrompt;
895
926
  if (path) {
896
927
  try {
897
928
  const content = await this.runtime.fs.readFile(path);
898
- toolResults.push({ tool, result: content });
929
+ const result = this.formatFileContentWithLineNumbers(content, tool.params.start_line, tool.params.end_line);
930
+ toolResults.push({ tool, result });
899
931
  } catch (error) {
900
932
  toolResults.push({ tool, result: `Error: ${error.message}` });
901
933
  }
@@ -908,6 +940,8 @@ ${finalPrompt}` : finalPrompt;
908
940
  const result = await this.runtime.terminal.execCommand(cmd);
909
941
  toolResults.push({ tool, result: `STDOUT: ${result.stdout}
910
942
  STDERR: ${result.stderr}` });
943
+ } else {
944
+ toolResults.push({ tool, result: "Error: No command provided." });
911
945
  }
912
946
  } else if (tool.name === "agent_write_to_file" /* FILE_NEW */) {
913
947
  const path = tool.params.path;
@@ -919,12 +953,18 @@ STDERR: ${result.stderr}` });
919
953
  } catch (error) {
920
954
  toolResults.push({ tool, result: `Error: ${error.message}` });
921
955
  }
956
+ } else {
957
+ toolResults.push({ tool, result: "Error: Missing path or content." });
922
958
  }
923
959
  } else if (tool.name === "agent_list_files" /* LIST_FILES */) {
924
960
  const path = tool.params.path || this.runtime.env.cwd();
961
+ const recursive = tool.params.recursive === "true";
925
962
  try {
926
- const files = await this.runtime.fs.readDir(path);
927
- toolResults.push({ tool, result: files.map((f) => f.name + (f.isDirectory() ? "/" : "")).join("\n") });
963
+ const files = await this.runtime.fs.readDir(path, { recursive });
964
+ toolResults.push({
965
+ tool,
966
+ result: files.map((f) => `${f.isDirectory() ? "[DIR] " : " "}${f.name}${f.isDirectory() ? "/" : ""}`).join("\n")
967
+ });
928
968
  } catch (e) {
929
969
  toolResults.push({ tool, result: `Error: ${e.message}` });
930
970
  }
@@ -1064,10 +1104,15 @@ STDERR: ${result.stderr}` });
1064
1104
  try {
1065
1105
  const res = await fetch(url);
1066
1106
  const text = await res.text();
1067
- toolResults.push({ tool, result: text.substring(0, 3e3) });
1107
+ const MAX_LEN = 8e3;
1108
+ const truncated = text.length > MAX_LEN ? `${text.substring(0, MAX_LEN)}
1109
+ ...[truncated ${text.length - MAX_LEN} chars]` : text;
1110
+ toolResults.push({ tool, result: truncated });
1068
1111
  } catch (e) {
1069
1112
  toolResults.push({ tool, result: `Error: ${e.message}` });
1070
1113
  }
1114
+ } else {
1115
+ toolResults.push({ tool, result: "Error: No url provided." });
1071
1116
  }
1072
1117
  } else if (tool.name === "agent_focus_chain" /* TODO */) {
1073
1118
  toolResults.push({ tool, result: `Focus chain updated successfully.` });
@@ -1155,6 +1200,44 @@ ${this.promptManager.getUsedToolResultInstructions()}`;
1155
1200
  }
1156
1201
  return this.getPrompt();
1157
1202
  }
1203
+ /**
1204
+ * 将文件内容格式化为带行号文本(模拟编辑器行号显示),
1205
+ * 支持通过 start_line / end_line 截取读取范围。
1206
+ */
1207
+ formatFileContentWithLineNumbers(content, startLineParam, endLineParam) {
1208
+ const lines = content.split(/\r?\n/);
1209
+ const normalized = lines.length > 0 && lines[lines.length - 1] === "" ? lines.slice(0, -1) : lines;
1210
+ const total = normalized.length;
1211
+ if (total === 0) {
1212
+ return "1|(empty file)";
1213
+ }
1214
+ const parseLine = (val, fallback) => {
1215
+ if (val === void 0 || val === null || val.trim() === "") {
1216
+ return fallback;
1217
+ }
1218
+ const num = Number.parseInt(val, 10);
1219
+ if (!Number.isFinite(num) || num <= 0) {
1220
+ return fallback;
1221
+ }
1222
+ return num;
1223
+ };
1224
+ const start = parseLine(startLineParam, 1);
1225
+ const end = parseLine(endLineParam, total);
1226
+ if (start > end) {
1227
+ return `Error: start_line (${start}) cannot be greater than end_line (${end}).`;
1228
+ }
1229
+ if (start > total) {
1230
+ return `Error: start_line (${start}) is out of range. The file has ${total} lines.`;
1231
+ }
1232
+ const from = Math.max(1, start);
1233
+ const to = Math.min(total, end);
1234
+ const width = String(total).length;
1235
+ const selected = normalized.slice(from - 1, to);
1236
+ const numbered = selected.map((line, idx) => `${String(from + idx).padStart(width)}|${line}`).join("\n");
1237
+ const header = from === 1 && to === total ? `1-${total}/${total}` : `${from}-${to}/${total}`;
1238
+ return `${header}
1239
+ ${numbered}`;
1240
+ }
1158
1241
  /**
1159
1242
  * 简单的 Diff 解析与替换辅助方法
1160
1243
  */