merge

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 15 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 merge is the deterministic, record-aware three-way merge for tasks JSONL files — the Go port of lib/tasks/jsonl_merge.rb.

The merge is field-level; ordering stays ours-first while the final DFS walk guarantees parent-before-child structural validity. Nothing here touches a file: Merge builds and VALIDATES entirely in memory, and only a result that passed carries text. That ordering is the whole safety property — a write-then-validate driver would leave a rejected merge's output in the working file looking clean, and returning nonzero afterwards could not take it back.

Index

Constants

View Source
const (
	DecisionDeleted                      = "deleted"
	DecisionDeletedByOurs                = "deleted_by_ours"
	DecisionDeletedByTheirs              = "deleted_by_theirs"
	DecisionKeptTheirsEditOverOursDelete = "kept_theirs_edit_over_ours_delete"
	DecisionKeptOursEditOverTheirsDelete = "kept_ours_edit_over_theirs_delete"
	DecisionAddedOurs                    = "added_ours"
	DecisionAddedTheirs                  = "added_theirs"
	DecisionMergedConcurrentAdd          = "merged_concurrent_add"
	DecisionMergedFields                 = "merged_fields"
	DecisionRestoredAncestor             = "restored_ancestor_for_edited_descendant"
	DecisionOursOrderingConflict         = "ours_ordering_conflict"
)

The decisions a merge can record. They are the audit log's vocabulary: a merge that silently loses or duplicates a task is the failure nobody notices until the data is already wrong, so every record the merge touched says what happened to it and why.

View Source
const (
	ReasonRemovalWins  = "removal_wins"
	ReasonClaimHolds   = "claim_holds"
	ReasonEarlierClaim = "earlier_claim"
	ReasonLaterIntent  = "later_intent"

	ClearedOnNonTask  = "cleared_on_non_task"
	ClearedOnProposal = "cleared_on_proposal"
	ClearedOnClose    = "cleared_on_close"
)

Why one delegation marker outranked the other, and why a resolved marker was then cleared.

View Source
const Version = check.Version

Version is the schema version this binary merges. Both SIDES must declare it.

Variables

This section is empty.

Functions

func FormatEvent

func FormatEvent(event Event) string

FormatEvent renders one decision the way the log carries it.

func RunDriver

func RunDriver(args []string, stdout, stderr io.Writer, verbose bool) int

RunDriver is `tasks merge-driver <base> <ours> <theirs> <pathname> [marker-size] [ours-label] [theirs-label]` — the Git merge driver.

Git's contract is what shapes the failure path. Git hands the driver three TEMP files and copies whatever %A holds back over the working file when the driver returns, on failure exactly as on success. Git seeds %A with the ours blob and has already checked that same blob into the working file before the driver runs. So leaving %A untouched does NOT mean "wrote nothing": it means the working file is left as ours' full content, valid JSONL, no markers anywhere — a file `tasks check` passes and the reflex `git add tasks.jsonl` stages, silently discarding all of theirs. That is the failure this refusal path exists to prevent.

So a refusal writes what Git's own text driver would: ours verbatim, theirs verbatim, both fenced. The path stays UU with a nonzero exit, `tasks check` fails on the marker lines, and neither side has been summarized or dropped.

The rule for anyone changing this: never write a MERGED result to %A before it is known valid. Merge builds and validates entirely in memory and only a result that passed carries text, so the merged write below is reached only by a merge that is already known good.

Types

type DelegationEvent

type DelegationEvent struct {
	Reason  string
	Holder  string
	Cleared string
}

DelegationEvent is the delegation half of one record's decision: which rule decided the marker, who holds it afterwards, and whether the resolved record then dropped it.

type Event

type Event struct {
	ID            string
	Decision      string
	Conflicts     []string
	LowConfidence []string
	Delegation    *DelegationEvent
}

Event is one record's decision.

type Result

type Result struct {
	Text   string
	Events []Event
	Error  string
}

Result is one merge attempt. A failed merge carries no text at all: there is no partial result a caller could be tempted to write.

func Merge

func Merge(baseText, oursText, theirsText string) Result

Merge resolves three sides into one validated JSONL text.

func (Result) LogLines

func (r Result) LogLines(pathname string) []string

LogLines is the audit trail appended beside the store. A failed merge writes its reason and nothing else — there are no decisions to report, because none were applied.

func (Result) OK

func (r Result) OK() bool

OK reports whether the merge produced a validated result.

Jump to

Keyboard shortcuts

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