trailers

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package trailers provides parsing and formatting for Entire commit message trailers. Trailers are key-value metadata appended to git commit messages following the git trailer convention (key: value format after a blank line).

Index

Constants

View Source
const (
	// MetadataTrailerKey points to the metadata directory within a commit tree.
	MetadataTrailerKey = "Entire-Metadata"

	// StrategyTrailerKey indicates which strategy created the commit.
	StrategyTrailerKey = "Entire-Strategy"

	// SessionTrailerKey identifies which session created a commit.
	SessionTrailerKey = "Entire-Session"

	// CheckpointTrailerKey links commits to their checkpoint metadata on entire/checkpoints/v1.
	// Format: a checkpoint ID — either a legacy 12-hex ID (e.g. "a3b2c4d5e6f7")
	// or a 26-char ULID (see checkpoint/id.CheckpointPattern).
	// This trailer survives git amend and rebase operations.
	CheckpointTrailerKey = "Entire-Checkpoint"

	// AgentTrailerKey identifies the agent that created a checkpoint.
	// Format: human-readable agent name e.g. "Claude Code", "Cursor"
	AgentTrailerKey = "Entire-Agent"

	// OPFAppliedTrailerKey marks an entire/checkpoints/v1 commit whose blobs
	// have been redacted by the OpenAI Privacy Filter (the opt-in 9th,
	// network-backed layer, applied on top of the 8 regex layers).
	// Format: literal "true"; the trailer is omitted entirely when OPF was
	// not applied. The pre-push rewrite path treats commits lacking this
	// trailer as candidates to OPF-redact before they reach the remote.
	OPFAppliedTrailerKey = "Entire-OPF-Applied"

	// OPFAppliedTrailerValue is the only value that means "OPF ran." Any
	// other value (or trailer absence) is treated as "not applied" so a
	// future "false" / "skipped" value never accidentally enables OPF.
	OPFAppliedTrailerValue = "true"
)

Trailer key constants used in commit messages.

Variables

This section is empty.

Functions

func AppendCheckpointTrailer added in v0.5.3

func AppendCheckpointTrailer(message, checkpointID string) string

AppendCheckpointTrailer appends Entire-Checkpoint in trailer-aware format. If the message already ends with a trailer paragraph, append directly to it; otherwise add a blank line before starting a new trailer block.

func AppendOPFAppliedTrailer added in v0.7.8

func AppendOPFAppliedTrailer(message string) string

AppendOPFAppliedTrailer appends `Entire-OPF-Applied: true` in trailer-aware format. Idempotent: if the message already carries the trailer with value "true", the original message is returned unchanged so re-parenting an already-applied commit doesn't duplicate the trailer.

func FormatCheckpoint

func FormatCheckpoint(message string, cpID checkpointID.CheckpointID) string

FormatCheckpoint creates a commit message with a checkpoint trailer. This links user commits to their checkpoint metadata on entire/checkpoints/v1 branch.

func HasOPFApplied added in v0.7.8

func HasOPFApplied(commitMessage string) bool

HasOPFApplied reports whether the commit message carries an `Entire-OPF-Applied: true` trailer. Any other value (or absence) is treated as "OPF not applied" so the pre-push rewrite considers the commit a candidate for OPF redaction. Pinning the value to literal "true" — rather than just trailer presence — prevents a future "Entire-OPF-Applied: false" or "skipped" from accidentally meaning "yes, applied."

func IsTrailerLine added in v0.5.3

func IsTrailerLine(line string) bool

IsTrailerLine reports whether a line matches git trailer format.

func ParseAllCheckpoints added in v0.5.0

func ParseAllCheckpoints(commitMessage string) []checkpointID.CheckpointID

ParseAllCheckpoints extracts all checkpoint IDs from a commit message. Returns a slice of CheckpointIDs (may be empty if none found). Duplicate IDs are deduplicated while preserving order. This is useful for squash merge commits that contain multiple Entire-Checkpoint trailers.

func ParseCheckpoint

func ParseCheckpoint(commitMessage string) (checkpointID.CheckpointID, bool)

ParseCheckpoint extracts the checkpoint ID from a commit message. Returns the CheckpointID and true if found, empty ID and false otherwise.

func ParseMetadata

func ParseMetadata(commitMessage string) (string, bool)

ParseMetadata extracts metadata dir from commit message. Returns the metadata directory and true if found, empty string and false otherwise.

func ParseSession

func ParseSession(commitMessage string) (string, bool)

ParseSession extracts the session ID from a commit message. Returns the session ID and true if found, empty string and false otherwise. Note: If multiple Entire-Session trailers exist, this returns only the first one.

func RemoveCheckpointTrailers added in v0.11.5

func RemoveCheckpointTrailers(message string, drop func(checkpointID.CheckpointID) bool) (string, []checkpointID.CheckpointID)

RemoveCheckpointTrailers removes every whole Entire-Checkpoint trailer line whose ID drop selects, anywhere between the subject paragraph and a scissors line, and returns the new message with the IDs removed (nil when the message is unchanged). It does not try to reproduce git's trailer-block rules (mixed blocks, a "(cherry picked from ...)" note, custom comment characters): a line that is exactly a checkpoint trailer is one in every form git accepts, and leaving one behind would let an amend keep a deleted checkpoint alive. Indentation is ignored, since a squash message indents the squashed commits' messages. Prose that merely mentions an ID is not a whole trailer line and stays. Blank lines a removal leaves doubled are collapsed, and trailing blank lines are trimmed unless a scissors line follows; nothing at or below the scissors line is touched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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