validation

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package validation provides pre-write syntax validation for the editor tools (write_file/edit_file/multi_edit). It catches syntax errors BEFORE the file is written, so the agent gets an error and can fix it without corrupting the file on disk (SPEC v2 §3.3).

Design constraints (SPEC v2 §2.0):

  • Zero user learning cost: always on for the languages we support, the user never configures anything. Only fires when there's actually an error.
  • No prompt bloat: pure host logic (stdlib parsers), the model only sees the returned error string; nothing is added to the system prompt.
  • No new dependencies: Go uses go/parser (already imported by codeindex), JSON uses encoding/json. YAML/Python are intentionally omitted (would need a new dep / external process) — they fall through to "no check".
  • Fast: <100ms target. Go parse with AllErrors off stops at the first error; JSON validity is a single-pass scan.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateSyntax

func ValidateSyntax(path, content string) error

ValidateSyntax checks content for syntax errors based on the file extension. It returns nil when the content is valid (or the extension is unrecognized — we never block writes to languages we don't check). A non-nil *SyntaxError means the write MUST be refused so the file isn't corrupted on disk.

Supported: .go (go/parser), .json (encoding/json). All other extensions pass through (no check) — adding a language is a new case here, no caller change.

Types

type SyntaxError

type SyntaxError struct {
	Path    string
	Line    int    // 1-based; 0 if unavailable (JSON)
	Message string // the parser's error message
}

SyntaxError describes a pre-write syntax validation failure. It carries the path so the tool can surface "file.go:12: syntax error" to the model.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL