@probelabs/probe 0.6.0-rc254 → 0.6.0-rc256

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 (53) hide show
  1. package/README.md +166 -3
  2. package/bin/binaries/probe-v0.6.0-rc256-aarch64-apple-darwin.tar.gz +0 -0
  3. package/bin/binaries/probe-v0.6.0-rc256-aarch64-unknown-linux-musl.tar.gz +0 -0
  4. package/bin/binaries/probe-v0.6.0-rc256-x86_64-apple-darwin.tar.gz +0 -0
  5. package/bin/binaries/probe-v0.6.0-rc256-x86_64-pc-windows-msvc.zip +0 -0
  6. package/bin/binaries/probe-v0.6.0-rc256-x86_64-unknown-linux-musl.tar.gz +0 -0
  7. package/build/agent/ProbeAgent.d.ts +1 -1
  8. package/build/agent/ProbeAgent.js +39 -23
  9. package/build/agent/acp/tools.js +2 -1
  10. package/build/agent/acp/tools.test.js +2 -1
  11. package/build/agent/bashDefaults.js +75 -6
  12. package/build/agent/index.js +1752 -426
  13. package/build/agent/mcp/xmlBridge.js +3 -2
  14. package/build/agent/schemaUtils.js +127 -0
  15. package/build/agent/tools.js +0 -28
  16. package/build/delegate.js +3 -0
  17. package/build/index.js +2 -0
  18. package/build/tools/common.js +26 -8
  19. package/build/tools/edit.js +457 -65
  20. package/build/tools/fileTracker.js +318 -0
  21. package/build/tools/fuzzyMatch.js +271 -0
  22. package/build/tools/hashline.js +131 -0
  23. package/build/tools/lineEditHeuristics.js +138 -0
  24. package/build/tools/symbolEdit.js +119 -0
  25. package/build/tools/vercel.js +40 -9
  26. package/cjs/agent/ProbeAgent.cjs +1863 -528
  27. package/cjs/index.cjs +1891 -554
  28. package/index.d.ts +189 -1
  29. package/package.json +1 -1
  30. package/src/agent/ProbeAgent.d.ts +1 -1
  31. package/src/agent/ProbeAgent.js +39 -23
  32. package/src/agent/acp/tools.js +2 -1
  33. package/src/agent/acp/tools.test.js +2 -1
  34. package/src/agent/bashDefaults.js +75 -6
  35. package/src/agent/index.js +18 -7
  36. package/src/agent/mcp/xmlBridge.js +3 -2
  37. package/src/agent/schemaUtils.js +127 -0
  38. package/src/agent/tools.js +0 -28
  39. package/src/delegate.js +3 -0
  40. package/src/index.js +2 -0
  41. package/src/tools/common.js +26 -8
  42. package/src/tools/edit.js +457 -65
  43. package/src/tools/fileTracker.js +318 -0
  44. package/src/tools/fuzzyMatch.js +271 -0
  45. package/src/tools/hashline.js +131 -0
  46. package/src/tools/lineEditHeuristics.js +138 -0
  47. package/src/tools/symbolEdit.js +119 -0
  48. package/src/tools/vercel.js +40 -9
  49. package/bin/binaries/probe-v0.6.0-rc254-aarch64-apple-darwin.tar.gz +0 -0
  50. package/bin/binaries/probe-v0.6.0-rc254-aarch64-unknown-linux-musl.tar.gz +0 -0
  51. package/bin/binaries/probe-v0.6.0-rc254-x86_64-apple-darwin.tar.gz +0 -0
  52. package/bin/binaries/probe-v0.6.0-rc254-x86_64-pc-windows-msvc.zip +0 -0
  53. package/bin/binaries/probe-v0.6.0-rc254-x86_64-unknown-linux-musl.tar.gz +0 -0
package/index.d.ts CHANGED
@@ -13,8 +13,10 @@ export interface ProbeAgentOptions {
13
13
  systemPrompt?: string;
14
14
  /** Predefined prompt type (persona) */
15
15
  promptType?: 'code-explorer' | 'engineer' | 'code-review' | 'support' | 'architect';
16
- /** Allow the use of the 'implement' tool for code editing */
16
+ /** Allow the use of the 'edit' and 'create' tools for code editing */
17
17
  allowEdit?: boolean;
18
+ /** Annotate search/extract output with line hashes for integrity verification */
19
+ hashLines?: boolean;
18
20
  /** Architecture context filename to embed from repo root (defaults to AGENTS.md with CLAUDE.md fallback; ARCHITECTURE.md is always included when present) */
19
21
  architectureFileName?: string;
20
22
  /** Search directory path */
@@ -562,12 +564,196 @@ export declare function listFilesByLevel(
562
564
  */
563
565
  export declare const DEFAULT_SYSTEM_MESSAGE: string;
564
566
 
567
+ /**
568
+ * Content record for a tracked symbol
569
+ */
570
+ export interface ContentRecord {
571
+ /** SHA-256 content hash (first 16 hex chars) */
572
+ contentHash: string;
573
+ /** 1-indexed start line */
574
+ startLine: number;
575
+ /** 1-indexed end line */
576
+ endLine: number;
577
+ /** Symbol name, if from a symbol extract */
578
+ symbolName: string | null;
579
+ /** How the content was obtained: 'extract' or 'edit' */
580
+ source: string;
581
+ /** When the record was created (ms since epoch) */
582
+ timestamp: number;
583
+ }
584
+
585
+ /**
586
+ * Result of a staleness check
587
+ */
588
+ export interface FileCheckResult {
589
+ /** Whether the file is safe to edit */
590
+ ok: boolean;
591
+ /** Reason for rejection: 'untracked' or 'stale' */
592
+ reason?: 'untracked' | 'stale';
593
+ /** Human-readable message explaining the rejection */
594
+ message?: string;
595
+ }
596
+
597
+ /**
598
+ * Compute a SHA-256 content hash for a code block.
599
+ * Normalizes trailing whitespace per line for robustness.
600
+ */
601
+ export declare function computeContentHash(content: string): string;
602
+
603
+ /**
604
+ * Per-session content-aware file state tracker for safe multi-edit workflows.
605
+ * Two-tier tracking: file-level "seen" flag + symbol-level content hashes.
606
+ * Edits proceed when the target symbol hasn't changed, even if other parts of the file changed.
607
+ */
608
+ export declare class FileTracker {
609
+ constructor(options?: { debug?: boolean });
610
+
611
+ /** Mark a file as seen (read via search/extract) */
612
+ markFileSeen(resolvedPath: string): void;
613
+
614
+ /** Check if a file has been seen in this session */
615
+ isFileSeen(resolvedPath: string): boolean;
616
+
617
+ /** Store a content hash for a symbol */
618
+ trackSymbolContent(resolvedPath: string, symbolName: string, code: string, startLine: number, endLine: number, source?: string): void;
619
+
620
+ /** Look up a stored content record for a symbol */
621
+ getSymbolRecord(resolvedPath: string, symbolName: string): ContentRecord | null;
622
+
623
+ /** Check if a symbol's current content matches what was stored */
624
+ checkSymbolContent(resolvedPath: string, symbolName: string, currentCode: string): FileCheckResult;
625
+
626
+ /** Track files from extract target strings (marks as seen, hashes symbol targets) */
627
+ trackFilesFromExtract(targets: string[], cwd: string): Promise<void>;
628
+
629
+ /** Track files from probe search/extract output text (marks as seen) */
630
+ trackFilesFromOutput(output: string, cwd: string): Promise<void>;
631
+
632
+ /** Check if a file is safe to edit (seen-check only) */
633
+ checkBeforeEdit(resolvedPath: string): FileCheckResult;
634
+
635
+ /** Mark file as seen after write, invalidate content records */
636
+ trackFileAfterWrite(resolvedPath: string): Promise<void>;
637
+
638
+ /** Update stored hash after successful symbol write */
639
+ trackSymbolAfterWrite(resolvedPath: string, symbolName: string, code: string, startLine: number, endLine: number): void;
640
+
641
+ /** Remove all content records for a file */
642
+ invalidateFileRecords(resolvedPath: string): void;
643
+
644
+ /** Quick sync check if a file is being tracked (alias for isFileSeen) */
645
+ isTracked(resolvedPath: string): boolean;
646
+
647
+ /** Clear all tracking state */
648
+ clear(): void;
649
+ }
650
+
651
+ /**
652
+ * Edit tool configuration options
653
+ */
654
+ export interface EditToolOptions {
655
+ /** Debug mode */
656
+ debug?: boolean;
657
+ /** Allowed directories for file operations */
658
+ allowedFolders?: string[];
659
+ /** Working directory for resolving relative paths */
660
+ cwd?: string;
661
+ /** Workspace root for relative path display */
662
+ workspaceRoot?: string;
663
+ /** File tracker for staleness detection (created automatically by ProbeAgent) */
664
+ fileTracker?: FileTracker;
665
+ }
666
+
667
+ /**
668
+ * Edit tool parameters (text mode)
669
+ */
670
+ export interface EditTextParams {
671
+ /** Path to the file to edit */
672
+ file_path: string;
673
+ /** Text to find in the file (copy verbatim) */
674
+ old_string: string;
675
+ /** Replacement text */
676
+ new_string: string;
677
+ /** Replace all occurrences (default: false) */
678
+ replace_all?: boolean;
679
+ }
680
+
681
+ /**
682
+ * Edit tool parameters (symbol replace mode)
683
+ */
684
+ export interface EditSymbolReplaceParams {
685
+ /** Path to the file to edit */
686
+ file_path: string;
687
+ /** Symbol name to replace (e.g. "myFunction", "MyClass.myMethod") */
688
+ symbol: string;
689
+ /** New code to replace the symbol with */
690
+ new_string: string;
691
+ }
692
+
693
+ /**
694
+ * Edit tool parameters (symbol insert mode)
695
+ */
696
+ export interface EditSymbolInsertParams {
697
+ /** Path to the file to edit */
698
+ file_path: string;
699
+ /** Symbol name to insert near */
700
+ symbol: string;
701
+ /** New code to insert */
702
+ new_string: string;
703
+ /** Insert before or after the symbol */
704
+ position: 'before' | 'after';
705
+ }
706
+
707
+ /**
708
+ * Line-targeted edit parameters
709
+ */
710
+ export interface EditLineTargetedParams {
711
+ /** Path to the file to edit */
712
+ file_path: string;
713
+ /** New code content */
714
+ new_string: string;
715
+ /** Line reference (e.g. "42" or "42:ab" with hash) */
716
+ start_line: string;
717
+ /** End of line range, inclusive (e.g. "55" or "55:cd"). Defaults to start_line. */
718
+ end_line?: string;
719
+ /** Insert before or after the line instead of replacing */
720
+ position?: 'before' | 'after';
721
+ }
722
+
723
+ /**
724
+ * Create tool parameters
725
+ */
726
+ export interface CreateParams {
727
+ /** Path where the file should be created */
728
+ file_path: string;
729
+ /** Content to write to the file */
730
+ content: string;
731
+ /** Overwrite if file exists (default: false) */
732
+ overwrite?: boolean;
733
+ }
734
+
735
+ /**
736
+ * Create edit tool instance
737
+ */
738
+ export declare function editTool(options?: EditToolOptions): {
739
+ execute(params: EditTextParams | EditSymbolReplaceParams | EditSymbolInsertParams | EditLineTargetedParams): Promise<string>;
740
+ };
741
+
742
+ /**
743
+ * Create create tool instance
744
+ */
745
+ export declare function createTool(options?: EditToolOptions): {
746
+ execute(params: CreateParams): Promise<string>;
747
+ };
748
+
565
749
  /**
566
750
  * Schema definitions
567
751
  */
568
752
  export declare const searchSchema: any;
569
753
  export declare const querySchema: any;
570
754
  export declare const extractSchema: any;
755
+ export declare const editSchema: any;
756
+ export declare const createSchema: any;
571
757
  export declare const attemptCompletionSchema: any;
572
758
 
573
759
  /**
@@ -576,6 +762,8 @@ export declare const attemptCompletionSchema: any;
576
762
  export declare const searchToolDefinition: any;
577
763
  export declare const queryToolDefinition: any;
578
764
  export declare const extractToolDefinition: any;
765
+ export declare const editToolDefinition: string;
766
+ export declare const createToolDefinition: string;
579
767
  export declare const attemptCompletionToolDefinition: any;
580
768
 
581
769
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc254",
3
+ "version": "0.6.0-rc256",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -35,7 +35,7 @@ export interface ProbeAgentOptions {
35
35
  systemPrompt?: string;
36
36
  /** Predefined prompt type (persona) */
37
37
  promptType?: 'code-explorer' | 'code-searcher' | 'engineer' | 'code-review' | 'support' | 'architect';
38
- /** Allow the use of the 'implement' tool for code editing */
38
+ /** Allow the use of the 'edit' and 'create' tools for code editing */
39
39
  allowEdit?: boolean;
40
40
  /** Enable the delegate tool for task distribution to subagents */
41
41
  enableDelegate?: boolean;
@@ -57,7 +57,6 @@ import {
57
57
  useSkillToolDefinition,
58
58
  readImageToolDefinition,
59
59
  attemptCompletionToolDefinition,
60
- implementToolDefinition,
61
60
  editToolDefinition,
62
61
  createToolDefinition,
63
62
  googleSearchToolDefinition,
@@ -66,6 +65,7 @@ import {
66
65
  parseXmlToolCallWithThinking
67
66
  } from './tools.js';
68
67
  import { createMessagePreview, detectUnrecognizedToolCall, detectStuckResponse, areBothStuckResponses } from '../tools/common.js';
68
+ import { FileTracker } from '../tools/fileTracker.js';
69
69
  import {
70
70
  createWrappedTools,
71
71
  listFilesToolInstance,
@@ -83,7 +83,8 @@ import {
83
83
  isJsonSchemaDefinition,
84
84
  createSchemaDefinitionCorrectionPrompt,
85
85
  validateAndFixMermaidResponse,
86
- tryAutoWrapForSimpleSchema
86
+ tryAutoWrapForSimpleSchema,
87
+ tryExtractValidJsonPrefix
87
88
  } from './schemaUtils.js';
88
89
  import { removeThinkingTags, extractThinkingContent } from './xmlParsingUtils.js';
89
90
  import { predefinedPrompts } from './shared/prompts.js';
@@ -178,7 +179,7 @@ export class ProbeAgent {
178
179
  * @param {string} [options.customPrompt] - Custom prompt to replace the default system message
179
180
  * @param {string} [options.systemPrompt] - Alias for customPrompt; takes precedence when both are provided
180
181
  * @param {string} [options.promptType] - Predefined prompt type (code-explorer, code-searcher, architect, code-review, support)
181
- * @param {boolean} [options.allowEdit=false] - Allow the use of the 'implement' tool
182
+ * @param {boolean} [options.allowEdit=false] - Allow the use of the 'edit' and 'create' tools
182
183
  * @param {boolean} [options.enableDelegate=false] - Enable the delegate tool for task distribution to subagents
183
184
  * @param {boolean} [options.enableExecutePlan=false] - Enable the execute_plan DSL orchestration tool
184
185
  * @param {string} [options.architectureFileName] - Architecture context filename to embed from repo root (defaults to AGENTS.md with CLAUDE.md fallback; ARCHITECTURE.md is always included when present)
@@ -229,6 +230,7 @@ export class ProbeAgent {
229
230
  this.customPrompt = options.systemPrompt || options.customPrompt || null;
230
231
  this.promptType = options.promptType || 'code-explorer';
231
232
  this.allowEdit = !!options.allowEdit;
233
+ this.hashLines = options.hashLines !== undefined ? !!options.hashLines : this.allowEdit;
232
234
  this.enableDelegate = !!options.enableDelegate;
233
235
  this.enableExecutePlan = !!options.enableExecutePlan;
234
236
  this.debug = options.debug || process.env.DEBUG === '1';
@@ -328,7 +330,8 @@ export class ProbeAgent {
328
330
  if (this.debug) {
329
331
  console.log(`[DEBUG] Generated session ID for agent: ${this.sessionId}`);
330
332
  console.log(`[DEBUG] Maximum tool iterations configured: ${MAX_TOOL_ITERATIONS}`);
331
- console.log(`[DEBUG] Allow Edit (implement tool): ${this.allowEdit}`);
333
+ console.log(`[DEBUG] Allow Edit: ${this.allowEdit}`);
334
+ console.log(`[DEBUG] Hash Lines: ${this.hashLines}`);
332
335
  console.log(`[DEBUG] Search delegation enabled: ${this.searchDelegate}`);
333
336
  console.log(`[DEBUG] Workspace root: ${this.workspaceRoot}`);
334
337
  console.log(`[DEBUG] Working directory (cwd): ${this.cwd}`);
@@ -831,9 +834,12 @@ export class ProbeAgent {
831
834
  cwd: this.cwd,
832
835
  workspaceRoot: this.workspaceRoot,
833
836
  allowedFolders: this.allowedFolders,
837
+ // File state tracking for safe multi-edit workflows (only when editing is enabled)
838
+ fileTracker: this.allowEdit ? new FileTracker({ debug: this.debug }) : null,
834
839
  outline: this.outline,
835
840
  searchDelegate: this.searchDelegate,
836
841
  allowEdit: this.allowEdit,
842
+ hashLines: this.hashLines,
837
843
  enableDelegate: this.enableDelegate,
838
844
  enableExecutePlan: this.enableExecutePlan,
839
845
  enableBash: this.enableBash,
@@ -2553,16 +2559,12 @@ ${extractGuidance}
2553
2559
  }
2554
2560
 
2555
2561
  // Edit tools (require both allowEdit flag AND allowedTools permission)
2556
- if (this.allowEdit && isToolAllowed('implement')) {
2557
- toolDefinitions += `${implementToolDefinition}\n`;
2558
- }
2559
2562
  if (this.allowEdit && isToolAllowed('edit')) {
2560
2563
  toolDefinitions += `${editToolDefinition}\n`;
2561
2564
  }
2562
2565
  if (this.allowEdit && isToolAllowed('create')) {
2563
2566
  toolDefinitions += `${createToolDefinition}\n`;
2564
2567
  }
2565
-
2566
2568
  // Bash tool (require both enableBash flag AND allowedTools permission)
2567
2569
  if (this.enableBash && isToolAllowed('bash')) {
2568
2570
  toolDefinitions += `${bashToolDefinition}\n`;
@@ -2645,7 +2647,7 @@ The configuration is loaded from src/config.js lines 15-25 which contains the da
2645
2647
  availableToolsList += '- query: Search code using structural AST patterns.\n';
2646
2648
  }
2647
2649
  if (isToolAllowed('extract')) {
2648
- availableToolsList += '- extract: Extract specific code blocks or lines from files.\n';
2650
+ availableToolsList += '- extract: Extract specific code blocks or lines from files. Use with symbol targets (e.g. "file.js#funcName") to get line numbers for line-targeted editing.\n';
2649
2651
  }
2650
2652
  if (isToolAllowed('listFiles')) {
2651
2653
  availableToolsList += '- listFiles: List files and directories in a specified location.\n';
@@ -2662,11 +2664,8 @@ The configuration is loaded from src/config.js lines 15-25 which contains the da
2662
2664
  if (isToolAllowed('readImage')) {
2663
2665
  availableToolsList += '- readImage: Read and load an image file for AI analysis.\n';
2664
2666
  }
2665
- if (this.allowEdit && isToolAllowed('implement')) {
2666
- availableToolsList += '- implement: Implement a feature or fix a bug using aider.\n';
2667
- }
2668
2667
  if (this.allowEdit && isToolAllowed('edit')) {
2669
- availableToolsList += '- edit: Edit files using exact string replacement.\n';
2668
+ availableToolsList += '- edit: Edit files using text replacement, AST-aware symbol operations, or line-targeted editing.\n';
2670
2669
  }
2671
2670
  if (this.allowEdit && isToolAllowed('create')) {
2672
2671
  availableToolsList += '- create: Create new files with specified content.\n';
@@ -2757,8 +2756,14 @@ Follow these instructions carefully:
2757
2756
  8. Once the task is fully completed, use the '<attempt_completion>' tool to provide the final result. This is the ONLY way to signal completion.
2758
2757
  9. Prefer concise and focused search queries. Use specific keywords and phrases to narrow down results.${this.allowEdit ? `
2759
2758
  10. When modifying files, choose the appropriate tool:
2760
- - Use 'edit' for precise changes to existing files (requires exact string match)
2761
- - Use 'create' for new files or complete file rewrites` : ''}
2759
+ - Use 'edit' for all code modifications:
2760
+ * For small changes (a line or a few lines), use old_string + new_string — copy old_string verbatim from the file.
2761
+ * For rewriting entire functions/classes/methods, use the symbol parameter instead (no exact text matching needed).
2762
+ * For editing specific lines from search/extract output, use start_line (and optionally end_line) with the line numbers shown in the output.${this.hashLines ? ' Line references include content hashes (e.g. "42:ab") for integrity verification.' : ''}
2763
+ * For editing inside large functions: first use extract with the symbol target (e.g. "file.js#myFunction") to see the function with line numbers${this.hashLines ? ' and hashes' : ''}, then use start_line/end_line to surgically edit specific lines within it.
2764
+ - Use 'create' for new files or complete file rewrites.
2765
+ - If an edit fails, read the error message — it tells you exactly how to fix the call and retry.
2766
+ - The system tracks which files you've seen via search/extract. If you try to edit a file you haven't read, or one that changed since you last read it, the edit will fail with instructions to re-read first. Always use extract before editing to ensure you have current file content.` : ''}
2762
2767
  </instructions>
2763
2768
  `;
2764
2769
 
@@ -3023,8 +3028,9 @@ Follow these instructions carefully:
3023
3028
  // +1 for schema formatting
3024
3029
  // +2 for potential Mermaid validation retries (can be multiple diagrams)
3025
3030
  // +1 for potential JSON correction
3026
- const baseMaxIterations = this.maxIterations || MAX_TOOL_ITERATIONS;
3027
- const maxIterations = options.schema ? baseMaxIterations + 4 : baseMaxIterations;
3031
+ // _maxIterationsOverride: used by correction calls to cap iterations (issue #447)
3032
+ const baseMaxIterations = options._maxIterationsOverride || this.maxIterations || MAX_TOOL_ITERATIONS;
3033
+ const maxIterations = (options._maxIterationsOverride) ? baseMaxIterations : (options.schema ? baseMaxIterations + 4 : baseMaxIterations);
3028
3034
 
3029
3035
  // Check if we're using CLI-based engines which handle their own agentic loop
3030
3036
  const isClaudeCode = this.clientApiProvider === 'claude-code' || process.env.USE_CLAUDE_CODE === 'true';
@@ -3420,8 +3426,11 @@ Follow these instructions carefully:
3420
3426
  validTools.push('attempt_completion');
3421
3427
 
3422
3428
  // Edit tools (require both allowEdit flag AND allowedTools permission)
3423
- if (this.allowEdit && this.allowedTools.isEnabled('implement')) {
3424
- validTools.push('implement', 'edit', 'create');
3429
+ if (this.allowEdit && this.allowedTools.isEnabled('edit')) {
3430
+ validTools.push('edit');
3431
+ }
3432
+ if (this.allowEdit && this.allowedTools.isEnabled('create')) {
3433
+ validTools.push('create');
3425
3434
  }
3426
3435
  // Bash tool (require both enableBash flag AND allowedTools permission)
3427
3436
  if (this.enableBash && this.allowedTools.isEnabled('bash')) {
@@ -3804,6 +3813,7 @@ Follow these instructions carefully:
3804
3813
  mcpConfigPath: this.mcpConfigPath, // Inherit MCP config path
3805
3814
  enableBash: this.enableBash, // Inherit bash enablement
3806
3815
  bashConfig: this.bashConfig, // Inherit bash configuration
3816
+ allowEdit: this.allowEdit, // Inherit edit/create permission
3807
3817
  allowedTools: allowedToolsForDelegate, // Inherit allowed tools from parent
3808
3818
  debug: this.debug,
3809
3819
  tracer: this.tracer
@@ -4685,11 +4695,14 @@ Convert your previous response content into actual JSON data that follows this s
4685
4695
  0
4686
4696
  );
4687
4697
 
4698
+ // Strip schema from correction options to prevent inflated iteration budget (issue #447)
4699
+ const { schema: _unusedSchema1, ...schemaDefCorrectionOptions } = options;
4688
4700
  finalResult = await this.answer(schemaDefinitionPrompt, [], {
4689
- ...options,
4701
+ ...schemaDefCorrectionOptions,
4690
4702
  _schemaFormatted: true,
4691
4703
  _skipValidation: true, // Skip validation in recursive correction calls to prevent loops
4692
- _completionPromptProcessed: true // Prevent cascading completion prompts in retry calls
4704
+ _completionPromptProcessed: true, // Prevent cascading completion prompts in retry calls
4705
+ _maxIterationsOverride: 3 // Correction should complete in 1-2 iterations (issue #447)
4693
4706
  });
4694
4707
  finalResult = cleanSchemaResponse(finalResult);
4695
4708
  validation = validateJsonResponse(finalResult);
@@ -4745,12 +4758,15 @@ Convert your previous response content into actual JSON data that follows this s
4745
4758
  );
4746
4759
  }
4747
4760
 
4761
+ // Strip schema from correction options to prevent inflated iteration budget (issue #447)
4762
+ const { schema: _unusedSchema2, ...correctionOptions } = options;
4748
4763
  finalResult = await this.answer(correctionPrompt, [], {
4749
- ...options,
4764
+ ...correctionOptions,
4750
4765
  _schemaFormatted: true,
4751
4766
  _skipValidation: true, // Skip validation in recursive correction calls to prevent loops
4752
4767
  _disableTools: true, // Only allow attempt_completion - prevent AI from using search/query tools
4753
- _completionPromptProcessed: true // Prevent cascading completion prompts in retry calls
4768
+ _completionPromptProcessed: true, // Prevent cascading completion prompts in retry calls
4769
+ _maxIterationsOverride: 3 // Correction should complete in 1-2 iterations (issue #447)
4754
4770
  });
4755
4771
  finalResult = cleanSchemaResponse(finalResult);
4756
4772
 
@@ -162,7 +162,8 @@ export class ACPToolManager {
162
162
  return ToolCallKind.extract;
163
163
  case 'delegate':
164
164
  return ToolCallKind.execute;
165
- case 'implement':
165
+ case 'edit':
166
+ case 'create':
166
167
  return ToolCallKind.edit;
167
168
  default:
168
169
  return ToolCallKind.execute;
@@ -117,7 +117,8 @@ describe('ACPToolManager', () => {
117
117
  expect(toolManager.getToolKind('query')).toBe(ToolCallKind.query);
118
118
  expect(toolManager.getToolKind('extract')).toBe(ToolCallKind.extract);
119
119
  expect(toolManager.getToolKind('delegate')).toBe(ToolCallKind.execute);
120
- expect(toolManager.getToolKind('implement')).toBe(ToolCallKind.edit);
120
+ expect(toolManager.getToolKind('edit')).toBe(ToolCallKind.edit);
121
+ expect(toolManager.getToolKind('create')).toBe(ToolCallKind.edit);
121
122
  expect(toolManager.getToolKind('unknown')).toBe(ToolCallKind.execute);
122
123
  });
123
124
  });
@@ -30,13 +30,45 @@ export const DEFAULT_ALLOW_PATTERNS = [
30
30
  'tree', 'tree:*',
31
31
 
32
32
  // Git read-only operations
33
- 'git:status', 'git:log', 'git:log:*', 'git:diff', 'git:diff:*',
33
+ 'git:status', 'git:status:*', 'git:log', 'git:log:*', 'git:diff', 'git:diff:*',
34
34
  'git:show', 'git:show:*', 'git:branch', 'git:branch:*',
35
35
  'git:tag', 'git:tag:*', 'git:describe', 'git:describe:*',
36
36
  'git:remote', 'git:remote:*', 'git:config:*',
37
- 'git:blame', 'git:blame:*', 'git:shortlog', 'git:reflog',
38
- 'git:ls-files', 'git:ls-tree', 'git:rev-parse', 'git:rev-list',
37
+ 'git:blame', 'git:blame:*', 'git:shortlog', 'git:shortlog:*', 'git:reflog', 'git:reflog:*',
38
+ 'git:ls-files', 'git:ls-files:*', 'git:ls-tree', 'git:ls-tree:*',
39
+ 'git:ls-remote', 'git:ls-remote:*',
40
+ 'git:rev-parse', 'git:rev-parse:*', 'git:rev-list', 'git:rev-list:*',
41
+ 'git:cat-file', 'git:cat-file:*',
42
+ 'git:diff-tree', 'git:diff-tree:*', 'git:diff-files', 'git:diff-files:*',
43
+ 'git:diff-index', 'git:diff-index:*',
44
+ 'git:for-each-ref', 'git:for-each-ref:*',
45
+ 'git:merge-base', 'git:merge-base:*',
46
+ 'git:name-rev', 'git:name-rev:*',
47
+ 'git:count-objects', 'git:count-objects:*',
48
+ 'git:verify-commit', 'git:verify-commit:*', 'git:verify-tag', 'git:verify-tag:*',
49
+ 'git:check-ignore', 'git:check-ignore:*', 'git:check-attr', 'git:check-attr:*',
50
+ 'git:stash:list', 'git:stash:show', 'git:stash:show:*',
51
+ 'git:worktree:list', 'git:worktree:list:*',
52
+ 'git:notes:list', 'git:notes:show', 'git:notes:show:*',
39
53
  'git:--version', 'git:help', 'git:help:*',
54
+
55
+ // GitHub CLI (gh) read-only operations
56
+ 'gh:--version', 'gh:help', 'gh:help:*', 'gh:status',
57
+ 'gh:auth:status', 'gh:auth:status:*',
58
+ 'gh:issue:list', 'gh:issue:list:*', 'gh:issue:view', 'gh:issue:view:*',
59
+ 'gh:issue:status', 'gh:issue:status:*',
60
+ 'gh:pr:list', 'gh:pr:list:*', 'gh:pr:view', 'gh:pr:view:*',
61
+ 'gh:pr:status', 'gh:pr:status:*', 'gh:pr:diff', 'gh:pr:diff:*',
62
+ 'gh:pr:checks', 'gh:pr:checks:*',
63
+ 'gh:repo:list', 'gh:repo:list:*', 'gh:repo:view', 'gh:repo:view:*',
64
+ 'gh:release:list', 'gh:release:list:*', 'gh:release:view', 'gh:release:view:*',
65
+ 'gh:run:list', 'gh:run:list:*', 'gh:run:view', 'gh:run:view:*',
66
+ 'gh:workflow:list', 'gh:workflow:list:*', 'gh:workflow:view', 'gh:workflow:view:*',
67
+ 'gh:gist:list', 'gh:gist:list:*', 'gh:gist:view', 'gh:gist:view:*',
68
+ 'gh:search:issues', 'gh:search:issues:*', 'gh:search:prs', 'gh:search:prs:*',
69
+ 'gh:search:repos', 'gh:search:repos:*', 'gh:search:code', 'gh:search:code:*',
70
+ 'gh:search:commits', 'gh:search:commits:*',
71
+ 'gh:api', 'gh:api:*',
40
72
 
41
73
  // Package managers (information only)
42
74
  'npm:list', 'npm:ls', 'npm:view', 'npm:info', 'npm:show',
@@ -165,9 +197,46 @@ export const DEFAULT_DENY_PATTERNS = [
165
197
  'sysctl:-w:*',
166
198
 
167
199
  // Dangerous git operations
168
- 'git:push', 'git:push:*', 'git:force', 'git:reset:--hard:*',
169
- 'git:clean:-fd', 'git:rm:*', 'git:commit', 'git:merge',
170
- 'git:rebase', 'git:cherry-pick', 'git:stash:drop',
200
+ 'git:push', 'git:push:*', 'git:force', 'git:reset', 'git:reset:*',
201
+ 'git:clean', 'git:clean:*', 'git:rm', 'git:rm:*',
202
+ 'git:commit', 'git:commit:*', 'git:merge', 'git:merge:*',
203
+ 'git:rebase', 'git:rebase:*', 'git:cherry-pick', 'git:cherry-pick:*',
204
+ 'git:stash:drop', 'git:stash:drop:*', 'git:stash:pop', 'git:stash:pop:*',
205
+ 'git:stash:push', 'git:stash:push:*', 'git:stash:clear',
206
+ 'git:branch:-d', 'git:branch:-d:*', 'git:branch:-D', 'git:branch:-D:*',
207
+ 'git:branch:--delete', 'git:branch:--delete:*',
208
+ 'git:tag:-d', 'git:tag:-d:*', 'git:tag:--delete', 'git:tag:--delete:*',
209
+ 'git:remote:remove', 'git:remote:remove:*', 'git:remote:rm', 'git:remote:rm:*',
210
+ 'git:checkout:--force', 'git:checkout:--force:*',
211
+ 'git:checkout:-f', 'git:checkout:-f:*',
212
+ 'git:submodule:deinit', 'git:submodule:deinit:*',
213
+ 'git:notes:add', 'git:notes:add:*', 'git:notes:remove', 'git:notes:remove:*',
214
+ 'git:worktree:add', 'git:worktree:add:*',
215
+ 'git:worktree:remove', 'git:worktree:remove:*',
216
+
217
+ // Dangerous GitHub CLI (gh) write operations
218
+ 'gh:issue:create', 'gh:issue:create:*', 'gh:issue:close', 'gh:issue:close:*',
219
+ 'gh:issue:delete', 'gh:issue:delete:*', 'gh:issue:edit', 'gh:issue:edit:*',
220
+ 'gh:issue:reopen', 'gh:issue:reopen:*',
221
+ 'gh:issue:comment', 'gh:issue:comment:*',
222
+ 'gh:pr:create', 'gh:pr:create:*', 'gh:pr:close', 'gh:pr:close:*',
223
+ 'gh:pr:merge', 'gh:pr:merge:*', 'gh:pr:edit', 'gh:pr:edit:*',
224
+ 'gh:pr:reopen', 'gh:pr:reopen:*', 'gh:pr:review', 'gh:pr:review:*',
225
+ 'gh:pr:comment', 'gh:pr:comment:*',
226
+ 'gh:repo:create', 'gh:repo:create:*', 'gh:repo:delete', 'gh:repo:delete:*',
227
+ 'gh:repo:fork', 'gh:repo:fork:*', 'gh:repo:rename', 'gh:repo:rename:*',
228
+ 'gh:repo:archive', 'gh:repo:archive:*', 'gh:repo:clone', 'gh:repo:clone:*',
229
+ 'gh:release:create', 'gh:release:create:*', 'gh:release:delete', 'gh:release:delete:*',
230
+ 'gh:release:edit', 'gh:release:edit:*',
231
+ 'gh:run:cancel', 'gh:run:cancel:*', 'gh:run:rerun', 'gh:run:rerun:*',
232
+ 'gh:workflow:run', 'gh:workflow:run:*',
233
+ 'gh:workflow:enable', 'gh:workflow:enable:*', 'gh:workflow:disable', 'gh:workflow:disable:*',
234
+ 'gh:gist:create', 'gh:gist:create:*', 'gh:gist:delete', 'gh:gist:delete:*',
235
+ 'gh:gist:edit', 'gh:gist:edit:*',
236
+ 'gh:secret:set', 'gh:secret:set:*', 'gh:secret:delete', 'gh:secret:delete:*',
237
+ 'gh:variable:set', 'gh:variable:set:*', 'gh:variable:delete', 'gh:variable:delete:*',
238
+ 'gh:label:create', 'gh:label:create:*', 'gh:label:delete', 'gh:label:delete:*',
239
+ 'gh:ssh-key:add', 'gh:ssh-key:add:*', 'gh:ssh-key:delete', 'gh:ssh-key:delete:*',
171
240
 
172
241
  // File system mounting and partitioning
173
242
  'mount', 'mount:*', 'umount', 'umount:*', 'fdisk', 'fdisk:*',
@@ -124,7 +124,8 @@ function parseArgs() {
124
124
  schema: null,
125
125
  provider: null,
126
126
  model: null,
127
- allowEdit: false,
127
+ allowEdit: process.env.ALLOW_EDIT === '1' || false,
128
+ hashLines: process.env.HASH_LINES !== undefined ? process.env.HASH_LINES === '1' : undefined,
128
129
  enableDelegate: false,
129
130
  verbose: false,
130
131
  help: false,
@@ -167,6 +168,10 @@ function parseArgs() {
167
168
  config.verbose = true;
168
169
  } else if (arg === '--allow-edit') {
169
170
  config.allowEdit = true;
171
+ } else if (arg === '--hash-lines') {
172
+ config.hashLines = true;
173
+ } else if (arg === '--no-hash-lines') {
174
+ config.hashLines = false;
170
175
  } else if (arg === '--enable-delegate') {
171
176
  config.enableDelegate = true;
172
177
  } else if (arg === '--no-delegate') {
@@ -275,12 +280,14 @@ Options:
275
280
  --schema <schema|file> Output schema (JSON, XML, any format - text or file path)
276
281
  --provider <name> Force AI provider: anthropic, openai, google
277
282
  --model <name> Override model name
278
- --allow-edit Enable code modification capabilities
283
+ --allow-edit Enable code modification capabilities (edit + create tools)
284
+ --hash-lines Annotate search/extract output with line hashes (default: on when --allow-edit)
285
+ --no-hash-lines Disable line hash annotations even with --allow-edit
279
286
  --enable-delegate Enable delegate tool for task distribution to subagents
280
287
  --allowed-tools <tools> Filter available tools (comma-separated list)
281
288
  Use '*' or 'all' for all tools (default)
282
289
  Use 'none' or '' for no tools (raw AI mode)
283
- Specific tools: search,query,extract,listFiles,searchFiles,listSkills,useSkill
290
+ Specific tools: search,query,extract,edit,create,listFiles,searchFiles,listSkills,useSkill
284
291
  Supports exclusion: '*,!bash' (all except bash)
285
292
  --disable-tools Disable all tools (raw AI mode, no code analysis)
286
293
  Convenience flag equivalent to --allowed-tools none
@@ -318,6 +325,8 @@ Environment Variables:
318
325
  FORCE_PROVIDER Force specific provider (anthropic, openai, google)
319
326
  MODEL_NAME Override model name
320
327
  MAX_RESPONSE_TOKENS Maximum tokens for AI response
328
+ ALLOW_EDIT Enable code modification (set to '1')
329
+ HASH_LINES Annotate output with line hashes (set to '1'; default: on with ALLOW_EDIT)
321
330
  DEBUG Enable verbose mode (set to '1')
322
331
 
323
332
  Examples:
@@ -334,6 +343,8 @@ Examples:
334
343
  probe agent "Explain this code" --allowed-tools search,extract # Only search and extract
335
344
  probe agent "What is this project about?" --allowed-tools none # Raw AI mode (no tools)
336
345
  probe agent "Tell me about this project" --disable-tools # Raw AI mode (convenience flag)
346
+ probe agent "Fix the off-by-one error" --allow-edit --path ./src # Enable code editing
347
+ ALLOW_EDIT=1 probe agent "Refactor the login flow" # Edit via env var
337
348
  probe agent --mcp # Start MCP server mode
338
349
  probe agent --acp # Start ACP server mode
339
350
 
@@ -612,9 +623,9 @@ class ProbeAgentMcpServer {
612
623
  // Retry once with correction prompt
613
624
  const correctionPrompt = createJsonCorrectionPrompt(result, schema, validation.error);
614
625
  try {
615
- result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true });
626
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true, _maxIterationsOverride: 3 });
616
627
  result = cleanSchemaResponse(result);
617
-
628
+
618
629
  // Validate again after correction
619
630
  const finalValidation = validateJsonResponse(result);
620
631
  if (!finalValidation.isValid && args.debug) {
@@ -960,11 +971,11 @@ async function main() {
960
971
  try {
961
972
  if (appTracer) {
962
973
  result = await appTracer.withSpan('agent.json_correction',
963
- () => agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true }),
974
+ () => agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true, _maxIterationsOverride: 3 }),
964
975
  { 'original_error': validation.error }
965
976
  );
966
977
  } else {
967
- result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true });
978
+ result = await agent.answer(correctionPrompt, [], { schema, _schemaFormatted: true, _disableTools: true, _maxIterationsOverride: 3 });
968
979
  }
969
980
  result = cleanSchemaResponse(result);
970
981
 
@@ -6,6 +6,7 @@
6
6
  import { MCPClientManager } from './client.js';
7
7
  import { loadMCPConfiguration } from './config.js';
8
8
  import { processXmlWithThinkingAndRecovery } from '../xmlParsingUtils.js';
9
+ import { unescapeXmlEntities } from '../../tools/common.js';
9
10
 
10
11
  /**
11
12
  * Convert MCP tool to XML definition format
@@ -111,7 +112,7 @@ export function parseXmlMcpToolCall(xmlString, mcpToolNames = []) {
111
112
  let match;
112
113
  while ((match = paramPattern.exec(content)) !== null) {
113
114
  const [, paramName, paramValue] = match;
114
- params[paramName] = paramValue.trim();
115
+ params[paramName] = unescapeXmlEntities(paramValue.trim());
115
116
  }
116
117
  }
117
118
 
@@ -393,7 +394,7 @@ function parseNativeXmlTool(xmlString, toolName) {
393
394
  const [, paramName, paramValue] = match;
394
395
  // Skip if this is the params tag itself (MCP format)
395
396
  if (paramName !== 'params') {
396
- params[paramName] = paramValue.trim();
397
+ params[paramName] = unescapeXmlEntities(paramValue.trim());
397
398
  }
398
399
  }
399
400