memsync

package
v0.16.397 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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.

View Source
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

func EntryName(cwd string) string

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

func FolderID(ctx context.Context, cwd string, localFolders bool) string

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

func FolderKey(cwd string) string

FolderKey is the project id a folder names for itself in its KeyFile ("dir:<key>"), "" without a valid one.

func IsConflictCopy

func IsConflictCopy(name string) bool

IsConflictCopy says whether name is a copy a sync made of the other version of a note.

func MemoryDir

func MemoryDir(projectsDir, cwd string) string

MemoryDir is Claude Code's memory folder of the project in cwd.

func NormalizeRemote

func NormalizeRemote(remote string) string

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.

func PathID

func PathID(cwd string) string

PathID is the id of a folder without a remote, by its absolute path ("dir:<path>"); "" for a path that is no id (a space in it) or for a relative one. Machines that keep the folder at the same path share the project.

func ProjectID

func ProjectID(ctx context.Context, cwd string) string

ProjectID is the id of the project in cwd: its git remote (origin, else the first one); "" without a remote.

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

type HTTPClient struct {
	URL    string
	Secret []byte
	HTTP   *http.Client
}

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

type Project

type Project struct {
	ID  string `json:"id"`
	Dir string `json:"dir"`
}

Project is a memory folder and the id it syncs under.

func Known

func Known(projectsDir string) []Project

Known are the memory folders under Claude Code's projects folder that synced before (they keep their project id).

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.

type Syncer

type Syncer struct {
	Client Client
	Now    func() time.Time
	// contains filtered or unexported fields
}

Syncer syncs memory folders through a Client; one sync at a time.

func (*Syncer) Sync

func (s *Syncer) Sync(ctx context.Context, projects []Project) Report

Sync pulls and pushes the notes of the projects. A project whose pull fails is left as it is.

Jump to

Keyboard shortcuts

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