@quantish/agent 0.1.13 → 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 +110 -45
  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,
@@ -2661,83 +2729,80 @@ function extractTokenInfo(token) {
2661
2729
  price: token.price ?? token.probability
2662
2730
  };
2663
2731
  }
2664
- var DEFAULT_SYSTEM_PROMPT = `You are Quantish, an AI coding and trading agent.
2665
-
2666
- CRITICAL BEHAVIOR RULES:
2667
- - Be concise. No emojis. No verbose explanations. Just code and brief descriptions.
2668
- - When debugging, check logs FIRST before restarting servers.
2669
- - If API returns found > 0, there ARE results. Read and use them.
2732
+ var DEFAULT_SYSTEM_PROMPT = `You are Quantish, an AI coding and trading agent. Be concise.
2670
2733
 
2671
- ## Two APIs
2734
+ ## APIs
2672
2735
 
2673
- TRADING API (requires QUANTISH_API_KEY):
2736
+ TRADING (requires QUANTISH_API_KEY):
2674
2737
  - URL: https://quantish-sdk-production.up.railway.app/mcp/execute
2675
- - Format: JSON-RPC 2.0
2738
+ - Format: JSON-RPC 2.0 { jsonrpc: '2.0', method: 'tools/call', params: { name, arguments }, id }
2676
2739
  - Tools: get_balances, get_positions, place_order, cancel_order, get_orders, get_orderbook, get_price
2677
2740
 
2678
- DISCOVERY API (free, public):
2741
+ DISCOVERY (free):
2679
2742
  - URL: https://quantish.live/mcp/execute
2680
- - Format: Simple { name, arguments }
2743
+ - Format: { name, arguments }
2681
2744
  - Key: qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8
2682
2745
  - Tools: search_markets, get_market_details, get_trending_markets
2683
2746
 
2684
- ## API Response Structure
2747
+ ## Response Structures (IMPORTANT - use these field paths)
2685
2748
 
2686
- search_markets returns:
2749
+ search_markets / get_trending_markets returns:
2687
2750
  {
2688
- "found": 10,
2751
+ "found": N,
2752
+ "markets": [{ "platform", "id", "title", "markets": [{ "marketId", "question", "outcomes": [{ "name", "price" }], "clobTokenIds": "[json_array]", "conditionId" }] }]
2753
+ }
2754
+
2755
+ get_market_details returns:
2756
+ {
2757
+ "platform": "polymarket",
2758
+ "id": "12345",
2759
+ "conditionId": "0x...",
2760
+ "title": "Market Title",
2761
+ "clobTokenIds": "["TOKEN_YES","TOKEN_NO"]",
2689
2762
  "markets": [{
2690
- "platform": "polymarket",
2691
- "id": "12345",
2692
- "title": "Bitcoin Up or Down - Dec 28, 5PM ET",
2693
- "markets": [{
2694
- "marketId": "67890",
2695
- "question": "Bitcoin Up or Down?",
2696
- "outcomes": [
2697
- { "name": "Up", "price": 0.52 },
2698
- { "name": "Down", "price": 0.48 }
2699
- ],
2700
- "clobTokenIds": "["TOKEN_ID_YES", "TOKEN_ID_NO"]",
2701
- "conditionId": "0xabc..."
2702
- }]
2763
+ "marketId": "67890",
2764
+ "question": "Question?",
2765
+ "outcomes": [{ "name": "Yes", "price": 0.55 }, { "name": "No", "price": 0.45 }],
2766
+ "clobTokenIds": "["TOKEN_YES","TOKEN_NO"]"
2703
2767
  }]
2704
2768
  }
2705
2769
 
2706
- To extract token IDs: JSON.parse(market.markets[0].clobTokenIds)
2707
- Outcome prices are in: market.markets[0].outcomes[].price
2770
+ KEY FIELDS:
2771
+ - market.id = top-level ID for get_market_details
2772
+ - market.markets[0].marketId = sub-market ID
2773
+ - market.markets[0].outcomes[].name = "Yes"/"No" or outcome name
2774
+ - market.markets[0].outcomes[].price = decimal 0-1
2775
+ - JSON.parse(market.clobTokenIds || market.markets[0].clobTokenIds) = token IDs array
2776
+ - market.conditionId = condition ID for trading
2708
2777
 
2709
- ## Helper Functions (copy exactly)
2778
+ ## Standalone App Code
2710
2779
 
2711
- Trading:
2780
+ Trading helper:
2712
2781
  async function callTradingTool(name, args = {}) {
2713
2782
  const res = await fetch('https://quantish-sdk-production.up.railway.app/mcp/execute', {
2714
2783
  method: 'POST',
2715
2784
  headers: { 'Content-Type': 'application/json', 'x-api-key': process.env.QUANTISH_API_KEY },
2716
2785
  body: JSON.stringify({ jsonrpc: '2.0', method: 'tools/call', params: { name, arguments: args }, id: Date.now() })
2717
2786
  });
2718
- const data = await res.json();
2719
- return JSON.parse(data.result.content[0].text);
2787
+ return JSON.parse((await res.json()).result.content[0].text);
2720
2788
  }
2721
2789
 
2722
- Discovery:
2790
+ Discovery helper:
2723
2791
  async function callDiscoveryTool(name, args = {}) {
2724
2792
  const res = await fetch('https://quantish.live/mcp/execute', {
2725
2793
  method: 'POST',
2726
2794
  headers: { 'Content-Type': 'application/json', 'X-API-Key': 'qm_ueQeqrmvZyHtR1zuVbLYkhx0fKyVAuV8' },
2727
2795
  body: JSON.stringify({ name, arguments: args })
2728
2796
  });
2729
- const data = await res.json();
2730
- return JSON.parse(data.result.content[0].text);
2797
+ return JSON.parse((await res.json()).result.content[0].text);
2731
2798
  }
2732
2799
 
2733
2800
  ## Rules
2734
-
2735
- 1. Never use @modelcontextprotocol/sdk in standalone apps - use fetch()
2736
- 2. Trading tools need QUANTISH_API_KEY. Discovery tools are free.
2737
- 3. Always create .env.example and use dotenv
2738
- 4. Never hardcode prices or mock data
2739
- 5. If found > 0, markets exist - use them
2740
- 6. Debug by reading logs, not by restarting servers repeatedly`;
2801
+ 1. Never use @modelcontextprotocol/sdk - use fetch()
2802
+ 2. Always create .env.example and use dotenv
2803
+ 3. Never hardcode/mock data - always fetch real data
2804
+ 4. Check logs before restarting servers
2805
+ 5. PREFER edit_lines over edit_file - uses line numbers, saves tokens`;
2741
2806
  var Agent = class {
2742
2807
  anthropic;
2743
2808
  mcpClient;
@@ -2838,7 +2903,7 @@ var Agent = class {
2838
2903
  * @param options - Optional configuration including abort signal
2839
2904
  */
2840
2905
  async run(userMessage, options) {
2841
- const maxIterations = this.config.maxIterations ?? 15;
2906
+ const maxIterations = this.config.maxIterations ?? 200;
2842
2907
  const model = this.config.model ?? "claude-sonnet-4-5-20250929";
2843
2908
  const maxTokens = this.config.maxTokens ?? 8192;
2844
2909
  const systemPrompt = this.config.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantish/agent",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "AI-powered agent for building trading bots on Polymarket",
5
5
  "type": "module",
6
6
  "bin": {