identity

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 12 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 identity checks that the git author and committer identities a commit would use in a managed repo match the identity pinned in .abcd/config/identity.json, and recognises a machine identity in either role.

It is the single source of truth for the iss-62 managed-repo identity gate: `ahoy doctor` surfaces a divergence as a detection gap, and the installed pre-commit hook calls Check to fail closed before a mis-attributed commit can land — so a stray repo-local override (e.g. a sandbox "Test User") is caught up front rather than discovered later.

Index

Constants

View Source
const PinRelPath = ".abcd/config/identity.json"

PinRelPath is the committed identity pin, relative to the repo root.

Variables

This section is empty.

Functions

func DeclaredProductionMode added in v0.7.0

func DeclaredProductionMode(root string) (provenance.Mode, error)

DeclaredProductionMode is the repo's default production mode: the pin's optional member, or provenance.DefaultMode when the repo has no pin or the pin declares none. It is the ONE resolution of that question, so no surface re-derives "absent means hand-written" for itself.

func IsMachineAddress added in v0.11.1

func IsMachineAddress(role Role, email string) bool

IsMachineAddress reports the STRUCTURAL address signals alone, in role: a bot mailbox in either role, and a mailbox named for not being read as the author. The mailbox is the discriminator, never the host: a person's forge privacy address (`1234+name@users.noreply.github.com`) is not a machine's.

func IsMachineName added in v0.11.1

func IsMachineName(name string) bool

IsMachineName reports the STRUCTURAL name signal alone: the `[bot]` suffix the forge stamps on an app's account name. It names no vendor, so a reader that must not decide on a vendor token (the contributors page) can use it.

func IsToolIdentity added in v0.11.1

func IsToolIdentity(role Role, name, email string) bool

IsToolIdentity reports whether name <email> is a machine identity in the given role of a commit: an AI vendor's name or mail domain, the forge's own `[bot]` account, or a bot mailbox, in either role; and, in the AUTHOR role only, a mailbox named for not being read (`noreply@`). The asymmetry is the attribution gate's own — the forge stamps `GitHub <noreply@github.com>` as the committer of every web-UI merge made on a human's click, so it passes as a committer and nowhere else.

It is how the routine case becomes machine-visible: an autonomous run that commits under the harness's default identity is flagged wherever the identity gate runs, before the attribution gate refuses the pull request in CI.

func Outranking added in v0.11.1

func Outranking(root string, want Effective) ([]string, error)

Outranking names every source that outranks a repository's user.name and user.email for either role and holds a value other than want: a GIT_AUTHOR_* / GIT_COMMITTER_* environment override, or an author.* / committer.* config key. Writing repo-local user.* cannot change what such a source stamps, so a caller that would write it asks this first and, when the list is not empty, says what to unset instead of writing to no effect.

func WriteLocal added in v0.11.1

func WriteLocal(root string, id Effective) error

WriteLocal sets user.name and user.email in the repository's own .git/config (never the global or system file), as the person running it: a plain git invocation, never a privileged one. Both fields are required.

func WritePin

func WritePin(root string, p Pin) error

WritePin writes the pin to .abcd/config/identity.json (creating the config directory), pretty-printed with a trailing newline. It is how a repo adopts the identity gate. Both fields are required.

Types

type Effective

type Effective struct {
	Name  string
	Email string
}

Effective is the identity git would actually stamp on a commit in the repo, resolved as git resolves the author: the GIT_AUTHOR_NAME/GIT_AUTHOR_EMAIL environment overrides first, then git config's local > global > system layering.

func EffectiveCommitter added in v0.11.1

func EffectiveCommitter(root string) (Effective, error)

EffectiveCommitter returns the committer identity git would stamp on a commit in root, resolved exactly as EffectiveIdentity resolves the author: GIT_COMMITTER_NAME / GIT_COMMITTER_EMAIL first, then committer.name / committer.email, then user.name / user.email. An unset field is empty, never fabricated.

func EffectiveIdentity

func EffectiveIdentity(root string) (Effective, error)

EffectiveIdentity returns the author identity git would stamp on a commit in root. Each field is resolved the way git resolves it: the GIT_AUTHOR_NAME / GIT_AUTHOR_EMAIL environment override first (an agent or CI sandbox that exports one lands a mis-attributed commit a config-only check would wave through), then the role's own author.name / author.email config key, which git ranks ahead of user.* (iss-2609261454332615), then user.name / user.email. Config keys follow git's layering: command-line configuration (`git -c`, as a hook inherits it), then local, global and system. An unset name or email yields an empty field, not an error.

type Pin

type Pin struct {
	Name  string `json:"name"`
	Email string `json:"email"`
	// ProductionMode is the repo's DEFAULT production mode: how the text of a
	// record this repository mints was produced, unless the minting verb says
	// otherwise (itd-178). It rides the pin rather than a second config file
	// because this is already the repo's attribution seam and already has a
	// reader; a second file would be a second reader of the same question.
	//
	// Optional and omitted when empty, so a pin written before the member existed
	// round-trips byte-identically. An absent member means provenance.DefaultMode.
	// The self-contained pre-commit identity guard seds `name` and `email` out of
	// this file by name, so an added member is invisible to it.
	ProductionMode string `json:"production_mode,omitempty"`
}

Pin is the expected commit identity, committed so every checkout enforces the same value regardless of local git config.

func LoadPin

func LoadPin(root string) (Pin, bool, error)

LoadPin reads .abcd/config/identity.json. It returns (pin, true, nil) when the pin is present and well formed, (Pin{}, false, nil) when the file is absent, and an error when it is malformed or missing a field — validating this external input rather than trusting it.

type Proposal added in v0.11.1

type Proposal struct {
	Identity Effective
	// From names the source for the person being asked.
	From string
}

Proposal is the human identity the gate offers when the effective one diverges, and where it was read from.

func Propose added in v0.11.1

func Propose(root string) (Proposal, bool, error)

Propose returns the identity to offer: the committed pin, else the global git identity (user.name/user.email in the caller's global config). The chain is disk-only by decision (itd-131, adr-38): no network lookup in an implicit path. A machine identity is never proposed. ok is false when neither source holds a complete human identity.

type Result

type Result struct {
	Status    Status
	Pin       Pin
	Effective Effective
	Reason    string

	// Committer is the committer identity git would stamp (EffectiveCommitter).
	Committer Effective
	// CommitterDiverges reports a committer that differs from the author and is
	// not the pinned identity either: a GIT_COMMITTER_* override, a committer.*
	// config key, or an author override the committer does not share. A
	// committer that is the same wrong identity as the author is not reported
	// again — the author status already says so, and one fix mends both.
	CommitterDiverges bool
	// CommitterReason says what diverges, for the person reading the gap.
	CommitterReason string

	// AuthorIsTool and CommitterIsTool report a machine identity in that role
	// (IsToolIdentity), pinned or not: the routine case, made visible.
	AuthorIsTool    bool
	CommitterIsTool bool
}

Result carries the comparison outcome and the identities for reporting.

Status and Effective describe the AUTHOR, with the meaning they have always had. The committer is reported beside them rather than folded into Status, so every existing reader of the author statuses reads exactly what it did.

func Check

func Check(root string) (Result, error)

Check resolves the effective author and committer, loads the pin, and compares them.

func (Result) Blocks

func (r Result) Blocks() bool

Blocks reports whether a pre-commit hook should refuse the commit. A mismatch or an unset author identity blocks, and so does a committer that diverges from the pin; a match, or an un-pinned (opted-out) repo, does not — an absent pin must never break commits in a repo that has not adopted the gate.

type Role added in v0.11.1

type Role string

Role is one of the two identities git stamps on a commit. The author is who wrote the change and the committer is who recorded it; the contributor graph reads both, so the gate resolves both.

const (
	// RoleAuthor is the commit's author (%an/%ae).
	RoleAuthor Role = "author"
	// RoleCommitter is the commit's committer (%cn/%ce).
	RoleCommitter Role = "committer"
)

type Status

type Status int

Status is the outcome of comparing the effective identity to the pin.

const (
	// StatusOK: a pin exists and the effective identity matches it.
	StatusOK Status = iota
	// StatusNoPin: no identity.json — the repo has not opted into the gate.
	StatusNoPin
	// StatusMismatch: a pin exists and the effective identity differs.
	StatusMismatch
	// StatusUnset: a pin exists but git has no author identity configured.
	StatusUnset
)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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