MingaAgent.EditBoundary (Minga v0.1.0)

Copy Markdown View Source

Defines a line range that an agent session is allowed to edit within a buffer.

Boundaries are per-buffer, per-session. When set, agent edits outside the boundary are rejected with a descriptive error. Boundaries adjust automatically when edits change the line count within the bounded region or when user edits above the boundary shift line numbers.

Summary

Types

t()

A line range boundary (both inclusive, 0-indexed).

Functions

Adjusts the boundary after an edit changed the line count.

Checks whether a line falls within the boundary (inclusive on both ends).

Checks whether a line range (start..end, both inclusive) falls entirely within the boundary.

Creates a new boundary for the given line range (both inclusive, 0-indexed).

Types

t()

@type t() :: %MingaAgent.EditBoundary{
  end_line: non_neg_integer(),
  start_line: non_neg_integer()
}

A line range boundary (both inclusive, 0-indexed).

Functions

adjust(edit_boundary, edit_line, line_delta)

@spec adjust(t(), non_neg_integer(), integer()) :: t() | nil

Adjusts the boundary after an edit changed the line count.

edit_line is the 0-indexed line where the edit started. line_delta is the number of lines added (positive) or removed (negative) by the edit.

  • Edits within the boundary: the end shifts by line_delta.
  • Edits above the boundary: both start and end shift by line_delta.
  • Edits below the boundary: no change.

Returns nil if the boundary collapses to zero or negative size (e.g., the user deleted all lines within the boundary).

contains_line?(edit_boundary, line)

@spec contains_line?(t(), non_neg_integer()) :: boolean()

Checks whether a line falls within the boundary (inclusive on both ends).

contains_range?(edit_boundary, range_start, range_end)

@spec contains_range?(t(), non_neg_integer(), non_neg_integer()) :: boolean()

Checks whether a line range (start..end, both inclusive) falls entirely within the boundary.

new(start_line, end_line)

@spec new(non_neg_integer(), non_neg_integer()) :: {:ok, t()} | {:error, String.t()}

Creates a new boundary for the given line range (both inclusive, 0-indexed).

Returns {:error, reason} if the range is invalid.