Skip to content

[Phase 2.5-B] Implement write agent tools (edit_file, create_file) #345

Description

@frankbria

Summary

Add the file-modification tools to codeframe/core/tools.py: edit_file (search-replace via editor.py) and create_file (whole-file for new files only).

Acceptance Criteria

  • edit_file tool:
    • Input: { path, edits: [{ search, replace }] }
    • Delegates to SearchReplaceEditor.apply_edits() from editor.py
    • On success: returns unified diff
    • On failure: returns actual file content near expected match (for LLM retry)
    • Must read file before editing (verified internally)
  • create_file tool:
    • Input: { path, content }
    • Creates file with content, auto-creates parent directories
    • Fails if file already exists — returns error suggesting edit_file instead
    • This prevents the Add Claude Code GitHub Workflow #1 failure mode (config file overwrites)
  • Both tools added to AGENT_TOOLS list and execute_tool dispatcher
  • Tests in tests/core/test_tools.py covering:
    • Successful edit with diff output
    • Edit failure with context feedback
    • Create new file success
    • Create existing file → error with suggestion
    • Path traversal attempts blocked
  • All existing tests pass

Implementation Notes

Dependencies

Reference

  • docs/AGENT_V3_UNIFIED_PLAN.md (Tool Set → edit_file, create_file)
  • docs/AGENT_ARCHITECTURE_CRITIQUE.md (Section 2.1 — greenfield vs brownfield)

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase-2.5Phase 2.5: Agent Execution Redesign (ReAct)phase-2.5-BPhase B: Tool Definitions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions