status

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package status is the write face: the only package here allowed to write vault files. It flips a note's frontmatter status field as a surgical, single-line rewrite — never a YAML re-serialization — and leaves every other byte of the file exactly as it found it. Nothing authenticates who triggered a flip; the file's new bytes are the whole record.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed means the write face is fail-closed: the vault contract failed
	// to load, or its pinned root capability has been closed. Reading tolerates
	// a missing contract; a write without one could destroy a file.
	ErrClosed = errors.New("write face is closed")
	// ErrArtifactPolicyUnavailable means the core contract loaded but its
	// artifact policy is unavailable, so instance writes cannot be classified.
	ErrArtifactPolicyUnavailable = errors.New("artifact policy unavailable")
	// ErrNonInstance means the requested path is a readable artifact rather
	// than a governed note instance.
	ErrNonInstance = errors.New("target is not a governable artifact")
	// ErrOutsideKnowledgeScope means the requested path is a note the lifecycle
	// never reaches: it lies outside the directories scan.knowledge_dirs names
	// as the knowledge layer, and the state machine runs only there.
	ErrOutsideKnowledgeScope = errors.New("target is outside the knowledge layer scan.knowledge_dirs declares")
	// ErrInvalidPath means a status request did not name a local vault-relative
	// slash path.
	ErrInvalidPath = errors.New("invalid vault-relative path")
	// ErrStale means the submitted form's "from" no longer matches the note's
	// on-disk status: the page was loaded before someone else changed the file.
	ErrStale = errors.New("note is stale, reload and try again")
	// ErrConcurrentWrite means the file's identity, mode, mtime or bytes
	// changed between Flip's descriptor read and its pre-write recheck. It is
	// distinct from ErrStale and does not satisfy errors.Is(err, ErrStale).
	ErrConcurrentWrite = errors.New("note changed while flipping")
	// ErrContentChanged means the note's bytes no longer carry the content
	// identity the caller read: something outside the status line was edited
	// after the page rendered. The status line's own divergence is ErrStale.
	ErrContentChanged = errors.New("note content changed after it was read")
	// ErrStatusLine means the frontmatter block does not contain exactly one
	// line beginning with "status:". yomihon reports; a human edits the file.
	ErrStatusLine = errors.New("frontmatter does not have exactly one status line")
	// ErrPublishedReserved means the flip named published as its target. That
	// status records a completed publication outside the vault, which nothing
	// here can attest, so the value enters a note only by hand.
	ErrPublishedReserved = errors.New("published records a completed publication and no publisher exists to attest one")
	// ErrStatusSyntaxUnsupported means the reader understands the note's
	// status but the frontmatter writes it in a form the surgical rewriter
	// cannot preserve — an explicit or quoted key, a flow mapping, an anchor
	// the rewrite would sever. The note is refused unchanged.
	ErrStatusSyntaxUnsupported = errors.New("frontmatter writes status in a syntax the surgical rewriter does not support")
	// ErrDurabilityUnsupported means the platform cannot prove an atomic
	// rename's directory entry reached durable storage, so the write face
	// refuses rather than leave new bytes a crash could silently discard.
	ErrDurabilityUnsupported = errors.New("durable install is unsupported on this platform")
	// ErrInstallStranded means another program edited the note inside the
	// install window and the edit could not be put back under the note's own
	// name. Both versions are on disk, one named in the error, and nothing was
	// removed. Unlike ErrConcurrentWrite it cannot say which the note carries.
	ErrInstallStranded = errors.New("an edit raced the flip and both versions were left on disk")
	// ErrInstallUncertain means the atomic replacement completed but the
	// containing directory could not be synchronized, so the new bytes are
	// visible without their survival across an immediate crash being confirmed.
	ErrInstallUncertain = errors.New("note rewritten but durability was not confirmed")
)

Sentinel errors. Callers match with errors.Is.

Functions

This section is empty.

Types

type ArtifactPolicyUnavailableError

type ArtifactPolicyUnavailableError struct {
	// contains filtered or unexported fields
}

ArtifactPolicyUnavailableError carries the contract-derived diagnostic for a write refused because instance classification is unavailable.

func (*ArtifactPolicyUnavailableError) Error

Error returns the artifact policy diagnostic verbatim.

func (*ArtifactPolicyUnavailableError) Unwrap

Unwrap makes the error identifiable with ErrArtifactPolicyUnavailable.

type Authority added in v0.2.0

type Authority struct {
	// contains filtered or unexported fields
}

Authority is one immutable read-only lifecycle projection captured from a Writer. Its query methods perform no filesystem or contract-source I/O, so one request derives every status decision from the same sample.

func (Authority) CanReturn added in v0.2.0

func (v Authority) CanReturn(noteType, from, to string) bool

CanReturn reports whether some chain of contract-legal transitions leads from "to" back to "from", which is what decides between a quiet single press and a two-step confirm. The walk never enters the published status, so no return exists only by way of it. A closed view claims nothing and is false.

func (Authority) Claim added in v0.2.0

func (v Authority) Claim() schema.Claim

Claim reports how far the lifecycle authority got, so a caller that closes a projection carries the same reason value the contract produced.

func (Authority) Closed added in v0.2.0

func (v Authority) Closed() bool

Closed reports whether this captured view can classify governed instances.

func (Authority) DeclaresStatuses added in v0.2.0

func (v Authority) DeclaresStatuses(noteType string) bool

DeclaresStatuses reports whether the contract gives this note type a status vocabulary at all. KnownStatus cannot carry that distinction — it answers false both for a value outside a list and for a type that has no list — and the two call for opposite sentences.

func (Authority) Diagnostic added in v0.2.0

func (v Authority) Diagnostic(lang wording.Lang) string

Diagnostic explains, in lang, why this captured view is closed. It is empty both when lifecycle reads are available and when nothing ever claimed authority. A released write face is yomihon's own fault and is answered from the dictionary; everything else carries the contract's own sentence.

func (Authority) Governed added in v0.2.0

func (v Authority) Governed() bool

Governed reports whether anything claimed authority over this vault. A false answer is not a failure: the folder simply has no lifecycle.

func (Authority) IsLessonType added in v0.2.0

func (v Authority) IsLessonType(noteType string) bool

IsLessonType reports whether noteType is the type this vault files its course members as. The name comes from the contract layer, which spells it once; whether this folder declares the type is deliberately not asked, since a note that calls itself a lesson gets the reading aids either way and a folder with no contract would otherwise lose them.

func (Authority) KnownStatus added in v0.2.0

func (v Authority) KnownStatus(noteType, status string) bool

KnownStatus reports whether status is among the contract's declared values for the given note type. A closed view knows none; so does an undeclared type.

func (Authority) LegalTransition added in v0.2.0

func (v Authority) LegalTransition(noteType, from, to string) bool

LegalTransition reports whether the contract legalises moving a note of this type from one status to another. It answers a question about a transition that already happened and never authorises a write, which Flip settles.

func (Authority) Order added in v0.2.0

func (v Authority) Order() []string

Order returns the default note group's statuses in declared order. A nil result means the view is closed; an empty non-nil one is a valid declaration.

func (Authority) Transitions added in v0.2.0

func (v Authority) Transitions(relPath, noteType, current string) []string

Transitions returns the from-list-legal target statuses from current, in contract order. Owner lists are declarative data and never subtract from the answer. The published status is never among them: Flip would refuse it, and a note the lifecycle does not reach gets none by the same test Flip applies.

func (Authority) WhyUngoverned added in v0.2.0

func (v Authority) WhyUngoverned(relPath string) error

WhyUngoverned reports the refusal Flip would return for relPath, so a page with an empty transition set can name the reason. A note the lifecycle reaches, a closed authority and a path it cannot name all answer nil.

func (Authority) WriteDiagnostic added in v0.2.0

func (v Authority) WriteDiagnostic(lang wording.Lang) string

WriteDiagnostic explains, in lang, why this captured authority cannot offer status transitions. Contract and artifact-policy failures take precedence over a platform-only write limitation. Empty means a POST may be offered.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the write face's single HTTP endpoint.

func NewHandler

func NewHandler(writer *Writer, shell func() nav.Shell, log *slog.Logger) *Handler

NewHandler wires the write face's HTTP surface around an existing Writer. A fail-closed write face is still a non-nil Writer. shell is sampled once only after a failed write, so the recovery page uses one reading snapshot.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux)

Register mounts the write face's route.

type Writer added in v0.2.0

type Writer struct {
	// contains filtered or unexported fields
}

Writer is the write face: it flips one note's frontmatter status field. Constructed once per process with the loaded contract, or nil to fail closed.

func Open

func Open(source *vaultfs.Reader, contract *schema.Contract, governance schema.Governance, log *slog.Logger) (*Writer, error)

Open pins an independent write capability for source's already-selected vault; both open directory identities must match before it returns. A nil contract, or an unavailable artifact policy, closes the write face. governance is what the folder asserted about its own contract, which a nil contract cannot answer; with a contract it must be contract.Governance().

func (*Writer) Authority added in v0.2.0

func (w *Writer) Authority() Authority

Authority captures the write face's current read-only authority. Flip does not use this snapshot: writes revalidate the source under the writer's lock.

func (*Writer) Close added in v0.2.0

func (w *Writer) Close() error

Close waits for an in-progress Flip or status read, then releases the pinned write capability. Calls after Close fail closed.

func (*Writer) ConsumeReceipt added in v0.2.0

func (w *Writer) ConsumeReceipt(rel, from string) bool

ConsumeReceipt reports whether this write face recently completed a flip that left status "from" at rel, and spends the receipt when it does: the first reading gets true, every later one false. A mismatched origin spends nothing, so a hand-typed address cannot burn the real redirect's receipt.

func (*Writer) Flip added in v0.2.0

func (w *Writer) Flip(ctx context.Context, rel, from, to string, contentIdentity [sha256.Size]byte) error

Flip moves the note at rel from status "from" to status "to": it validates the transition against the contract, confirms the note's bytes still carry contentIdentity, rewrites exactly the frontmatter status line, and atomically installs the result under the note's own name. Every refusal before the install leaves the file untouched. ctx is honoured up to the lock and not after: past that point the install runs to completion or refuses.

func (*Writer) ObservedStatus added in v0.2.0

func (w *Writer) ObservedStatus(ctx context.Context, rel string) (string, error)

ObservedStatus reports the status the note carries on disk right now. The reading page's other values come from a scan seconds old, which is right for a body or a link graph; an older status would offer a transition from a state the note has already left.

func (*Writer) VaultRoot added in v0.2.0

func (w *Writer) VaultRoot() string

VaultRoot is the absolute path of the vault this writer writes into. It is empty on a nil Writer and after Close.

Jump to

Keyboard shortcuts

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