This document describes Same.dev's code editing and validation workflow, covering tool selection logic, pre-edit requirements, validation procedures, and error handling mechanisms. This page focuses specifically on the mechanics of making code changes and ensuring they are error-free before delivery to the user.
For information about parallel tool execution strategy across multiple files, see Tool Execution and Parallel Processing. For web development best practices including framework-specific configurations, see Web Development Best Practices.
Same.dev provides two distinct tools for code modification: edit_file and string_replace. The selection between these tools follows a clear decision tree based on file size and edit scope.
The primary selection criterion is file size, with a threshold of 2500 lines determining tool choice:
| Condition | Selected Tool | Rationale |
|---|---|---|
| File > 2500 lines AND small edit | string_replace | Efficient for targeted changes in large files |
| File ≤ 2500 lines | edit_file | Preferred for most edits with intelligent apply model |
| New file creation | Either (context dependent) | Both tools support file creation |
The edit_file tool is the default preference for the majority of editing scenarios due to its intelligent apply model that understands code structure and context.
Decision Tree Diagram
Sources: Same.dev/Prompt.txt238-239
When the edit_file tool's apply model fails to follow a reasonable code_edit suggestion, the system implements a retry mechanism using the smart_apply parameter:
The smart_apply parameter activates enhanced code understanding in the apply model, improving its ability to correctly interpret and execute the intended edit.
Sources: Same.dev/Prompt.txt239-240
Same.dev enforces a strict read-before-write requirement for nearly all editing operations:
Rule: Unless appending a small, easy-to-apply edit to a file or creating a new file, the agent MUST read the contents or section being edited before making modifications.
Exceptions:
Rationale: This requirement ensures the agent has accurate context about:
Workflow Integration
Sources: Same.dev/Prompt.txt235-236
Before editing, the agent typically performs parallel read operations to gather comprehensive context:
read_fileThis context gathering leverages Same.dev's parallel execution capability to minimize latency (see Tool Execution and Parallel Processing).
Sources: Same.dev/Prompt.txt70-71 Same.dev/Prompt.txt235-236
The run_linter tool is a mandatory component of Same.dev's code quality assurance system:
Invocation Points:
Purpose: Detect linting errors, type errors, and other runtime issues before they reach the user.
Sources: Same.dev/Prompt.txt237-238
When run_linter detects errors, the agent enters an iterative fixing loop:
Loop Logic:
Fix Criteria:
Sources: Same.dev/Prompt.txt237-238
Same.dev implements a circuit breaker pattern to prevent infinite fixing loops:
Circuit Breaker Rules:
| Iteration | Action | Outcome |
|---|---|---|
| Attempt 1 | Apply fix, run linter | Continue if errors remain |
| Attempt 2 | Apply fix, run linter | Continue if errors remain |
| Attempt 3 | Apply fix, run linter | STOP regardless of outcome |
| After 3 | Stop and ask user what to do next | Escalation path |
Escalation Options Presented to User:
Circuit Breaker State Machine
This circuit breaker prevents resource waste and user frustration from repeated failed fix attempts on the same file.
Sources: Same.dev/Prompt.txt237-238
Same.dev mandates that all generated code must be runnable immediately by the user without errors:
Critical Requirements:
Code Generation Restrictions:
| Prohibited Content | Rationale |
|---|---|
| Extremely long hashes | Not helpful, expensive to generate |
| Binary data | Cannot be run as code, expensive |
| .ico files | Non-textual, expensive |
| Other non-textual content | General prohibition on non-runnable content |
These restrictions prevent the generation of content that appears to be code but cannot be executed or validated.
Sources: Same.dev/Prompt.txt67-69 Same.dev/Prompt.txt232-234
The agent must proactively ensure all code dependencies are satisfied:
Import Statement Requirements:
Dependency Installation:
bun add for package installation (not npm)Sources: Same.dev/Prompt.txt67 Same.dev/Prompt.txt232
While Same.dev strongly emphasizes parallel tool execution (see Tool Execution and Parallel Processing), code editing operations have specific sequencing requirements:
Edit Operations That MUST Be Sequential:
Operations That CAN Be Parallel:
Example Workflow
The parallel read phase maximizes efficiency (3-5x faster), while the sequential edit-validate phase ensures correctness.
Sources: Same.dev/Prompt.txt45-49 Same.dev/Prompt.txt210-214
The following diagram illustrates the complete state machine for Same.dev's code editing and validation workflow, integrating all components:
This state machine encompasses:
Sources: Same.dev/Prompt.txt62-75 Same.dev/Prompt.txt227-240
The following table summarizes the key parameters and thresholds governing Same.dev's editing workflow:
| Parameter | Value | Purpose |
|---|---|---|
| File size threshold | 2500 lines | Determines edit_file vs string_replace |
| Circuit breaker limit | 3 attempts | Maximum fixing iterations per file |
| required_param: relative_file_path | First argument | Tool parameter ordering requirement |
| smart_apply parameter | Boolean | Retry mechanism for edit_file |
| Validation trigger | "significant edit" | When to invoke run_linter |
| Parallel edit constraint | Same file: NO | Prevent concurrent same-file edits |
| Read requirement | Pre-edit | Must read before editing (with exceptions) |
Sources: Same.dev/Prompt.txt62-75 Same.dev/Prompt.txt227-240
Refresh this wiki