Documentation
¶
Overview ¶
Package central manages the lore central repository as a typed handle. It owns the projects/<name>/<agent-dir>/ layout and the git operations needed to maintain it.
Index ¶
- func Exists(path string) (bool, error)
- func IsEmpty(dir string) (bool, error)
- type AgentDirReplacement
- type Central
- func (c *Central) AddAgentDir(name, dirName, sourcePath string) (destPath string, undo func() error, err error)
- func (c *Central) Commit(message string) error
- func (c *Central) CommitExists(sha string) (bool, error)
- func (c *Central) CommitPaths(message string, paths ...string) error
- func (c *Central) HasRemote() (bool, error)
- func (c *Central) HeadSHA() (string, error)
- func (c *Central) ListProjects() ([]string, error)
- func (c *Central) LockMutations() (func() error, error)
- func (c *Central) ProjectAgentDirs(name string) ([]string, error)
- func (c *Central) ProjectPath(name, dirName string) string
- func (c *Central) RecoverReplacements() error
- func (c *Central) RemoveProjectStaged(name string) (undo func() error, err error)
- func (c *Central) RenameProjectStaged(old, newName string) (undo func() error, err error)
- func (c *Central) ScopedDirty(projectName string, dirNames []string) (bool, error)
- func (c *Central) Snapshot(commit, projectName, dirName string) (reconcile.Snapshot, []reconcile.Issue, error)
- func (c *Central) StageAgentDirReplacements(replacements []AgentDirReplacement) (*ReplacementSet, error)
- type ReplacementSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEmpty ¶
IsEmpty reports whether dir is empty (or contains only known OS-metadata junk), or doesn't exist. Used by `lore init` to decide whether to refuse onboarding a non-empty default location.
The denylist exists because `ls` hides dotfiles by default: a user on macOS with only a `.DS_Store` in ~/agent-context sees an apparently empty dir but `lore init` would refuse, producing a confusing error. The denylist is deliberately narrow (four well-known names); a user who genuinely places `.foo` in this dir is respected.
Types ¶
type AgentDirReplacement ¶
AgentDirReplacement describes one project copy that replaces central.
type Central ¶
type Central struct {
Path string // absolute path
}
Central is a typed handle on a central repo on disk.
func Initialize ¶
Initialize creates path (if missing), runs git init, lays down the canonical repo structure (README.md + projects/.gitkeep), and makes an initial commit so the repo isn't in unborn-HEAD state.
Atomicity: if Initialize created the directory and any step after the MkdirAll fails, the directory is removed before returning. This means a retry sees a clean slate rather than a half-built repo. If path already existed when we were called, we leave it alone on failure (it's not ours to delete).
Caller is responsible for higher-level checks like "is the dir non-empty".
func Open ¶
Open returns a handle for an existing central repo. Verifies path exists and contains a .git directory; further structural validation (e.g. `projects/` present) is left to `lore use` in a later slice.
func (*Central) AddAgentDir ¶
func (c *Central) AddAgentDir(name, dirName, sourcePath string) ( destPath string, undo func() error, err error, )
AddAgentDir copies sourcePath into central and stages the new copy. Returns the absolute destination path along with an undo closure the orchestrator drives on failure:
- undo() removes the central copy and drops the staged path.
Commits are NOT part of AddAgentDir's contract: a single `lore add` may onboard multiple agent dirs and the orchestrator emits one commit covering them all via Central.Commit once every per-dir side effect has succeeded.
Refuses with CodeConflict if projects/<name>/<dirName>/ already exists. A project directory that already contains *other* agent dirs is fine (the slice-5 multi-dir case: `.claude` is tracked, user runs `lore add --dir .cursor` to extend the same project).
func (*Central) Commit ¶
Commit creates a commit on the central repo with the given message, using the user's real git identity (no inline -c flags) per ADR 0003. Stages must already be set up by prior AddAgentDir / RemoveAgentDir calls.
func (*Central) CommitExists ¶
CommitExists reports whether a SHA remains resolvable as a commit.
func (*Central) CommitPaths ¶
CommitPaths commits only the staged changes under the given repo-relative pathspecs, leaving any unrelated staged content in central untouched. mv uses this so a rename can't fold a user's pre-staged work elsewhere in central into the rename commit. Pass both the old and new project paths so git records the delete-at-old and add-at-new sides of the rename. Uses the real git identity per ADR 0003, same as Commit.
func (*Central) HasRemote ¶
HasRemote reports whether the central repo has any configured git remote. Used to decide whether to print the "no remote configured" hint.
func (*Central) ListProjects ¶
ListProjects returns the names of every tracked project (the subdirectories of projects/), in deterministic (sorted) order. Skips the .gitkeep placeholder and any non-directory entries. Returns an empty slice (never nil-vs-empty surprises) when nothing is tracked.
central is the authority on which projects exist; pull and list enumerate from here so projects that are not placed on this machine remain visible.
func (*Central) LockMutations ¶
LockMutations serializes central mutations until the returned function runs.
func (*Central) ProjectAgentDirs ¶
ProjectAgentDirs returns the names of every agent directory tracked under projects/<name>/, in deterministic (sorted) order. Returns CodeNotFound when the project dir is missing or empty.
The sorted result is the source of truth for "what dirs does this project have?". State's per-project AgentDirs is a cache populated from this when state was migrated from v1 or when the orchestrator needs to backfill.
func (*Central) ProjectPath ¶
ProjectPath returns the absolute on-disk location of a tracked agent directory inside the central repo. Pure path computation; does not check that the path exists.
func (*Central) RecoverReplacements ¶
RecoverReplacements repairs or clears replacements left by an interrupted push.
func (*Central) RemoveProjectStaged ¶
RemoveProjectStaged runs `git rm -r projects/<name>/` inside the central repo, staging the deletion of the entire project directory (and every agent dir under it). Returns an undo closure the orchestrator drives on failure:
- undo() restores both the index and the working tree via `git checkout HEAD -- projects/<name>/`, mirroring git's own "oops, I git rm'd" recovery primitive.
Commits are NOT part of RemoveProjectStaged's contract: the orchestrator emits the rm commit via Central.Commit at the success boundary, same as AddAgentDir + Commit.
Refuses with CodeNotFound if projects/<name>/ does not exist in the central repo working tree. Refuses with CodeRefusedSafety if the project directory has uncommitted modifications in central's working tree, so a `git rm` doesn't silently destroy local edits.
func (*Central) RenameProjectStaged ¶
RenameProjectStaged runs `git mv projects/<old> projects/<new>` inside the central repo, staging the rename of the entire project directory (and every agent dir under it). Returns an undo closure the orchestrator drives on failure:
- undo() reverses the staged rename with `git mv projects/<new> projects/<old>`, restoring both the index and the working tree. Relies on the orchestrator's Commit not having fired yet, so the reverse move re-stages cleanly against the same HEAD.
Commits are NOT part of RenameProjectStaged's contract: the orchestrator emits the mv commit via Central.Commit at the success boundary, same as RemoveProjectStaged + Commit.
Refuses with CodeNotFound if projects/<old>/ does not exist, with CodeConflict if projects/<new>/ already exists, and with CodeRefusedSafety if projects/<old>/ has uncommitted changes (the reverse-git-mv undo can't cleanly account for staged edits or untracked files, so we hand control back to commit / stash / discard first).
func (*Central) ScopedDirty ¶
ScopedDirty reports whether central has working-tree content under the selected agent directories that differs from committed HEAD.
func (*Central) Snapshot ¶
func (c *Central) Snapshot(commit, projectName, dirName string) (reconcile.Snapshot, []reconcile.Issue, error)
Snapshot reads one agent directory exactly as stored at a commit.
func (*Central) StageAgentDirReplacements ¶
func (c *Central) StageAgentDirReplacements(replacements []AgentDirReplacement) (*ReplacementSet, error)
StageAgentDirReplacements publishes and stages a recoverable replacement set.
type ReplacementSet ¶
type ReplacementSet struct {
// contains filtered or unexported fields
}
ReplacementSet owns staged central replacements until commit or rollback.
func (*ReplacementSet) Finish ¶
func (s *ReplacementSet) Finish() error
Finish discards committed replacement backups.
func (*ReplacementSet) Paths ¶
func (s *ReplacementSet) Paths() []string
Paths returns the repo-relative pathspecs owned by this replacement set.
func (*ReplacementSet) Rollback ¶
func (s *ReplacementSet) Rollback() error
Rollback restores central content and its index to HEAD.