record

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 13 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 record reads the JSONL record format used by tasks.

Index

Constants

View Source
const DelegationField = "delegation"
View Source
const DelegationNoteLimit = delegationNoteLimit

DelegationNoteLimit is the note bound a refusal quotes.

View Source
const LineKey = "line"

LineKey is the physical line number the parser stamps onto a record. It is bookkeeping, never part of the schema, so emission always drops it.

Variables

View Source
var DelegationKeyOrder = []string{"kind", "mode", "status", "assignee", "at", "work_ref", "note"}

note is APPENDED last so every record written before it existed keeps its exact byte layout.

View Source
var KeyOrder = []string{
	"type", "id", "parent", "state", "priority", "title", "tags", "scheduled", "scheduled_time",
	"deadline", "deadline_time", "recur", "lead", "lead_skip", "delegation",
	"closed", "rejected", "archived", "links", "body", "updated",
}

KeyOrder is the canonical field order for a serialized record. A key present on a record but absent here is emitted after these, in the record's own source order, so a field a newer writer added survives a write by this one.

View Source
var ReservedModeNames = []string{"off", "none", "clear", "release"}

ReservedModeNames are the words a mode may not be, because a surface already spends them on an action.

`off`/`none`/`clear` are the words that clear a work reference or a note, and a mode spelled like one of them WOULD be ambiguous where both are written in one place: `tasks delegate <ref> --note off` cannot mean both "clear the briefing" and "the briefing is the word off".

`release` is reserved for a weaker but real reason — it is the name of a delegation verb (`tasks release <ref>`, and the modal's Release button), so a mode called `release` would have a person reading "release" in two senses on one screen. That one is about the reader, not the parser.

This is refused at CONFIGURATION time rather than resolved with a precedence rule, because the collision is real: someone who wants a mode called `release` has picked a name that already means something, and the honest moment to say so is when they write the config, not at the moment they need to revoke a claim. Refusing also keeps every surface agreeing on one vocabulary, rather than one of them quietly accepting a mode the others would read as a verb.

Functions

func Absent

func Absent(value json.RawMessage) bool

Absent is Delegation.absent?: nil, the empty string, the empty array and the empty object all mean "this field is not here".

func DecodeStrings

func DecodeStrings(raw json.RawMessage) []string

DecodeStrings reads a stored string array, skipping members that are not strings — which is what Ruby's tag handling does with a foreign writer's list.

func DelegationAgent

func DelegationAgent(value any) bool

func DelegationClaimed

func DelegationClaimed(value any) bool

func DelegationEmail

func DelegationEmail(value any) bool

DelegationEmail is Delegation.email? — an identifier that is also address-SHAPED, so a stray `@work` cannot become a person a task waits on.

func DelegationErrors

func DelegationErrors(value any) []string

DelegationErrors returns Ruby-compatible schema diagnostics for delegation. It validates modes against the BUILT-IN vocabulary; a caller holding a configured one calls DelegationErrorsWith instead.

func DelegationErrorsWith added in v1.11.0

func DelegationErrorsWith(value any, modes ModeVocabulary) []string

DelegationErrorsWith is the same check against a caller-supplied mode vocabulary. Nil means the built-in set.

func DelegationHuman

func DelegationHuman(value any) bool

func DelegationIdentifier

func DelegationIdentifier(value any) bool

DelegationIdentifier is Delegation.identifier?: real UTF-8, non-empty, bounded, no whitespace in any script, no control or escape characters.

func DelegationNoteErrors added in v1.11.0

func DelegationNoteErrors(value any) []string

DelegationNoteErrors validates one note the way DelegationWorkRefErrors validates one reference: BEFORE a marker is built, so the writer reads the note's own problem rather than a whole-marker shape report.

func DelegationObject

func DelegationObject(value any) bool

func DelegationOrderedKeys

func DelegationOrderedKeys(value map[string]any, sourceOrder []string) []string

DelegationOrdered supplies the canonical key order plus unknowns in source order. Go maps cannot retain insertion order, so callers that need emission order should use DelegationOrderedKeys with the source-field order they already possess.

func DelegationReady

func DelegationReady(value any) bool

func DelegationStamp

func DelegationStamp(value time.Time) string

func DelegationStoredErrors added in v1.11.0

func DelegationStoredErrors(value any, modes ModeVocabulary) (errors []string, warnings []string)

DelegationStoredErrors validates a marker that is ALREADY ON DISK, which is a different question from validating one about to be written.

A marker being written must name a mode the active vocabulary lists: that is a refusal, and DelegationErrorsWith is what states it. A marker already in the file may name a mode the CURRENT configuration no longer lists — the user removed it, or the record came from another machine — and that must not invalidate the file. Records like that load, show, and check; the mode comes back as a warning so the user can see it and decide, and every other delegation rule still applies to it in full.

A mode of the wrong SHAPE stays an error either way: no configuration could ever have produced it.

func DelegationTimestamp

func DelegationTimestamp(value any) bool

func DelegationUnknownKeys

func DelegationUnknownKeys(value any) []string

func DelegationValid

func DelegationValid(value any) bool

func DelegationWorkRefErrors

func DelegationWorkRefErrors(value any) []string

DelegationWorkRefErrors is Delegation.work_ref_errors for one reference. The work-ref writer validates BEFORE it builds a marker, so the user reads the reference's own problem rather than a whole-marker shape report.

func Dump

func Dump(records []Record) (string, error)

Dump serializes records to full file text: one record per line with a trailing newline at EOF. An empty list yields the empty string.

func DumpRecord

func DumpRecord(record Record) (string, error)

DumpRecord serializes one record to a single JSON line with no trailing newline. Known keys emit in KeyOrder, then unknown keys in source order. Null, the empty string, the empty array, and the empty object are omitted: they mean an absent field, not a present-but-empty one.

func EncodeJSON

func EncodeJSON(out *bytes.Buffer, raw json.RawMessage) error

EncodeJSON writes one already-parsed JSON value the way Ruby's JSON.generate writes it: no whitespace, object members in source order, and Ruby's escape set and number spellings. It is the seam the store's revision digests need — those digest `JSON.generate(...)` output, so a Go emitter that escaped `<` or reordered a nested object would compute a different token from identical bytes.

func EncodeString

func EncodeString(out *bytes.Buffer, value string)

EncodeString writes a Go string as a JSON string with Ruby's escape set.

func NestedCanonical

func NestedCanonical(key string, raw json.RawMessage) (string, error)

NestedCanonical renders one nested object — a delegation or a `*_time` value — in its canonical key order, exactly as Format.nested_object followed by JSON.generate does in Ruby. The merge needs those bytes as a total order over two delegation markers, which is what makes "exactly one worker holds a claim" survive a multi-device sync.

func RawInt

func RawInt(value int) json.RawMessage

RawInt encodes an integer.

func RawString

func RawString(value string) json.RawMessage

RawString encodes a Go string as a canonical JSON string, with Ruby's escape set rather than Go's — encoding/json is never the writer here.

func RawStrings

func RawStrings(values []string) json.RawMessage

RawStrings encodes a list of strings as a canonical JSON array.

func RubyInspect

func RubyInspect(value any) string

RubyInspect renders a value the way a Ruby diagnostic quotes it, which is what every delegation refusal's wording depends on.

func ValidModeName added in v1.11.0

func ValidModeName(mode string) bool

ValidModeName reports whether a string is spelled like a mode. It says nothing about membership; that is the vocabulary's question.

Types

type Field

type Field struct {
	Key   string
	Value json.RawMessage
}

Field is one parsed object member. The parser retains source member order so a later canonical emitter can append forward-compatible keys in the same order Ruby's Hash preserves them.

func Fields

func Fields(raw json.RawMessage) ([]Field, error)

Fields parses a JSON object's members, retaining source order and each member's raw representation.

type GeneratorError

type GeneratorError struct {
	Key   string
	Value string
}

GeneratorError reports a value JSON cannot represent. Ruby's generator raises JSON::GeneratorError for a non-finite float; nothing else in the record format can reach this layer unrepresentable, because every value arrives from a successful parse.

func (*GeneratorError) Error

func (e *GeneratorError) Error() string

type ModeSet added in v1.11.0

type ModeSet []string

ModeSet is the ordinary implementation: an ordered, closed list of modes.

func BuiltinModes added in v1.11.0

func BuiltinModes() ModeSet

BuiltinModes is the vocabulary this build ships with, and the value every seam falls back to when a caller supplies none.

func ParseModeList added in v1.11.0

func ParseModeList(value string) (ModeSet, string)

ParseModeList reads the configured mode list — a comma-separated list of bare words, and nothing more. A mode carries NO label or description on purpose: the label a user would write is the word itself, every surface already renders the word, and a `mode:Label` syntax would need escaping rules, a display column, and a second answer to "what does a refusal quote back". The syntax stays boring so the vocabulary stays one list.

The second result explains the refusal; when it is non-empty the caller must fall back to the built-in set rather than run on a half-understood list.

func (ModeSet) Modes added in v1.11.0

func (s ModeSet) Modes() []string

func (ModeSet) Quoted added in v1.11.0

func (s ModeSet) Quoted() string

func (ModeSet) Valid added in v1.11.0

func (s ModeSet) Valid(mode string) bool

type ModeVocabulary added in v1.11.0

type ModeVocabulary interface {
	// Valid reports whether one mode string is a member.
	Valid(mode string) bool
	// Modes lists the members in the order a human should read them.
	Modes() []string
	// Quoted renders the set the way a refusal quotes it back
	// ("refine/research/implement").
	Quoted() string
}

The delegation mode vocabulary lives behind ONE seam, and it is carried as a VALUE, never as a location.

A mode is the kind of delegation this is — the authority the receiver has. The built-in vocabulary is refine/research/implement, but the set is a user decision, not a schema fact, so everything that has to answer "is this a mode" or "what does a refusal quote back" takes a ModeVocabulary from its caller and defaults to BuiltinModes when given nil.

There is deliberately no package-level setter. A process-wide vocabulary would make this package's answers depend on start-up order (a package-level var in some surface, evaluated during init, would silently keep the built-in set) and would let one test's configuration leak into another's. Instead the store and the checker each hold the vocabulary they were constructed with, which is what makes configuring it later one field rather than a refactor.

func Modes added in v1.11.0

func Modes(vocabulary ModeVocabulary) ModeVocabulary

Modes resolves an optional vocabulary to the one to use.

type ParseError

type ParseError struct {
	Line    int
	Message string
}

ParseError is a non-fatal defect in an input file. Parsing continues after per-line errors so callers can still inspect the records that were sound.

type Record

type Record struct {
	Fields []Field
	Line   int
}

Record is one parsed JSONL object. Fields retain JSON representations and source order so later validation and canonical emission can make their own type decisions. Line is physical and is never part of the persisted record schema.

func Clone

func Clone(r Record) Record

Clone is `duplicate_records`' per-record half: a detached copy whose fields can be replaced without disturbing the original. Values are json.RawMessage and are only ever replaced, never mutated in place, so copying the slice is a deep copy in practice.

func CloneAll

func CloneAll(records []Record) []Record

CloneAll is `duplicate_records`.

func (*Record) Delete

func (r *Record) Delete(key string)

Delete is `rec.delete(key)`, removing every occurrence.

func (Record) Get

func (r Record) Get(key string) (json.RawMessage, bool)

Get is `rec[key]`: the raw value, or ok=false when the key is absent. The FIRST occurrence wins, matching the parser's own duplicate-key handling.

func (Record) Has

func (r Record) Has(key string) bool

Has reports key presence, including a present-but-null key.

func (*Record) Set

func (r *Record) Set(key string, value json.RawMessage)

Set is `rec[key] = value`: an existing key keeps its position, a new one is appended.

func (*Record) SetDefault

func (r *Record) SetDefault(key string, value json.RawMessage)

SetDefault is Ruby's `rec[key] ||= value`: it writes only when the key is absent or holds nil/false.

func (*Record) SetOptional

func (r *Record) SetOptional(key string, value json.RawMessage)

SetOptional is Store#replace_optional: an absent, null or empty value deletes the key rather than writing a present-but-empty one, because the format reads those as the same thing and writing one would change the bytes for no semantic difference.

func (*Record) SetString

func (r *Record) SetString(key, value string)

SetString is Set for a plain string value.

func (Record) String

func (r Record) String(key string) string

String is `rec[key]` decoded as a String, or "" for absent and non-string values. Every caller here treats a non-string exactly as Ruby's `.to_s` on a nil would: as the empty string.

func (Record) Truthy

func (r Record) Truthy(key string) bool

Truthy is Ruby truthiness for a stored value: anything but absent, null and false.

type Result

type Result struct {
	Records []Record
	Errors  []ParseError
}

Result is the complete, non-failing outcome of parsing a JSONL file.

func Parse

func Parse(input []byte) Result

Parse reads JSONL leniently. A malformed or non-object line becomes an error, while valid records retain their physical one-based line number. Invalid UTF-8 is a whole-file error because Ruby rejects it before it can safely split the file into JSONL lines.

func (Result) OK

func (r Result) OK() bool

OK reports whether the input had no parse errors.

Jump to

Keyboard shortcuts

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