@quantish/agent 0.1.14 → 0.1.15

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 (2) hide show
  1. package/dist/index.js +71 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -780,6 +780,41 @@ async function fileExists(filePath) {
780
780
  return { success: false, error: `Failed to check file: ${error2 instanceof Error ? error2.message : String(error2)}` };
781
781
  }
782
782
  }
783
+ async function editLines(filePath, startLine, endLine, newContent) {
784
+ try {
785
+ const resolvedPath = path.resolve(filePath);
786
+ if (!existsSync(resolvedPath)) {
787
+ return { success: false, error: `File not found: ${filePath}` };
788
+ }
789
+ const content = await fs.readFile(resolvedPath, "utf-8");
790
+ const lines = content.split("\n");
791
+ if (startLine < 1 || endLine < startLine || startLine > lines.length) {
792
+ return {
793
+ success: false,
794
+ error: `Invalid line range: ${startLine}-${endLine}. File has ${lines.length} lines.`
795
+ };
796
+ }
797
+ const startIdx = startLine - 1;
798
+ const endIdx = Math.min(endLine, lines.length);
799
+ const newLines = newContent.split("\n");
800
+ const beforeLines = lines.slice(0, startIdx);
801
+ const afterLines = lines.slice(endIdx);
802
+ const resultLines = [...beforeLines, ...newLines, ...afterLines];
803
+ const newFileContent = resultLines.join("\n");
804
+ await fs.writeFile(resolvedPath, newFileContent, "utf-8");
805
+ return {
806
+ success: true,
807
+ data: {
808
+ path: resolvedPath,
809
+ linesReplaced: endIdx - startIdx,
810
+ newLinesInserted: newLines.length,
811
+ totalLines: resultLines.length
812
+ }
813
+ };
814
+ } catch (error2) {
815
+ return { success: false, error: `Failed to edit lines: ${error2 instanceof Error ? error2.message : String(error2)}` };
816
+ }
817
+ }
783
818
  async function editFile(filePath, oldString, newString, options) {
784
819
  try {
785
820
  const resolvedPath = path.resolve(filePath);
@@ -897,9 +932,35 @@ var filesystemTools = [
897
932
  required: ["path"]
898
933
  }
899
934
  },
935
+ {
936
+ name: "edit_lines",
937
+ description: "Edit specific lines in a file by line number. MORE EFFICIENT than edit_file - use this when you know the line numbers from read_file. Only sends line numbers + new content, not full old content.",
938
+ input_schema: {
939
+ type: "object",
940
+ properties: {
941
+ path: {
942
+ type: "string",
943
+ description: "The path to the file to edit"
944
+ },
945
+ start_line: {
946
+ type: "number",
947
+ description: "The first line number to replace (1-based, inclusive)"
948
+ },
949
+ end_line: {
950
+ type: "number",
951
+ description: "The last line number to replace (1-based, inclusive)"
952
+ },
953
+ new_content: {
954
+ type: "string",
955
+ description: "The new content to insert (replaces lines start_line through end_line)"
956
+ }
957
+ },
958
+ required: ["path", "start_line", "end_line", "new_content"]
959
+ }
960
+ },
900
961
  {
901
962
  name: "edit_file",
902
- description: "Edit a file by replacing a specific string with new content. Safer than write_file as it only modifies the targeted section. The old_string must match exactly (including whitespace).",
963
+ description: "Edit a file by replacing a specific string with new content. Use edit_lines instead when you know line numbers - it uses fewer tokens.",
903
964
  input_schema: {
904
965
  type: "object",
905
966
  properties: {
@@ -1042,6 +1103,13 @@ async function executeFilesystemTool(name, args) {
1042
1103
  return deleteFile(args.path);
1043
1104
  case "file_exists":
1044
1105
  return fileExists(args.path);
1106
+ case "edit_lines":
1107
+ return editLines(
1108
+ args.path,
1109
+ args.start_line,
1110
+ args.end_line,
1111
+ args.new_content
1112
+ );
1045
1113
  case "edit_file":
1046
1114
  return editFile(
1047
1115
  args.path,
@@ -2733,7 +2801,8 @@ async function callDiscoveryTool(name, args = {}) {
2733
2801
  1. Never use @modelcontextprotocol/sdk - use fetch()
2734
2802
  2. Always create .env.example and use dotenv
2735
2803
  3. Never hardcode/mock data - always fetch real data
2736
- 4. Check logs before restarting servers`;
2804
+ 4. Check logs before restarting servers
2805
+ 5. PREFER edit_lines over edit_file - uses line numbers, saves tokens`;
2737
2806
  var Agent = class {
2738
2807
  anthropic;
2739
2808
  mcpClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantish/agent",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "AI-powered agent for building trading bots on Polymarket",
5
5
  "type": "module",
6
6
  "bin": {