Skip to content
internal/coord
Edit
On this page

Package coord implements the coordination layer that prevents concurrent agents from corrupting the working tree by guarding tree-mutating operations.

#internal/coord

#internal/coord

Package coord implements the coordination layer that prevents concurrent agents from corrupting the working tree by guarding tree-mutating operations. It checks whether the working tree is clean before allowing switch, merge, rebase, reset, and pull to proceed.

It also owns the other half of that coordination: what safegit does when git itself has an operation in flight. sequencer.Read reports the state and holds no policy; this package decides which commands may run against it (GuardInFlight) and what the operator is told when one may not (WayOutOf, RefuseInFlight). Both refusal paths -- the commit pipeline's and the passthrough guard's -- render their advice from here, so they cannot name different commands for the same state.

#DirtyState

Go go
type DirtyState struct

DirtyState describes why the working tree is not clean.

#SequencerContext

Go go
type SequencerContext struct

SequencerContext is a caller's DECLARATION that it is the conclusion path for an in-flight git operation.

Every ordinary caller passes nil, which means "refuse if anything is in flight" -- a commit, an amend, a reword or an undo taken while git is mid-merge or mid-cherry-pick builds its tree from a parent commit and hands commit-tree a single parent, silently discarding the operation's staged result and its second parent. A non-nil context means the caller IS the command that finishes the named operation and must be allowed to commit during exactly the state everyone else is refused for.

The declaration is checked, not trusted: a context naming an operation other than the one actually in flight is itself a refusal, as is a context supplied when nothing is in flight at all.

#WayOut

Go go
type WayOut struct

WayOut names the commands that end an in-flight operation: the one that concludes it, keeping the work, and the one that abandons it, throwing the work away.

It is the single authority for that advice. Every refusal safegit prints while an operation is in flight renders it from here, so no two refusals can name different commands for the same state.

#InFlightError

Go go
type InFlightError struct

InFlightError is the refusal a command owes an operator when git has an operation in flight that the command cannot run against. Its message states what is in flight, factually, and the way out.

#Check

Go go
func Check(ctx context.Context, gitDir string) (*DirtyState, error)

Check inspects the working tree of the repository whose git directory is gitDir. Returns nil if clean.

#WayOutOf

Go go
func WayOutOf(s sequencer.State) WayOut

WayOutOf returns the way out of the state s reports.

Where safegit owns the conclusion it names its own command; where it does not it names git's, and it never names git's rebase commands for a git am or the other way round -- the two share a state directory and an operator sent to the wrong one gets a refusal, not a conclusion.

#RefuseInFlight

Go go
func RefuseInFlight(operation string, s sequencer.State) string

RefuseInFlight renders the refusal text for one operation against one state.

#GuardInFlight

Go go
func GuardInFlight(gitDir, operation string, declared *SequencerContext) error

GuardInFlight is the one check that decides whether operation may run against whatever git has in flight in gitDir. It returns nil when it may, an *InFlightError when the state forbids it, and a plain error when the state could not be read at all -- which is also a refusal, because a state file safegit cannot parse is not evidence that nothing is in flight.

declared is the caller's SequencerContext: nil for every ordinary caller.

It is filesystem-only (sequencer.Read starts no subprocess), so putting it on the hot path of commit costs a handful of stat calls.

#DirtyState.Refuse

Go go
func (d *DirtyState) Refuse(operation string) string

Refuse formats a refusal message from a DirtyState.

The advice depends on WHY the tree is dirty. Ordinarily the dirt is the operator's own uncommitted work and committing it is the way forward. While git has an operation in flight the same dirt is the operation's conflict markers and staged result: committing it is exactly what safegit refuses to do (it would drop the operation's other parent and everything the pathspec does not name), so the message names the operation and the command that ends it instead of advice no one can follow.

#InFlightError.Error

Go go
func (e *InFlightError) Error() string { return RefuseInFlight(e.Operation, e.State) }

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • claudewheel A TUI Claude Code Launcher that lets you have more than one profile, manage sessions lifecycle, pick the exact CC version, model to use (even older unlisted ones), pick which GitHub account to use, etc.
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • fastware A batteries-included ASGI framework: msgspec JSON, a managed Granian server, dependency injection, SSE, WebSockets, auth, and a test client
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • selfdoc Static Site Generator that builds a project's documentation site directly from its source code, so the docs can never drift from the code they describe, with SEO/AEO, first-class blog, search, and cross-project linking built in
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
  • wesktop A Python framework that turns an ASGI web app into a desktop application, serving it from a local Granian server and displaying it in a native OS window via pywebview
Search