Documentation
¶
Overview ¶
Package write changes files in a vault: create, append, patch frontmatter, edit text, replace. Each op, built next to its transform in its own file, works out a file's new content; the batch engine (batch.go) holds every op to the document rules, replaces each changed file atomically and makes at most one commit.
Index ¶
Constants ¶
const ( ToolCreate = "create_doc" ToolAppend = "append_section" ToolPatch = "update_frontmatter" ToolReplace = "replace_doc" ToolEdit = "edit_text" )
The write tools an Op stands for, as named in commit messages, errors and the server's tool list.
const MaxBatchOps = 200
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchResult ¶
type BatchResult struct {
Results []Result `json:"results"`
Commit string `json:"commit,omitempty"`
Warnings []string `json:"warnings"`
}
BatchResult is what Batch returns: a Result per op, in op order, and the one commit with its warnings. A Result's Hash is its file's hash after the batch.
type ConflictError ¶
type ConflictError struct{ Path, Current string }
ConflictError means replace_doc saw a file that changed since it was read.
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
type Git ¶
type Git struct {
Dir, Name, Email string
Bin string // default: git on the PATH
Timeout time.Duration // for the whole commit, not per git command; zero means 10 s
}
Git commits written files in the vault folder Dir, as Name <Email>, so every AI change can be reviewed (git log --author) and reverted. It shells out to the git binary and never pushes.
func (*Git) Commit ¶
Commit commits paths (slash-separated, relative to Dir) with message msg. It only commits when Dir is the root of its git repository, and only those paths, so staged work by a human is left alone. It never fails a write: every problem comes back as warning, and then hash is empty.
Root only, because a vault inside a bigger repository, like examples/vault in this one, must never receive AI commits. A commit covers whole files, so a human's uncommitted edit to a written file goes into the AI's commit.
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op is one write: the tool it stands for, what it targets (a path, or the type for create_doc) and the new content it works out for one file. Build it with NewCreateOp, NewAppendOp, NewPatchOp, NewReplaceOp, NewEditOp or NewFailedOp, and run it with Apply or Batch.
func NewAppendOp ¶
NewAppendOp returns the op that adds content to the end of a "## heading" section, or adds the section at the end of the file.
func NewCreateOp ¶
NewCreateOp returns the op that makes a new document of a configured type. The path comes from the type's folder and filename pattern.
func NewEditOp ¶
NewEditOp returns the op that replaces the one occurrence of old in a file with replacement. An empty replacement deletes it.
func NewFailedOp ¶
NewFailedOp returns the op of a tool call the caller could not build, for example because its arguments did not decode. Apply and Batch report err as its failure.
func NewPatchOp ¶
NewPatchOp returns the op that changes frontmatter keys and tags, leaving the body's bytes alone.
func NewReplaceOp ¶
NewReplaceOp returns the op that rewrites a whole file, but only if it still has the content whose hash the caller read.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer applies safe changes to one vault. Writes are serialised, since tool calls may overlap; every write goes through the batch engine (batch.go, Apply and Batch), and every file is replaced atomically. A nil Git means no commits and no commit warnings: main passes nil when commits are off, and tests do, so they do not depend on git state.
func (*Writer) Apply ¶
Apply runs one op and commits it as "<tool>: <path>". Its errors are the op's own, unlabelled.