Documentation
¶
Overview ¶
Package record reads the JSONL record format used by tasks.
Index ¶
- Constants
- Variables
- func Absent(value json.RawMessage) bool
- func DecodeStrings(raw json.RawMessage) []string
- func DelegationAgent(value any) bool
- func DelegationClaimed(value any) bool
- func DelegationEmail(value any) bool
- func DelegationErrors(value any) []string
- func DelegationErrorsWith(value any, modes ModeVocabulary) []string
- func DelegationHuman(value any) bool
- func DelegationIdentifier(value any) bool
- func DelegationNoteErrors(value any) []string
- func DelegationObject(value any) bool
- func DelegationOrderedKeys(value map[string]any, sourceOrder []string) []string
- func DelegationReady(value any) bool
- func DelegationStamp(value time.Time) string
- func DelegationStoredErrors(value any, modes ModeVocabulary) (errors []string, warnings []string)
- func DelegationTimestamp(value any) bool
- func DelegationUnknownKeys(value any) []string
- func DelegationValid(value any) bool
- func DelegationWorkRefErrors(value any) []string
- func Dump(records []Record) (string, error)
- func DumpRecord(record Record) (string, error)
- func EncodeJSON(out *bytes.Buffer, raw json.RawMessage) error
- func EncodeString(out *bytes.Buffer, value string)
- func NestedCanonical(key string, raw json.RawMessage) (string, error)
- func RawInt(value int) json.RawMessage
- func RawString(value string) json.RawMessage
- func RawStrings(values []string) json.RawMessage
- func RubyInspect(value any) string
- func ValidModeName(mode string) bool
- type Field
- type GeneratorError
- type ModeSet
- type ModeVocabulary
- type ParseError
- type Record
- func (r *Record) Delete(key string)
- func (r Record) Get(key string) (json.RawMessage, bool)
- func (r Record) Has(key string) bool
- func (r *Record) Set(key string, value json.RawMessage)
- func (r *Record) SetDefault(key string, value json.RawMessage)
- func (r *Record) SetOptional(key string, value json.RawMessage)
- func (r *Record) SetString(key, value string)
- func (r Record) String(key string) string
- func (r Record) Truthy(key string) bool
- type Result
Constants ¶
const DelegationField = "delegation"
const DelegationNoteLimit = delegationNoteLimit
DelegationNoteLimit is the note bound a refusal quotes.
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 ¶
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.
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.
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 DelegationClaimed ¶
func DelegationEmail ¶
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 ¶
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 DelegationIdentifier ¶
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
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 DelegationOrderedKeys ¶
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 DelegationStamp ¶
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 DelegationUnknownKeys ¶
func DelegationValid ¶
func DelegationWorkRefErrors ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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
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.
type GeneratorError ¶
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
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.
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 ¶
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 ¶
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 ¶
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 (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) 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.
type Result ¶
type Result struct {
Records []Record
Errors []ParseError
}
Result is the complete, non-failing outcome of parsing a JSONL file.