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
- Variables
- func BinaryPath() (string, error)
- func Disconnect(app string, m *manifest.Manifest) error
- func DisconnectForce(app string, m *manifest.Manifest) error
- func ForceRemoveEntry(it manifest.Item) error
- func Known(app string) bool
- func RemovalOrder(items []manifest.Item) []manifest.Item
- func RemoveCreatedFile(it manifest.Item) (bool, error)
- func RemoveEntry(it manifest.Item) error
- type ErrChanged
- type FileChange
- type Plan
Constants ¶
const TOMLPointer = "toml:mcp_servers.mai"
TOMLPointer is the pointer of the MCP table that mai writes in the config.toml of Codex.
Variables ¶
var Apps = []string{"antigravity", "claude", "codex", "copilot", "cursor"}
Apps are the names of the apps that mai connect knows.
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.
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.
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
BinaryPath returns the path of the mai binary that Prepare writes in the entries.
func Disconnect ¶
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
DisconnectForce is Disconnect with ForceRemoveEntry for each entry.
func ForceRemoveEntry ¶
ForceRemoveEntry removes the entry of the item also when its content changed.
func RemovalOrder ¶ added in v3.0.1
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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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.