coordinate

package
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package coordinate is the native symbol-lock store for the NativeCoordinator (change 0013). One file per symbol, created with O_CREATE|O_EXCL so the filesystem itself decides the winner of a concurrent claim — the same atomic primitive grit uses on Azure via If-None-Match, but local.

File locks are single-machine by design. grit's Azure and S3 backends exist for teams; this is for one developer's parallel agents, which is why it ships with OpenPlus rather than requiring an install.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Held

type Held struct {
	Granted bool

	// On a refusal:
	BlockedBy     string
	BlockedSymbol string

	// On a reclaim of an expired lock:
	Reclaimed     bool
	ReclaimedFrom string
}

Held is the outcome of an Acquire attempt.

type NativeCoordinator

type NativeCoordinator struct {
	RepoRoot string
	// Expiry bounds how long a lock lives. Zero uses defaultLockExpiry.
	Expiry time.Duration
	// contains filtered or unexported fields
}

NativeCoordinator implements orchestrate.Coordinator natively: symbol locks backed by the file Store, worktrees via git, merges via git. No external binary (change 0013).

The Coordinator port from change 0012 is unchanged; this is a second adapter. Native is the default because it ships with OpenPlus; grit remains available for non-Go languages and multi-machine coordination.

func (*NativeCoordinator) Available

func (n *NativeCoordinator) Available() bool

Available reports whether coordination is possible: the project must be a git repository (worktrees and merges need it). No external binary is required.

func (*NativeCoordinator) Claim

func (n *NativeCoordinator) Claim(ctx context.Context, agent, intent string, syms []string) (orchestrate.Claim, error)

Claim validates every symbol exists in the Go index, acquires locks for all of them atomically, and creates a detached worktree for the agent. A nonexistent symbol is refused — granting a lock on nothing would let two agents both believe they had exclusive access to nothing.

func (*NativeCoordinator) Done

func (n *NativeCoordinator) Done(ctx context.Context, agent string) error

Done commits everything in the agent's worktree, merges it into the base branch, removes the worktree, and releases locks. A merge conflict is reported and the locks still release — a stuck merge must not hold symbols forever.

func (*NativeCoordinator) Release

func (n *NativeCoordinator) Release(ctx context.Context, agent string) error

Release is the failure path: remove the worktree and free locks, merging nothing. It must not error on cleanup.

type Store

type Store struct {
	Dir    string        // .openplus/locks under the project root
	Expiry time.Duration // 0 means locks never expire
	// contains filtered or unexported fields
}

Store is the file-backed lock table. Safe for concurrent use.

func NewStore

func NewStore(dir string, expiry time.Duration) *Store

NewStore constructs a Store rooted at Dir, with the given Expiry.

func (*Store) Acquire

func (s *Store) Acquire(agent, intent string, symbols []string) (Held, error)

Acquire attempts to lock every symbol for agent. The acquire is all-or- nothing: if any symbol is held (by another agent, within its expiry), nothing is locked and the first blocking holder is reported. A claim of zero symbols is an error — locking nothing grants nothing.

func (*Store) Holder

func (s *Store) Holder(symbol string) string

Holder returns the agent holding a symbol, or "" if none or unreadable.

func (*Store) ReleaseAgent

func (s *Store) ReleaseAgent(agent string) error

ReleaseAgent frees every lock held by agent. Releasing an agent that holds nothing succeeds quietly — the failure path must not error on cleanup.

Jump to

Keyboard shortcuts

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