wave-agent-sdk 0.11.6 → 0.11.7

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 (105) hide show
  1. package/builtin/skills/init/SKILL.md +2 -0
  2. package/builtin/skills/settings/SKILLS.md +3 -2
  3. package/builtin/skills/settings/SUBAGENTS.md +1 -3
  4. package/dist/agent.d.ts +6 -0
  5. package/dist/agent.d.ts.map +1 -1
  6. package/dist/agent.js +18 -1
  7. package/dist/constants/tools.d.ts +1 -1
  8. package/dist/constants/tools.d.ts.map +1 -1
  9. package/dist/constants/tools.js +1 -1
  10. package/dist/managers/MemoryRuleManager.d.ts.map +1 -1
  11. package/dist/managers/MemoryRuleManager.js +1 -9
  12. package/dist/managers/aiManager.d.ts.map +1 -1
  13. package/dist/managers/aiManager.js +22 -3
  14. package/dist/managers/messageManager.d.ts +13 -5
  15. package/dist/managers/messageManager.d.ts.map +1 -1
  16. package/dist/managers/messageManager.js +62 -34
  17. package/dist/managers/pluginManager.d.ts.map +1 -1
  18. package/dist/managers/pluginManager.js +4 -2
  19. package/dist/managers/slashCommandManager.d.ts +2 -0
  20. package/dist/managers/slashCommandManager.d.ts.map +1 -1
  21. package/dist/managers/slashCommandManager.js +98 -4
  22. package/dist/managers/toolManager.d.ts.map +1 -1
  23. package/dist/managers/toolManager.js +8 -2
  24. package/dist/prompts/index.d.ts +2 -0
  25. package/dist/prompts/index.d.ts.map +1 -1
  26. package/dist/prompts/index.js +5 -0
  27. package/dist/services/GitService.d.ts +1 -0
  28. package/dist/services/GitService.d.ts.map +1 -1
  29. package/dist/services/GitService.js +16 -0
  30. package/dist/services/MarketplaceService.d.ts +7 -0
  31. package/dist/services/MarketplaceService.d.ts.map +1 -1
  32. package/dist/services/MarketplaceService.js +321 -252
  33. package/dist/services/aiService.d.ts +34 -0
  34. package/dist/services/aiService.d.ts.map +1 -1
  35. package/dist/services/aiService.js +124 -1
  36. package/dist/services/initializationService.d.ts.map +1 -1
  37. package/dist/services/initializationService.js +18 -0
  38. package/dist/tools/agentTool.js +3 -3
  39. package/dist/tools/bashTool.d.ts.map +1 -1
  40. package/dist/tools/bashTool.js +4 -4
  41. package/dist/tools/editTool.d.ts.map +1 -1
  42. package/dist/tools/editTool.js +2 -0
  43. package/dist/tools/globTool.d.ts.map +1 -1
  44. package/dist/tools/globTool.js +15 -3
  45. package/dist/tools/grepTool.d.ts.map +1 -1
  46. package/dist/tools/grepTool.js +38 -12
  47. package/dist/tools/readTool.d.ts.map +1 -1
  48. package/dist/tools/readTool.js +61 -0
  49. package/dist/tools/skillTool.js +2 -2
  50. package/dist/tools/types.d.ts +16 -0
  51. package/dist/tools/types.d.ts.map +1 -1
  52. package/dist/tools/webFetchTool.d.ts +3 -0
  53. package/dist/tools/webFetchTool.d.ts.map +1 -0
  54. package/dist/tools/webFetchTool.js +171 -0
  55. package/dist/tools/writeTool.d.ts.map +1 -1
  56. package/dist/tools/writeTool.js +2 -0
  57. package/dist/types/commands.d.ts +1 -1
  58. package/dist/types/commands.d.ts.map +1 -1
  59. package/dist/types/messaging.d.ts +1 -0
  60. package/dist/types/messaging.d.ts.map +1 -1
  61. package/dist/utils/bashParser.d.ts +14 -0
  62. package/dist/utils/bashParser.d.ts.map +1 -1
  63. package/dist/utils/bashParser.js +243 -142
  64. package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
  65. package/dist/utils/convertMessagesForAPI.js +7 -0
  66. package/dist/utils/fileUtils.d.ts +8 -0
  67. package/dist/utils/fileUtils.d.ts.map +1 -1
  68. package/dist/utils/fileUtils.js +52 -0
  69. package/dist/utils/messageOperations.d.ts +12 -3
  70. package/dist/utils/messageOperations.d.ts.map +1 -1
  71. package/dist/utils/messageOperations.js +77 -9
  72. package/package.json +4 -2
  73. package/src/agent.ts +19 -1
  74. package/src/constants/tools.ts +1 -1
  75. package/src/managers/MemoryRuleManager.ts +1 -10
  76. package/src/managers/aiManager.ts +23 -3
  77. package/src/managers/messageManager.ts +76 -38
  78. package/src/managers/pluginManager.ts +4 -2
  79. package/src/managers/slashCommandManager.ts +130 -4
  80. package/src/managers/toolManager.ts +11 -2
  81. package/src/prompts/index.ts +6 -0
  82. package/src/services/GitService.ts +20 -0
  83. package/src/services/MarketplaceService.ts +397 -324
  84. package/src/services/aiService.ts +197 -1
  85. package/src/services/initializationService.ts +38 -0
  86. package/src/tools/agentTool.ts +3 -3
  87. package/src/tools/bashTool.ts +3 -4
  88. package/src/tools/editTool.ts +3 -0
  89. package/src/tools/globTool.ts +16 -3
  90. package/src/tools/grepTool.ts +41 -13
  91. package/src/tools/readTool.ts +69 -0
  92. package/src/tools/skillTool.ts +2 -2
  93. package/src/tools/types.ts +13 -0
  94. package/src/tools/webFetchTool.ts +194 -0
  95. package/src/tools/writeTool.ts +3 -0
  96. package/src/types/commands.ts +1 -1
  97. package/src/types/messaging.ts +1 -0
  98. package/src/utils/bashParser.ts +268 -157
  99. package/src/utils/convertMessagesForAPI.ts +8 -0
  100. package/src/utils/fileUtils.ts +69 -0
  101. package/src/utils/messageOperations.ts +84 -9
  102. package/dist/tools/taskOutputTool.d.ts +0 -3
  103. package/dist/tools/taskOutputTool.d.ts.map +0 -1
  104. package/dist/tools/taskOutputTool.js +0 -198
  105. package/src/tools/taskOutputTool.ts +0 -222
@@ -411,13 +411,139 @@ export const DANGEROUS_COMMANDS = [
411
411
  "chown",
412
412
  "sh",
413
413
  "bash",
414
+ "zsh",
415
+ "fish",
416
+ "pwsh",
417
+ "cmd.exe",
418
+ "powershell.exe",
414
419
  "sudo",
415
420
  "dd",
416
421
  "apt",
417
422
  "apt-get",
418
423
  "yum",
419
424
  "dnf",
425
+ "ssh",
426
+ "scp",
427
+ "sftp",
428
+ "ftp",
429
+ "telnet",
430
+ "nc",
431
+ "netcat",
420
432
  ];
433
+ export const TOOL_RULES = {
434
+ // Node/JS
435
+ npm: { depth: 2, scopeFlags: ["--prefix", "-C", "--registry"] },
436
+ "npm run": { depth: 3, scopeFlags: ["--prefix", "-C", "--registry"] },
437
+ pnpm: { depth: 2, scopeFlags: ["-C", "--dir", "-F", "--filter"] },
438
+ "pnpm run": { depth: 3, scopeFlags: ["-C", "--dir", "-F", "--filter"] },
439
+ yarn: { depth: 2, scopeFlags: ["workspace", "--cwd"] },
440
+ "yarn run": { depth: 3, scopeFlags: ["workspace", "--cwd"] },
441
+ "yarn workspace": { depth: 4, scopeFlags: ["--cwd"] },
442
+ bun: { depth: 2 },
443
+ "bun run": { depth: 3 },
444
+ deno: { depth: 2 },
445
+ "deno run": { depth: 3 },
446
+ "deno task": { depth: 3 },
447
+ // Git
448
+ git: {
449
+ depth: 2,
450
+ scopeFlags: ["-C", "-c", "--directory", "--work-tree", "--git-dir"],
451
+ },
452
+ // Python
453
+ python: { depth: 2 },
454
+ python3: { depth: 2 },
455
+ "python -m": { depth: 2 },
456
+ "python3 -m": { depth: 2 },
457
+ "python -m pip install": { depth: 3 },
458
+ "python3 -m pip install": { depth: 3 },
459
+ pip: { depth: 2 },
460
+ pip3: { depth: 2 },
461
+ poetry: { depth: 2 },
462
+ conda: { depth: 2 },
463
+ // Java
464
+ mvn: { depth: 2 },
465
+ gradle: { depth: 2 },
466
+ java: { depth: 1 },
467
+ "java -jar": { depth: 1 },
468
+ // Rust & Go
469
+ cargo: { depth: 2 },
470
+ go: { depth: 2 },
471
+ // Containers & Infrastructure
472
+ docker: { depth: 2 },
473
+ "docker-compose": { depth: 2 },
474
+ kubectl: { depth: 2 },
475
+ terraform: { depth: 2 },
476
+ gcloud: { depth: 2 },
477
+ "gcloud compute": { depth: 4 },
478
+ "gcloud container": { depth: 4 },
479
+ aws: { depth: 2 },
480
+ };
481
+ /**
482
+ * Registry of dangerous subcommands for specific tools.
483
+ */
484
+ export const DANGEROUS_SUBCOMMANDS = {
485
+ docker: ["rm", "rmi", "system", "volume", "network", "image", "container"],
486
+ git: ["reset", "clean"],
487
+ npm: ["uninstall", "un", "remove", "rm"],
488
+ pnpm: ["uninstall", "un", "remove", "rm"],
489
+ yarn: ["remove"],
490
+ deno: ["uninstall"],
491
+ bun: ["remove", "rm"],
492
+ };
493
+ /**
494
+ * Heuristic to determine if a flag takes an argument.
495
+ * If nextArg doesn't start with '-' and isn't a known subcommand, assume it's a flag value.
496
+ */
497
+ function flagTakesArg(flag, nextArg) {
498
+ if (!nextArg)
499
+ return false;
500
+ if (nextArg.startsWith("-"))
501
+ return false;
502
+ // If it's a common subcommand, it's probably not a flag argument
503
+ const commonSubcommands = [
504
+ "install",
505
+ "add",
506
+ "remove",
507
+ "run",
508
+ "test",
509
+ "build",
510
+ "status",
511
+ "diff",
512
+ "commit",
513
+ "push",
514
+ "pull",
515
+ "checkout",
516
+ "log",
517
+ "fetch",
518
+ "merge",
519
+ "rebase",
520
+ ];
521
+ if (commonSubcommands.includes(nextArg))
522
+ return false;
523
+ return true;
524
+ }
525
+ /**
526
+ * Detects if an argument is a file path or URL.
527
+ */
528
+ function shouldStopAtArg(arg) {
529
+ if (!arg)
530
+ return false;
531
+ // URLs
532
+ if (/^(https?|ftp|ssh|git):\/\//.test(arg))
533
+ return true;
534
+ // File paths (starts with /, ./, ../, or ~/)
535
+ if (arg.startsWith("/") ||
536
+ arg.startsWith("./") ||
537
+ arg.startsWith("../") ||
538
+ arg.startsWith("~/"))
539
+ return true;
540
+ // Common file extensions (but not scoped packages or common subcommands)
541
+ if (/\.(ts|js|py|sh|md|txt|json|yml|yaml|html|css|go|rs|java|cpp|c|h|php|rb|pl|sql)$/.test(arg) &&
542
+ !arg.includes("@") &&
543
+ !arg.includes("/"))
544
+ return true;
545
+ return false;
546
+ }
421
547
  /**
422
548
  * Extracts a "smart prefix" from a bash command based on common developer tools.
423
549
  * Returns null if the command is blacklisted or cannot be safely prefix-matched.
@@ -429,167 +555,142 @@ export function getSmartPrefix(command) {
429
555
  // For now, we only support prefix matching for single commands or the first command in a chain
430
556
  // to keep it simple and safe.
431
557
  const firstCommand = parts[0];
432
- let stripped = stripRedirections(stripEnvVars(firstCommand));
433
- // Handle sudo
434
- if (stripped.startsWith("sudo ")) {
435
- stripped = stripped.substring(5).trim();
436
- }
558
+ // Safety check: don't allow heredoc writes
559
+ if (isBashHeredocWrite(firstCommand))
560
+ return null;
561
+ const stripped = stripRedirections(stripEnvVars(firstCommand));
437
562
  const tokens = stripped.split(/\s+/);
438
563
  if (tokens.length === 0)
439
564
  return null;
440
- const exe = tokens[0];
441
- const sub = tokens[1];
565
+ const prefixParts = [];
566
+ let i = 0;
567
+ // Handle prefix tools like sudo
568
+ const prefixTools = ["sudo", "time", "stdbuf", "timeout"];
569
+ while (i < tokens.length && prefixTools.includes(tokens[i])) {
570
+ prefixParts.push(tokens[i]);
571
+ i++;
572
+ }
573
+ if (i >= tokens.length)
574
+ return null;
575
+ const exe = tokens[i];
442
576
  // Blacklist - Hard blacklist for dangerous commands
443
577
  if (DANGEROUS_COMMANDS.includes(exe))
444
578
  return null;
445
- // Node/JS
446
- if (["npm", "pnpm", "yarn", "deno", "bun"].includes(exe)) {
447
- let currentIdx = 1;
448
- const prefixParts = [exe];
449
- // Handle workspace/filter flags
450
- if (exe === "pnpm") {
451
- while ((tokens[currentIdx] === "-F" || tokens[currentIdx] === "--filter") &&
452
- tokens[currentIdx + 1]) {
453
- prefixParts.push(tokens[currentIdx], tokens[currentIdx + 1]);
454
- currentIdx += 2;
579
+ // Find the longest matching rule in TOOL_RULES
580
+ let bestRuleKey = "";
581
+ let rule;
582
+ for (const [key, r] of Object.entries(TOOL_RULES)) {
583
+ const keyTokens = key.split(/\s+/);
584
+ let match = true;
585
+ for (let j = 0; j < keyTokens.length; j++) {
586
+ if (tokens[i + j] !== keyTokens[j]) {
587
+ match = false;
588
+ break;
455
589
  }
456
590
  }
457
- else if (exe === "npm" &&
458
- (tokens[currentIdx] === "--prefix" || tokens[currentIdx] === "-C") &&
459
- tokens[currentIdx + 1]) {
460
- prefixParts.push(tokens[currentIdx], tokens[currentIdx + 1]);
461
- currentIdx += 2;
462
- }
463
- else if (exe === "yarn" &&
464
- tokens[currentIdx] === "workspace" &&
465
- tokens[currentIdx + 1]) {
466
- prefixParts.push(tokens[currentIdx], tokens[currentIdx + 1]);
467
- currentIdx += 2;
468
- }
469
- const subCommand = tokens[currentIdx];
470
- const safeSubcommands = [
471
- "install",
472
- "i",
473
- "add",
474
- "remove",
475
- "rm",
476
- "uninstall",
477
- "un",
478
- "test",
479
- "t",
480
- "build",
481
- "start",
482
- "dev",
483
- ];
484
- if (safeSubcommands.includes(subCommand)) {
485
- prefixParts.push(subCommand);
486
- return prefixParts.join(" ");
487
- }
488
- if ((subCommand === "run" || (exe === "deno" && subCommand === "task")) &&
489
- tokens[currentIdx + 1]) {
490
- prefixParts.push(subCommand, tokens[currentIdx + 1]);
491
- return prefixParts.join(" ");
591
+ if (match && key.length > bestRuleKey.length) {
592
+ bestRuleKey = key;
593
+ rule = r;
492
594
  }
493
- return null;
494
595
  }
495
- // Git
496
- if (exe === "git") {
497
- let currentIdx = 1;
498
- const prefixParts = [exe];
499
- // Handle -C <path>
500
- if (tokens[currentIdx] === "-C" && tokens[currentIdx + 1]) {
501
- prefixParts.push(tokens[currentIdx], tokens[currentIdx + 1]);
502
- currentIdx += 2;
503
- }
504
- const subCommand = tokens[currentIdx];
505
- const safeGitSubcommands = [
506
- "commit",
507
- "push",
508
- "pull",
509
- "checkout",
510
- "add",
511
- "status",
512
- "diff",
513
- "branch",
514
- "merge",
515
- "rebase",
516
- "log",
517
- "fetch",
518
- "remote",
519
- "stash",
520
- ];
521
- if (safeGitSubcommands.includes(subCommand)) {
522
- if (subCommand === "branch") {
523
- // Check for destructive flags
524
- const destructiveFlags = ["-d", "-D", "--delete"];
525
- if (tokens.some((t) => destructiveFlags.includes(t))) {
526
- return null;
527
- }
528
- }
529
- prefixParts.push(subCommand);
530
- return prefixParts.join(" ");
531
- }
596
+ // If no rule found, we don't suggest a prefix
597
+ if (!rule)
532
598
  return null;
533
- }
534
- // Python
535
- if (["python", "python3", "pip", "pip3", "poetry", "conda"].includes(exe)) {
536
- if (exe === "python" || exe === "python3") {
537
- if (tokens[1] === "-m" && tokens[2]) {
538
- if (tokens[2] === "pip" && tokens[3] === "install") {
539
- return `${exe} -m pip install`;
540
- }
541
- return `${exe} -m ${tokens[2]}`;
542
- }
543
- return null;
599
+ const depth = rule.depth;
600
+ const scopeFlags = rule.scopeFlags || [];
601
+ let currentDepth = 0;
602
+ // Safety check: only allow safe subcommands for git
603
+ const safeGitSubcommands = [
604
+ "commit",
605
+ "push",
606
+ "pull",
607
+ "checkout",
608
+ "add",
609
+ "status",
610
+ "diff",
611
+ "branch",
612
+ "merge",
613
+ "rebase",
614
+ "log",
615
+ "fetch",
616
+ "remote",
617
+ "stash",
618
+ ];
619
+ const destructiveGitFlags = [
620
+ "-d",
621
+ "-D",
622
+ "--delete",
623
+ "--hard",
624
+ "--force",
625
+ "-f",
626
+ ];
627
+ // Global safety check: scan ALL tokens for dangerous flags/subcommands
628
+ for (let j = i; j < tokens.length; j++) {
629
+ const token = tokens[j];
630
+ if (token.startsWith("-")) {
631
+ if (exe === "git" && destructiveGitFlags.includes(token))
632
+ return null;
544
633
  }
545
- if (["install", "add", "remove", "test", "run"].includes(sub)) {
546
- return `${exe} ${sub}`;
547
- }
548
- return null;
549
- }
550
- // Java
551
- if (["mvn", "gradle"].includes(exe)) {
552
- if (sub && !sub.startsWith("-")) {
553
- return `${exe} ${sub}`;
634
+ else {
635
+ if (DANGEROUS_SUBCOMMANDS[exe]?.includes(token))
636
+ return null;
554
637
  }
555
- return null;
556
- }
557
- if (exe === "java") {
558
- if (sub === "-jar")
559
- return "java -jar";
560
- return "java";
561
638
  }
562
- // Rust & Go
563
- if (exe === "cargo") {
564
- if (["build", "test", "run", "add", "check"].includes(sub)) {
565
- return `${exe} ${sub}`;
639
+ // Include all tokens from the best matching rule
640
+ const ruleTokens = bestRuleKey.split(/\s+/);
641
+ for (let j = 0; j < ruleTokens.length; j++) {
642
+ const token = tokens[i];
643
+ if (!token)
644
+ break;
645
+ if (token.startsWith("-")) {
646
+ if (exe === "git" && destructiveGitFlags.includes(token))
647
+ return null;
566
648
  }
567
- return null;
568
- }
569
- if (exe === "go") {
570
- if (["build", "test", "run", "get", "mod"].includes(sub)) {
571
- return `${exe} ${sub}`;
649
+ else {
650
+ if (DANGEROUS_SUBCOMMANDS[exe]?.includes(token))
651
+ return null;
652
+ if (exe === "git" &&
653
+ currentDepth > 0 &&
654
+ !safeGitSubcommands.includes(token)) {
655
+ return null;
656
+ }
657
+ currentDepth++;
572
658
  }
573
- return null;
659
+ prefixParts.push(token);
660
+ i++;
574
661
  }
575
- // Containers & Infrastructure
576
- if (exe === "docker" || exe === "docker-compose") {
577
- if (["run", "build", "ps", "exec", "up", "down"].includes(sub)) {
578
- return `${exe} ${sub}`;
662
+ // Continue until we reach the required depth
663
+ while (i < tokens.length && currentDepth < depth) {
664
+ const token = tokens[i];
665
+ if (token.startsWith("-")) {
666
+ // Safety checks for flags
667
+ if (exe === "git" && destructiveGitFlags.includes(token))
668
+ return null;
669
+ prefixParts.push(token);
670
+ if (scopeFlags.includes(token) || flagTakesArg(token, tokens[i + 1])) {
671
+ if (i + 1 < tokens.length) {
672
+ prefixParts.push(tokens[++i]);
673
+ }
674
+ }
579
675
  }
580
- return null;
581
- }
582
- if (exe === "kubectl") {
583
- if (["get", "describe", "apply", "logs"].includes(sub)) {
584
- return `${exe} ${sub}`;
676
+ else {
677
+ // Safety checks for subcommands
678
+ if (DANGEROUS_SUBCOMMANDS[exe]?.includes(token))
679
+ return null;
680
+ if (exe === "git" &&
681
+ currentDepth > 0 &&
682
+ !safeGitSubcommands.includes(token)) {
683
+ return null;
684
+ }
685
+ // Stop at data/paths
686
+ if (shouldStopAtArg(token) && currentDepth > 0)
687
+ break;
688
+ prefixParts.push(token);
689
+ currentDepth++;
585
690
  }
586
- return null;
691
+ i++;
587
692
  }
588
- if (exe === "terraform") {
589
- if (["plan", "apply", "destroy", "init"].includes(sub)) {
590
- return `${exe} ${sub}`;
591
- }
693
+ if (currentDepth < depth)
592
694
  return null;
593
- }
594
- return null;
695
+ return prefixParts.join(" ");
595
696
  }
@@ -1 +1 @@
1
- {"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AA0B7B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CAsN9B"}
1
+ {"version":3,"file":"convertMessagesForAPI.d.ts","sourceRoot":"","sources":["../../src/utils/convertMessagesForAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAIjD,OAAO,EAEL,0BAA0B,EAC3B,MAAM,qBAAqB,CAAC;AA0B7B;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,OAAO,EAAE,GAClB,0BAA0B,EAAE,CA8N9B"}
@@ -182,6 +182,13 @@ export function convertMessagesForAPI(messages) {
182
182
  });
183
183
  });
184
184
  }
185
+ // If there is a tool block in user message, add its result
186
+ if (block.type === "tool" && block.stage === "end" && block.result) {
187
+ contentParts.push({
188
+ type: "text",
189
+ text: `<local-command-stdout>\n${stripAnsiColors(block.result)}\n</local-command-stdout>`,
190
+ });
191
+ }
185
192
  });
186
193
  // Only add user message if there is meaningful content
187
194
  if (contentParts.length > 0) {
@@ -24,4 +24,12 @@ export declare function getLastLine(filePath: string, minLength?: number): Promi
24
24
  * @param {string} pattern - The pattern to add to global git ignore.
25
25
  */
26
26
  export declare function ensureGlobalGitIgnore(pattern: string): Promise<void>;
27
+ /**
28
+ * Suggests similar paths if a file is not found.
29
+ */
30
+ export declare function suggestPathUnderCwd(targetPath: string, workdir: string): Promise<string[]>;
31
+ /**
32
+ * Uses fuzzy matching to find the intended file.
33
+ */
34
+ export declare function findSimilarFile(targetPath: string, workdir: string): Promise<string | null>;
27
35
  //# sourceMappingURL=fileUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fileUtils.d.ts","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAI,GACZ,OAAO,CAAC,MAAM,CAAC,CA8DjB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC1E"}
1
+ {"version":3,"file":"fileUtils.d.ts","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,SAAI,GACZ,OAAO,CAAC,MAAM,CAAC,CA8DjB;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC1E;AA2BD;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,EAAE,CAAC,CAwBnB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGxB"}
@@ -3,6 +3,7 @@ import { createReadStream } from "node:fs";
3
3
  import path from "node:path";
4
4
  import { execSync } from "node:child_process";
5
5
  import { homedir } from "node:os";
6
+ import { glob } from "glob";
6
7
  /**
7
8
  * Reads the first line of a file efficiently using Node.js readline.
8
9
  *
@@ -143,3 +144,54 @@ export async function ensureGlobalGitIgnore(pattern) {
143
144
  // Ignore errors
144
145
  }
145
146
  }
147
+ /**
148
+ * Simple Levenshtein distance implementation
149
+ */
150
+ function levenshtein(a, b) {
151
+ const matrix = Array.from({ length: a.length + 1 }, () => Array.from({ length: b.length + 1 }, () => 0));
152
+ for (let i = 0; i <= a.length; i++)
153
+ matrix[i][0] = i;
154
+ for (let j = 0; j <= b.length; j++)
155
+ matrix[0][j] = j;
156
+ for (let i = 1; i <= a.length; i++) {
157
+ for (let j = 1; j <= b.length; j++) {
158
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
159
+ matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
160
+ }
161
+ }
162
+ return matrix[a.length][b.length];
163
+ }
164
+ /**
165
+ * Suggests similar paths if a file is not found.
166
+ */
167
+ export async function suggestPathUnderCwd(targetPath, workdir) {
168
+ try {
169
+ const allFiles = await glob("**/*", {
170
+ cwd: workdir,
171
+ nodir: true,
172
+ dot: true,
173
+ ignore: ["**/.git/**", "**/node_modules/**"],
174
+ });
175
+ const targetBasename = path.basename(targetPath);
176
+ const suggestions = allFiles
177
+ .map((file) => ({
178
+ path: file,
179
+ distance: levenshtein(targetBasename, path.basename(file)),
180
+ }))
181
+ .filter((item) => item.distance <= 3) // Threshold for similarity
182
+ .sort((a, b) => a.distance - b.distance)
183
+ .slice(0, 5)
184
+ .map((item) => item.path);
185
+ return suggestions;
186
+ }
187
+ catch {
188
+ return [];
189
+ }
190
+ }
191
+ /**
192
+ * Uses fuzzy matching to find the intended file.
193
+ */
194
+ export async function findSimilarFile(targetPath, workdir) {
195
+ const suggestions = await suggestPathUnderCwd(targetPath, workdir);
196
+ return suggestions.length > 0 ? suggestions[0] : null;
197
+ }
@@ -9,6 +9,7 @@ export interface UserMessageParams {
9
9
  }>;
10
10
  customCommandContent?: string;
11
11
  source?: MessageSource;
12
+ isMeta?: boolean;
12
13
  }
13
14
  export interface AddUserMessageParams extends UserMessageParams {
14
15
  messages: Message[];
@@ -17,6 +18,7 @@ export interface AddUserMessageParams extends UserMessageParams {
17
18
  export interface UpdateToolBlockParams {
18
19
  messages: Message[];
19
20
  id: string;
21
+ messageId?: string;
20
22
  parameters?: string;
21
23
  result?: string;
22
24
  success?: boolean;
@@ -28,7 +30,7 @@ export interface UpdateToolBlockParams {
28
30
  * - 'running': Tool execution in progress
29
31
  * - 'end': Tool execution completed with final result
30
32
  */
31
- stage: "start" | "streaming" | "running" | "end";
33
+ stage?: "start" | "streaming" | "running" | "end";
32
34
  name?: string;
33
35
  shortResult?: string;
34
36
  startLineNumber?: number;
@@ -67,13 +69,20 @@ export interface CompleteBangParams {
67
69
  */
68
70
  export declare const convertImageToBase64: (imagePath: string) => string;
69
71
  export declare const generateMessageId: () => string;
70
- export declare const addUserMessageToMessages: ({ messages, content, images, customCommandContent, source, id, }: AddUserMessageParams) => Message[];
72
+ export declare const addUserMessageToMessages: ({ messages, content, images, customCommandContent, source, id, isMeta, }: AddUserMessageParams) => Message[];
71
73
  /**
72
74
  * Update a user message's content or customCommandContent by its ID.
73
75
  */
74
76
  export declare const updateUserMessageInMessages: (messages: Message[], id: string, params: Partial<UserMessageParams>) => Message[];
75
77
  export declare const addAssistantMessageToMessages: (messages: Message[], content?: string, toolCalls?: ChatCompletionMessageFunctionToolCall[], usage?: Usage, additionalFields?: Record<string, unknown>) => Message[];
76
- export declare const updateToolBlockInMessage: ({ messages, id, parameters, result, success, error, stage, name, shortResult, startLineNumber, images, compactParams, parametersChunk, isManuallyBackgrounded, }: UpdateToolBlockParams) => Message[];
78
+ /**
79
+ * Add a tool block to a specific message by ID.
80
+ */
81
+ export declare const addToolBlockToMessageInMessages: (messages: Message[], messageId: string, params: Omit<AgentToolBlockUpdateParams, "id">) => {
82
+ messages: Message[];
83
+ toolBlockId: string;
84
+ };
85
+ export declare const updateToolBlockInMessage: ({ messages, id, messageId, parameters, result, success, error, stage, name, shortResult, startLineNumber, images, compactParams, parametersChunk, isManuallyBackgrounded, }: UpdateToolBlockParams) => Message[];
77
86
  export declare const addErrorBlockToMessage: ({ messages, error, }: AddErrorBlockParams) => Message[];
78
87
  export declare const addBangMessage: ({ messages, command, }: AddBangParams) => Message[];
79
88
  export declare const updateBangInMessage: ({ messages, command, output, }: UpdateBangParams) => Message[];
@@ -1 +1 @@
1
- {"version":3,"file":"messageOperations.d.ts","sourceRoot":"","sources":["../../src/utils/messageOperations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AAI5E,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAGD,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC7D,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,K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