Help us shape the future of Go! Take the 2026 Go Developer Survey

skilljournal

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package skilljournal makes a skill import transaction restart-safe.

A transaction publishes several imported trees, the configuration file, and the lockfile with independent renames. No filesystem makes that sequence one atomic step, so the transaction instead records its intent — and a durable copy of everything it is about to replace — in a journal inside its staging directory before it touches anything live.

If the process dies part way through, the journal survives. The next operation to enter the project lock calls Recover, which rolls the whole transaction back to the exact state it started from: no skill is left missing or half-published, and configuration, imported trees, and lock state can never be stranded at different generations.

Index

Constants

View Source
const (
	// StagingDirName is the transaction staging directory inside the imported
	// skill tier. Keeping it on the same filesystem guarantees rename-based
	// publication rather than a cross-device copy. It is hidden so skill
	// enumeration never mistakes it for an imported skill.
	StagingDirName = ".staging"
	// FileName is the journal document inside the staging directory.
	FileName = "journal.json"

	// StagedTreePrefix names a fully materialized replacement tree.
	StagedTreePrefix = "new-"
	// WriteBackupPrefix names the previous tree of a replaced skill.
	WriteBackupPrefix = "old-"
	// DeleteBackupPrefix names the previous tree of a deleted skill.
	DeleteBackupPrefix = "removed-"
	// ConfigBackupName is the pre-transaction configuration file copy.
	ConfigBackupName = "config.backup"
	// LockBackupName is the pre-transaction lockfile copy.
	LockBackupName = "lock.backup"
)
View Source
const AdoptionVersion = 2

AdoptionVersion extends recovery with explicitly retired local skill slots.

View Source
const LocalBackupPrefix = "local-"

LocalBackupPrefix distinguishes local retirements from imported writes.

View Source
const Version = 1

Version is the journal schema version. A journal recording a different version is rejected rather than guessed at, because recovering from a misread journal could destroy local work.

Variables

View Source
var ErrMalformed = errors.New("skill import journal is malformed")

ErrMalformed reports a journal that exists but cannot be trusted to drive recovery. Recovery fails loudly rather than deleting or restoring content on a guess.

Functions

func LegacyInstruction added in v1.0.0

func LegacyInstruction(name string) string

LegacyInstruction is the fixed trusted adoption rename map, never journal data.

func MarkCommitted

func MarkCommitted(stagingRoot string) error

MarkCommitted records that every live write already succeeded, so recovery keeps the new state instead of rolling it back.

func Recover

func Recover(targets Targets) error

Recover completes any interrupted transaction for a project.

It is a no-op when no transaction is in flight. An uncommitted transaction is rolled back to its pre-transaction state; a committed one only has its staging directory cleared. Callers must already hold the project lock.

func RecoverBoth added in v1.0.0

func RecoverBoth(root string) error

RecoverBoth uses trusted coordinates for both kinds before any source consumer.

func Rollback added in v1.0.0

func Rollback(targets Targets, applied Progress, writeFile func(string, []byte, os.FileMode) error) error

Rollback shares restart recovery's restore engine, but restores only touched paths and requires every backup the writer knows it moved. Failed validation leaves all live paths and recovery evidence intact.

func StagingRoot

func StagingRoot(importedSkillsDir string) string

StagingRoot returns the staging directory for an imported skill tier.

func Write

func Write(stagingRoot string, doc Document) error

Write records the transaction's intent durably, after replacement trees and file backups are staged and before the first live path changes. Tree backups are created by the subsequent live renames.

Types

type Document

type Document struct {
	Version          int      `json:"version"`
	LocalRetirements []string `json:"local_retirements,omitempty"`
	// Committed marks a transaction whose final durable write already
	// succeeded. Recovery then only removes the staging directory.
	Committed bool `json:"committed"`
	// Writes are the skills the transaction replaces or creates.
	Writes []WriteIntent `json:"writes"`
	// Deletes are the skill names the transaction removes.
	Deletes []string `json:"deletes"`
	// Config records that the transaction replaces the configuration file, so
	// recovery knows a configuration backup must be restored.
	Config bool `json:"config"`
	// LockExisted records whether a lockfile was present before the
	// transaction. Recovery restores the backup when it was, and removes the
	// published lockfile when it was not.
	LockExisted bool `json:"lock_existed"`
}

Document is the recorded intent of one in-flight transaction.

type Progress added in v1.0.0

type Progress struct {
	Writes           []WriteIntent
	Deletes          []string
	LocalRetirements []string
	Config           bool
	Lock             bool
}

Progress records live paths touched by an in-process transaction. Writes retain whether an original moved, so missing backups cannot be mistaken for originals that were never changed.

type Targets

type Targets struct {
	ImportedSkillsDir string
	LocalSkillsDir    string
	ConfigPath        string
	SkillsLockPath    string
	ExactFiles        bool
}

Targets are the resolved live paths a transaction publishes to. They are supplied by the caller rather than read from the journal so a tampered journal can never direct recovery at a path outside the project.

func (Targets) LocalPath added in v1.0.0

func (t Targets) LocalPath(name string) string

LocalPath maps only trusted standard instruction names to their legacy slots.

type WriteIntent

type WriteIntent struct {
	Name string `json:"name"`
	// Existed records whether the imported directory was present before the
	// transaction started. Recovery needs it because a write that was never
	// reached and a newly created skill both leave no backup behind: the first
	// must be left alone, the second must be removed.
	Existed bool `json:"existed"`
}

WriteIntent is one skill the transaction replaces or creates.

Jump to

Keyboard shortcuts

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