Documentation
¶
Overview ¶
Package memsync keeps a person's Claude Code memory the same on all of the person's machines (docs/hub/memory-sync.md).
Only the memory notes sync: <projects>/<entry>/memory/*.md, nothing else of the project. A project is known on every machine by the same id, its git remote (the folder differs from machine to machine). A folder without a remote syncs only when its person asks for it: by a key file in the folder (KeyFile) or, with LocalFolders on, by the folder's path. The hub keeps the notes of the machine's person; which person that is, the hub decides, not this package.
A sync is pull, then push, by the version of each note the machine saw last (kept in .harnessly-sync.json beside the notes). A note changed on both sides is a conflict: the local note stays as it is and the other version lands beside it as <name>.conflict-<version>.md, so both are kept. A failure leaves the local notes as they are.
Index ¶
- Constants
- func EntryName(cwd string) string
- func FolderID(ctx context.Context, cwd string, localFolders bool) string
- func FolderKey(cwd string) string
- func IsConflictCopy(name string) bool
- func MemoryDir(projectsDir, cwd string) string
- func NormalizeRemote(remote string) string
- func PathID(cwd string) string
- func ProjectID(ctx context.Context, cwd string) string
- type Client
- type Conflict
- type HTTPClient
- type Project
- type Report
- type Syncer
Constants ¶
const KeyFile = ".harnessly-memory-project"
KeyFile is the file in a folder whose first line names the folder's project, whatever its remote or path: `dir:<key>` is the id. The same key in folders of different machines is one project.
const StateFile = ".harnessly-sync.json"
StateFile is the file beside the notes that keeps the project id and the version of each note seen last.
const TrashDir = ".harnessly-sync-trash"
TrashDir keeps a copy of each note a sync removed because another machine deleted it.
Variables ¶
This section is empty.
Functions ¶
func EntryName ¶
EntryName is Claude Code's folder name for a project in cwd: every character but a letter or a digit is a dash.
func FolderID ¶
FolderID is the id of the project in cwd: its KeyFile, else its git remote; with localFolders a folder that has neither is known by its path. "" when the folder has no id and does not sync.
func FolderKey ¶
FolderKey is the project id a folder names for itself in its KeyFile ("dir:<key>"), "" without a valid one.
func IsConflictCopy ¶
IsConflictCopy says whether name is a copy a sync made of the other version of a note.
func NormalizeRemote ¶
NormalizeRemote is a git remote as a project id: host and path, lower case, without the user, the scheme, the port and .git. git@example.com:acme/app.git and https://example.com/acme/app are both git:example.com/acme/app.
Types ¶
type Client ¶
type Client interface {
Pull(ctx context.Context, projects []string) ([]hubproto.MemoryNote, error)
Put(ctx context.Context, put hubproto.MemoryPut) (hubproto.MemoryPutResult, error)
}
Client is the way to the person's memory in the hub: the agent of this machine (HTTPClient), or any service that speaks the same two calls (docs/hub/memory-sync.md).
type Conflict ¶
type Conflict struct {
Project string `json:"project"`
Name string `json:"name"`
Copy string `json:"copy"`
Machine string `json:"machine,omitempty"`
}
Conflict is a note changed on this machine and elsewhere: Copy is the file the other version was written to.
type HTTPClient ¶
HTTPClient calls POST <URL>/pull and <URL>/put, signed with the runtime's secret for the agent's memory relay.
func (*HTTPClient) Pull ¶
func (c *HTTPClient) Pull(ctx context.Context, projects []string) ([]hubproto.MemoryNote, error)
func (*HTTPClient) Put ¶
func (c *HTTPClient) Put(ctx context.Context, put hubproto.MemoryPut) (hubproto.MemoryPutResult, error)
type Report ¶
type Report struct {
At time.Time `json:"at"`
Projects int `json:"projects"`
Pulled []string `json:"pulled"`
Pushed []string `json:"pushed"`
Deleted []string `json:"deleted"`
Conflicts []Conflict `json:"conflicts"`
// Errors are the failures; the local notes they touch are as they were.
Errors []string `json:"errors"`
}
Report is what a sync did.