@datalyr/wizard 1.0.7 → 1.0.8

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.
@@ -2365,7 +2365,7 @@ async function executeAgent(params) {
2365
2365
  { role: "user", content: initialMessage }
2366
2366
  ];
2367
2367
  const filesModified = [];
2368
- const maxIterations = 20;
2368
+ const maxIterations = 30;
2369
2369
  let iterations = 0;
2370
2370
  while (iterations < maxIterations) {
2371
2371
  iterations++;
@@ -2537,6 +2537,73 @@ async function executeTool(toolUse, cwd, debug) {
2537
2537
  });
2538
2538
  return { content: files.slice(0, 100).join("\n") };
2539
2539
  }
2540
+ case "edit_file": {
2541
+ if (typeof input.path !== "string" || !input.path.trim()) {
2542
+ return { content: "Error: path must be a non-empty string", is_error: true };
2543
+ }
2544
+ if (typeof input.old_string !== "string") {
2545
+ return { content: "Error: old_string must be a string", is_error: true };
2546
+ }
2547
+ if (typeof input.new_string !== "string") {
2548
+ return { content: "Error: new_string must be a string", is_error: true };
2549
+ }
2550
+ const path3 = input.path.trim();
2551
+ const oldString = input.old_string;
2552
+ const newString = input.new_string;
2553
+ if (!isPathSafe(cwd, path3)) {
2554
+ return { content: "Error: path traversal detected - access denied", is_error: true };
2555
+ }
2556
+ const fullPath = (0, import_path3.join)(cwd, path3);
2557
+ const content = await (0, import_promises.readFile)(fullPath, "utf-8");
2558
+ const occurrences = content.split(oldString).length - 1;
2559
+ if (occurrences === 0) {
2560
+ return { content: `Error: old_string not found in ${path3}`, is_error: true };
2561
+ }
2562
+ if (occurrences > 1) {
2563
+ return { content: `Error: old_string found ${occurrences} times in ${path3} - must be unique`, is_error: true };
2564
+ }
2565
+ const newContent = content.replace(oldString, newString);
2566
+ await (0, import_promises.writeFile)(fullPath, newContent, "utf-8");
2567
+ return { content: `Successfully edited ${path3}` };
2568
+ }
2569
+ case "search_files": {
2570
+ if (typeof input.pattern !== "string" || !input.pattern.trim()) {
2571
+ return { content: "Error: pattern must be a non-empty string", is_error: true };
2572
+ }
2573
+ const searchPattern = input.pattern.trim();
2574
+ const searchPath = typeof input.path === "string" ? input.path.trim() : ".";
2575
+ const filePattern = typeof input.file_pattern === "string" ? input.file_pattern : "**/*.{ts,tsx,js,jsx,json,md}";
2576
+ if (!isPathSafe(cwd, searchPath)) {
2577
+ return { content: "Error: path traversal detected - access denied", is_error: true };
2578
+ }
2579
+ const fullPath = (0, import_path3.join)(cwd, searchPath);
2580
+ const files = await (0, import_glob2.glob)(filePattern, {
2581
+ cwd: fullPath,
2582
+ nodir: true,
2583
+ maxDepth: 5
2584
+ });
2585
+ const results = [];
2586
+ const regex = new RegExp(searchPattern, "gi");
2587
+ for (const file of files.slice(0, 50)) {
2588
+ try {
2589
+ const filePath = (0, import_path3.join)(fullPath, file);
2590
+ const content = await (0, import_promises.readFile)(filePath, "utf-8");
2591
+ const lines = content.split("\n");
2592
+ lines.forEach((line, index) => {
2593
+ if (regex.test(line)) {
2594
+ results.push(`${file}:${index + 1}: ${line.trim().slice(0, 100)}`);
2595
+ }
2596
+ regex.lastIndex = 0;
2597
+ });
2598
+ } catch {
2599
+ }
2600
+ if (results.length >= 50) break;
2601
+ }
2602
+ if (results.length === 0) {
2603
+ return { content: `No matches found for "${searchPattern}"` };
2604
+ }
2605
+ return { content: results.join("\n") };
2606
+ }
2540
2607
  default:
2541
2608
  return { content: `Unknown tool: ${name}`, is_error: true };
2542
2609
  }