Sypha AI Docs
FeaturesTools

write_to_file

Initialize new files or perform complete structural rewrites within your project workspace.

write_to_file

The write_to_file utility is the primary mechanism Sypha uses for establishing new files or executing comprehensive rewrites of existing code.

Parameters

  • path (required): The designated destination for creating or overwriting a file.
  • content (required): The complete textual data for the file.
  • line_count (required): The total number of lines contained within the content.

Operation Details

This tool performs a "descructive" update by completely replacing a target file's content. To maintain environment integrity, Sypha must provide an accurate line_count. If the line summation does not align (indicating a potential truncation in the AI response), the operation is halted and retried to prevent code corruption.

Verification & Trust

Similar to the apply_diff workflow, this tool initializes a Visual Diff within VS Code. You are presented with the full proposed content, allowing for a thorough review or manual adjustments before any data is committed to the file system.

Strategy: write_to_file vs apply_diff

  • Utilize write_to_file: When generating an entirely new project asset or when replacing the vast majority of an existing file (such as a full config reset).
  • Utilize apply_diff: When making incremental or targeted changes to established files. This method is significantly faster and more context-efficient.

Implementation Example

Generating a new component

<write_to_file>
  <path>src/ui/NavButton.tsx</path>
  <content>
    import { FC } from 'react';
    export const NavButton: FC = () => <button>Click Me</button>;
  </content>
  <line_count>3</line_count>
</write_to_file>

On this page