util

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CommitAttributionSummaryFile = ".commit-attribution-summary"
View Source
const HookErrorLogBasename = "hook-errors.log"

HookErrorLogBasename is the filename used for the global capture sidecar log. Hooks themselves remain non-blocking (`|| true` is preserved); this file gives doctor a place to read failures that would otherwise be silent.

View Source
const PreCommitCheckpointFile = ".pre-commit-checkpoint"
View Source
const ShortIDLen = 8

ShortIDLen is the number of characters shown in human-facing checkpoint IDs.

Variables

This section is empty.

Functions

func AppConfigDir

func AppConfigDir() (string, error)

AppConfigDir returns the global Semantica config directory.

func AppendActivityLog

func AppendActivityLog(semDir, format string, args ...any)

AppendActivityLog appends a timestamped log line to .semantica/activity.log.

func AppendHookError added in v0.3.9

func AppendHookError(provider, hook, msg string)

AppendHookError writes a JSONL entry to the global sidecar log at <AppConfigDir>/hook-errors.log. Write failures are ignored so diagnostics never block provider hooks.

The log directory is auto-created. Provider and hook may be empty for failures that do not have that context (e.g. unknown provider).

func AttributionV2Enabled added in v0.6.0

func AttributionV2Enabled(semDir string) bool

AttributionV2Enabled reads the environment override, then repository settings.

func CommitAttributionSummaryPath

func CommitAttributionSummaryPath(semDir string) string

func EnsureGitignoreEntries

func EnsureGitignoreEntries(repoRoot string, entries []string) error

EnsureGitignoreEntries appends any missing entries to the repo's .gitignore under a "# Semantica" section. Entries that already appear (with or without trailing slash for directories) are skipped.

func HookErrorLogPath added in v0.3.9

func HookErrorLogPath() (string, error)

HookErrorLogPath exposes the sidecar log location for diagnostic messages.

func IsConnected

func IsConnected(semDir string) bool

IsConnected returns true if the repo is connected to Semantica.

func IsEnabled

func IsEnabled(semDir string) bool

IsEnabled checks whether Semantica is enabled by looking for the marker file (.semantica/enabled) rather than parsing settings.json.

func IsEnabledAt

func IsEnabledAt(repoPath string) bool

IsEnabledAt checks whether Semantica is enabled for a repo at the given path.

func IsPlaybookEnabled

func IsPlaybookEnabled(semDir string) bool

IsPlaybookEnabled returns true if the auto-playbook automation is enabled.

func OpenWorkerLog

func OpenWorkerLog(semDir string) (*os.File, error)

OpenWorkerLog opens .semantica/worker.log in append mode. The caller is responsible for closing the returned file.

func PreCommitCheckpointPath

func PreCommitCheckpointPath(semDir string) string

func ResolveExecutable

func ResolveExecutable(names []string, extraCandidates ...string) string

ResolveExecutable returns the first matching executable path for any of the provided binary names. It checks PATH first, then common user and package manager install locations used across the supported platforms.

func SettingsPath

func SettingsPath(semDir string) string

func ShortID

func ShortID(full string) string

ShortID returns the first ShortIDLen characters of a full ID. If the input is shorter than ShortIDLen, it is returned unchanged.

func TrailersEnabled

func TrailersEnabled(semDir string) bool

TrailersEnabled returns whether attribution and diagnostics trailers are on. Defaults to true when the key is absent or settings cannot be read.

func WriteSettings

func WriteSettings(semDir string, s Settings) error

WriteSettings atomically replaces settings.json and updates the enabled marker used by hooks that cannot parse JSON.

Types

type Automations

type Automations struct {
	Playbook PlaybookAutomation
	// contains filtered or unexported fields
}

Automations configures repository automation while preserving unknown fields.

func (Automations) MarshalJSON added in v0.6.1

func (a Automations) MarshalJSON() ([]byte, error)

func (*Automations) UnmarshalJSON added in v0.6.1

func (a *Automations) UnmarshalJSON(b []byte) error

type HookErrorEntry added in v0.3.9

type HookErrorEntry struct {
	Timestamp string `json:"ts"`
	Provider  string `json:"provider,omitempty"`
	Hook      string `json:"hook,omitempty"`
	Message   string `json:"msg"`
}

HookErrorEntry is the JSONL shape doctor consumes when grouping hook errors by provider/hook.

func ReadHookErrorTail added in v0.3.9

func ReadHookErrorTail(maxLines int) ([]HookErrorEntry, error)

ReadHookErrorTail reads up to maxLines most-recent JSONL entries from the hook-errors.log. Malformed or truncated lines are silently skipped so a partially-written record near the end of the file does not break diagnostics.

type PlaybookAutomation

type PlaybookAutomation struct {
	Enabled bool
	// contains filtered or unexported fields
}

PlaybookAutomation configures playbook generation while preserving unknown fields.

func (PlaybookAutomation) MarshalJSON added in v0.6.1

func (p PlaybookAutomation) MarshalJSON() ([]byte, error)

func (*PlaybookAutomation) UnmarshalJSON added in v0.6.1

func (p *PlaybookAutomation) UnmarshalJSON(b []byte) error

type Settings

type Settings struct {
	Enabled         bool
	Version         int
	Providers       []string
	Trailers        *bool
	Automations     *Automations
	Connected       bool
	ConnectedRepoID string
	// AttributionV2 enables tool-delta scoring. An absent value is disabled.
	AttributionV2 *bool
	// contains filtered or unexported fields
}

Settings is the repository configuration stored in settings.json. Unknown fields are preserved when the file is rewritten.

func ReadSettings

func ReadSettings(semDir string) (Settings, error)

ReadSettings reads the settings file from the given .semantica directory. Returns zero-value Settings (Enabled: false) if the file is missing. Returns an error if the file exists but cannot be parsed, so callers can distinguish "not configured" from "settings format has changed."

func (Settings) MarshalJSON added in v0.6.1

func (s Settings) MarshalJSON() ([]byte, error)

func (*Settings) UnmarshalJSON added in v0.6.1

func (s *Settings) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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