>cogtrix v0.3.0

Files & Git

File Operations

All file tools enforce path safety: paths must resolve within the current working directory. Read-only tools (read_file, list_directory, file_info) also allow access to the application install directory — this matters in Docker containers where the working directory may differ from the install path (e.g., -w /tmp while the app lives at /app). Write tools are restricted to the working directory by default, but additional write directories can be allowed via --allow-write-path, COGTRIX_ALLOWED_WRITE_PATHS, or the allowed_write_paths config option (see Configuration).

read_file

Read contents of a file.

Parameters:

ParameterTypeRequiredDescription
pathstringYesFile path to read
encodingstringNoFile encoding (default: “utf-8”)
start_lineintNoLine number to start reading from (0-based)
max_linesintNoMaximum number of lines to read from start_line

Example:

Read file: /path/to/config.json

write_file

Write content to a file (creates if not exists, overwrites if it does).

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
pathstringYesFile path to write (must be within working directory)
contentstringYesContent to write
encodingstringNoFile encoding (default: “utf-8”)

patch_file

Surgically replace an exact string in a file without rewriting the whole file.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
pathstringYesFile path to edit (must be within an allowed write root)
old_strstringYesExact string to find (must appear exactly once in the file)
new_strstringYesReplacement string (may be empty to delete the match)

Notes:

  • Fails with a clear error if old_str is not found or appears more than once — add more surrounding context to make the match unique.
  • Writes the result atomically; the file is never left in a partial state.
  • Prefer this over write_file for targeted edits to existing files.

append_file

Append content to an existing file.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
pathstringYesFile path to append to
contentstringYesContent to append
encodingstringNoFile encoding (default: “utf-8”)

list_directory

List contents of a directory.

Parameters:

ParameterTypeRequiredDescription
pathstringYesDirectory path
patternstringNoGlob pattern to filter files (default: ”*“)
show_hiddenboolNoInclude hidden files (default: false)

Returns: List of files/directories with sizes


file_info

Get detailed information about a file or directory.

Parameters:

ParameterTypeRequiredDescription
pathstringYesFile or directory path

Returns: Size, creation date, modification date, permissions


Git Operations

Run Git commands from within Cogtrix to inspect and manage a repository. Read-only tools (git_status, git_diff, git_log) run without confirmation. Write tools (git_add, git_commit, git_create_branch, git_checkout) require confirmation. All commands use os.getcwd() as the working directory. Arguments are passed as list tokens — no shell interpolation occurs.

git_status

Show the working tree status: staged changes, unstaged changes, and untracked files.

Parameters: None

Returns: Short-format status output with branch name.


git_diff

Show a unified diff of changes in the working tree (or staged changes).

Parameters:

ParameterTypeRequiredDefaultDescription
pathstringNo"" (all)Specific file or directory to diff. Leave empty to diff all changes.
stagedboolNofalseShow staged (cached) diff instead of unstaged working-tree diff.

Returns: git diff --stat --patch output.


git_log

Show recent commit history with hash, date, author, and subject.

Parameters:

ParameterTypeRequiredDefaultDescription
max_countintNo10Number of commits to show (1–100).
branchstringNo"" (current)Branch or ref to show history for.

Returns: Formatted one-line-per-commit log.


git_add

Stage one or more files for the next commit.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
pathsarray of stringsYesFile paths to stage. Pass ["."] to stage all changes.

git_commit

Create a commit from all currently staged changes.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
messagestringYesCommit message (max 4096 chars).

git_create_branch

Create a new branch and switch to it.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDefaultDescription
namestringYesNew branch name (max 256 chars).
basestringNo"HEAD"Starting point: branch name, tag, or commit hash.

git_checkout

Switch to a branch or restore a file to its last committed state.

Requires Confirmation: Yes

Parameters:

ParameterTypeRequiredDescription
refstringYesBranch name to switch to, or file path to restore to HEAD.