connect

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package connect writes the MCP entry and the hooks of mai in the user configuration files of an agent app, and removes exactly those entries again. Each entry that it writes goes into the manifest with the SHA-256 of its content. The entries hold no secret.

Index

Constants

View Source
const TOMLPointer = "toml:mcp_servers.mai"

TOMLPointer is the pointer of the MCP table that mai writes in the config.toml of Codex.

Variables

View Source
var Apps = []string{"antigravity", "claude", "codex", "copilot", "cursor"}

Apps are the names of the apps that mai connect knows.

View Source
var Binary = runningBinary

Binary gives the path of the mai binary that the entries name. The apps start mai with the PATH of the app, not the PATH of the shell of the user, thus the entries use a full path. The default is the path of the running binary. A test replaces it.

View Source
var ErrExists = errors.New("connect: the file has a different mai entry")

ErrExists means that the file has a mai entry with a different content. Run mai disconnect first, or remove the entry by hand.

View Source
var ErrKept = errors.New("connect: the entry stays, because other content of the file needs it")

ErrKept means that the entry stays, because other content of the file needs it, for example "version" of a hooks file that holds hooks. The record of the entry stays too.

Functions

func BinaryPath added in v3.0.1

func BinaryPath() (string, error)

BinaryPath returns the path of the mai binary that Prepare writes in the entries.

func Disconnect

func Disconnect(app string, m *manifest.Manifest) error

Disconnect removes each entry of app in m, and each file that mai connect made for app and that is empty now. It removes the records of the removed items. It continues after an *ErrChanged and returns all of them at the end. An entry that other content needs (ErrKept) stays with its record, and gives no error.

func DisconnectForce added in v3.0.1

func DisconnectForce(app string, m *manifest.Manifest) error

DisconnectForce is Disconnect with ForceRemoveEntry for each entry.

func ForceRemoveEntry

func ForceRemoveEntry(it manifest.Item) error

ForceRemoveEntry removes the entry of the item also when its content changed.

func Known

func Known(app string) bool

Known reports if mai connect knows the app.

func RemovalOrder added in v3.0.1

func RemovalOrder(items []manifest.Item) []manifest.Item

RemovalOrder returns the items with each "version" entry at the end, because a hook that stays needs it. The sequence of the other items stays.

func RemoveCreatedFile

func RemoveCreatedFile(it manifest.Item) (bool, error)

RemoveCreatedFile removes a file that mai connect made, when it holds no content now. A file with content stays, and the result is false.

func RemoveEntry

func RemoveEntry(it manifest.Item) error

RemoveEntry removes exactly the entry of the item. An entry that is gone already gives no error. An entry with a different hash gives *ErrChanged and the file stays the same.

Types

type ErrChanged

type ErrChanged struct {
	Item    manifest.Item
	Current string
	Diff    string
}

ErrChanged means that the entry in the file is not the entry that mai wrote. Diff shows the text that mai wrote and the text in the file now. The caller asks the user, and then calls ForceRemoveEntry or keeps the entry.

func (*ErrChanged) Error

func (e *ErrChanged) Error() string

type FileChange

type FileChange struct {
	Path    string
	Before  []byte
	After   []byte
	Existed bool
	Items   []manifest.Item
	// Notes are lines for the user about the file. An example is a line about an entry that
	// is not of mai at an earlier place of the entry of mai.
	Notes []string
	// Delete marks a file of earlier places that mai connect made. The file goes, because no
	// content stays in it.
	Delete bool
	// contains filtered or unexported fields
}

FileChange is the change of one file.

type Plan

type Plan struct {
	App   string
	Agent string
	Files []*FileChange
}

Plan is the set of changes of mai connect for one app.

func Prepare

func Prepare(home, app, agent string) (*Plan, error)

Prepare computes the changes for app and agent in the files under home. It writes nothing. A file that exists keeps each byte outside the entries of mai.

func PrepareWith added in v3.3.1

func PrepareWith(home, app, agent string, m *manifest.Manifest) (*Plan, error)

PrepareWith is Prepare with the manifest m of the instance, or nil. The plan also removes an entry of mai at an earlier place. An earlier version of mai wrote the entry there, and the app does not read that place. The manifest gives the record of that entry and of its file. With these records, the removal is the same as at mai disconnect. The containers that mai made for the entry go too. A file that mai made goes when no content stays in it. When a symbolic link makes the file of the earlier place the same file as a file where the plan writes, the file does not change, and only the record of the earlier place goes. PrepareWith writes nothing.

func (*Plan) Apply

func (p *Plan) Apply(m *manifest.Manifest) error

Apply writes the files of the plan and records each entry in m. A file that did not exist gets a record of type file too, so that mai disconnect can remove it. When an app wrote a file after Prepare, Apply makes the same entries in the new text of the file, so that the write of the app stays.

func (*Plan) Changed

func (p *Plan) Changed() bool

Changed reports if the plan changes a file.

func (*Plan) Diff

func (p *Plan) Diff() string

Diff returns a unified diff of each change of the plan. A file that goes has the name /dev/null after the change.

func (*Plan) Notes added in v3.3.1

func (p *Plan) Notes() []string

Notes returns the notes of each file of the plan, one line each.

Jump to

Keyboard shortcuts

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