discussion¶
Package discussion keeps a catalog of discussion records: proposals and decisions written in reStructuredText (or, in an older GDS catalog, Typst) under one prefix, such as gds, sds, or eds. It loads a catalog, plans changes to it (a new draft, a promotion, a lifecycle decision, the generated index), and applies a plan as one recoverable transaction under a lock. Publication is a Renderer’s work: Guidedog’s engine linked in (discussion/embedded) or an installed guidedog program (discussion/external).
It uses only Odin’s core library. It allocates with context.allocator and frees nothing, so run it in an arena and free the arena when done. Failure is a Problem with directions, never a panic. When memory runs out, a procedure returns the problem discussion.memory (exit 3) and no partial result, and apply writes nothing it was not given whole.
Types
- discussion.Book :: struct¶
-
Book is one PDF a build makes: the document it starts from (records/0007-cache), the file it writes (gds-0007-cache.pdf), and the title and author of its cover.
- root: string¶
- file: string¶
- title: string¶
- discussion.Build_Request :: struct¶
-
Build_Request is one publication of the catalog in dir. A PDF build makes books; a selected build (selection, the record’s artifact name, such as gds-0007-cache) writes its book under _build/selected/SELECTION/pdf, and leaves the catalog’s complete PDF output alone. program is the renderer’s tool, 「」 for its default.
- dir: string¶
- prefix: string¶
- selection: string¶
- program: string¶
- discussion.Catalog :: struct¶
-
Catalog is a directory’s records in number order, drafts last. prefix 「」 is DEFAULT_PREFIX; labels nil is the prefix’s default vocabulary (see vocabulary); the zero process is the default one (see process_of).
- reserved: int¶
- prefix: string¶
- labels: []string¶
- discussion.Change :: struct¶
-
Change is one file of a plan: its path in the catalog, its contents before and after, and whether it existed before and is present after.
- path: string¶
- before: string¶
- after: string¶
- existed: bool¶
- present: bool¶
- discussion.Definition :: struct¶
-
Definition is a catalog’s configuration: its prefix, display name, default author, the labels its records may carry when it limits them, and its process. A command run in or under the catalog reads it, so it needs neither –prefix nor –dir.
- schema: int¶
- prefix: string¶
- name: string¶
- labels: []string `json:"labels,omitempty"`¶
- discussion.Init :: struct¶
-
Init is what a new catalog is made from: where, its identity, and its process. draft is the process draft’s text, from its title on, and template the record template, with metadata fields in prefix’s name; 「」 chooses the built-in one. labels limits the labels records may carry (nil: any well-formed label). process is the catalog’s workflow, types, and numbering; the zero Process is the default one. init writes them all to CONFIG_FILE.
- dir: string¶
- prefix: string¶
- name: string¶
- labels: []string¶
- draft: string¶
- template: string¶
- discussion.Numbering :: struct¶
-
Numbering is how promotion numbers records: at least width digits, zero-padded (4: 0007), and wider when a number needs it (10000 follows 9999); from start; and up to limit, or MAX_NUMBER when limit is 0.
- width: int¶
- start: int¶
- limit: int¶
- discussion.Options :: struct¶
-
Options are a command’s settings. prefix 「」 is DEFAULT_PREFIX.
- dir: string¶
- command: string¶
- identifier: string¶
- slug: string¶
- labels: string¶
- state: string¶
- label: string¶
- to: string¶
- reason: string¶
- evidence: string¶
- discussion: string¶
- record: string¶
- target: string¶
- number: int¶
- dry_run: bool¶
- check_only: bool¶
- historical: bool¶
- render: bool¶
- rollback: bool¶
- prefix: string¶
- discussion.Problem :: struct¶
-
Problem is a failure: its code (「discussion.slug」), title, the path it concerns, what went wrong, a hint that says what to do, and the exit status a command returns for it (0: no problem).
- code: string¶
- title: string¶
- path: string¶
- message: string¶
- hint: string¶
- exit: int¶
- discussion.Process :: struct¶
-
Process is how a catalog decides: its record types, its lifecycle states, the state of a new draft, the state promotion opens it in (with its number), and its numbering. The zero Process is DEFAULT_PROCESS, the process of GDS 0001.
- types: []string¶
- draft: string¶
- open: string¶
- discussion.Record :: struct¶
-
Record is one discussion. Its strings borrow the catalog’s arena; fields are the metadata as written, with values as quoted literals. A record load reads keeps only its metadata and which sections it has; text, the whole source, is read only for a record being changed.
- number: string¶
- slug: string¶
- title: string¶
- state: string¶
- kind: string¶
- created: string¶
- updated: string¶
- discussion: string¶
- category: string¶
-
optional memo fields, kept when present.
- status: string¶
-
optional memo fields, kept when present.
- summary: string¶
-
optional memo fields, kept when present.
- labels: []string¶
- path: string¶
- text: string¶
- historical: bool¶
-
an inherited record, kept as provenance and never changed.
- discussion.Renderer :: struct¶
-
Renderer publishes a catalog. Guidedog’s engine linked into the program is one (discussion/embedded.renderer); an installed guidedog program is another (discussion/external.renderer). publish makes one publication and returns where it wrote it; legacy builds an older Typst catalog, whose records are given, selected.
- name: string¶
- publish: proc(r: Build_Request) -> (output: string, p: Problem)¶
- discussion.State :: struct¶
-
State is one lifecycle state: the states the state command may move a record to from it, whether moving into it needs evidence, and the memo status of a record in it.
- name: string¶
- next: []string¶
- evidence: bool¶
- status: string¶
- discussion.Target :: enum¶
-
Target is what one publication makes: the catalog’s website, or its PDF books.
- Html¶
- Pdf¶
Procedures
- discussion.apply :: proc(dir: string, plan: Plan, prefix := DEFAULT_PREFIX) -> (p: Problem)¶
-
apply writes a plan’s changes to the catalog in dir as one transaction: each file must still have the contents the plan was made from, and each change must be whole (a record that parses, an index with one generated region), or nothing is written. A journal records the originals first and every file is replaced atomically, so an interrupted apply can be rolled back by recover. Hold lock while planning and applying.
- discussion.artifact_name :: proc(prefix: string, r: Record) -> string¶
-
artifact_name is the name of a record’s book and pages: gds-0007-cache.
- discussion.build :: proc(o: Options, c: Catalog, renderer: Renderer, program := "") -> (output: string, p: Problem)¶
-
build checks the catalog and publishes it with renderer: o.target 「html」, 「pdf」, or 「both」 (the default). HTML is the complete website; PDF is a book per record, or only the record o.record names. Builds treat warnings as errors. It returns where it wrote, comma-separated. program names the renderer’s tool (「」 for its default).
- discussion.check_index :: proc(dir: string, c: Catalog) -> Problem¶
-
check_index is a Problem when the index of dir differs from what index_plan would write.
- discussion.check_sources :: proc(c: Catalog) -> Problem¶
-
check_sources checks that every record other than a historical one has the sections the discussion template requires, Abstract and References; the first missing one is a Problem.
- discussion.default_process :: proc() -> Process¶
-
default_process is GDS 0001’s process: the states of STATES, the types of TYPES, and four-digit numbers from 1. It is static: nothing is allocated.
- discussion.definition :: proc(dir: string) -> (d: Definition, found: bool, p: Problem)¶
-
definition reads dir’s configuration, CONFIG_FILE, or else a DEFINITION_FILE, when it has one. A malformed one is a Problem; none is found = false.
- discussion.discover :: proc(from: string) -> (dir: string, d: Definition, found: bool, p: Problem)¶
-
discover finds the catalog that holds the directory from: the nearest directory at or above it with a definition.
- discussion.edit_plan :: proc(o: Options, c: Catalog) -> (plan: Plan, p: Problem)¶
-
edit_plan plans the change o.command asks of the record o.identifier names: promote (a draft takes the next number, and moves to the workflow’s open state) or state (a move the workflow allows, with its reason, and evidence where the target state needs it); with the index refreshed. It changes nothing; apply writes the plan. A historical record, or a move the workflow does not allow, is a Problem.
- discussion.format_number :: proc(p: Process, n: int) -> string¶
-
format_number writes n as p numbers it: zero-padded to the width.
- discussion.index_plan :: proc(dir: string, c: Catalog) -> (plan: Plan, p: Problem)¶
-
index_plan plans the regenerated registry and reading order of the catalog in dir: registry.rst and bundle.rst, or registry.typ and bundle.typ in an older Typst catalog. Only the region between the PREFIX-generated-start and -end markers is generated; the prose around it stays. The plan has no changes when the index is current. Unbalanced markers, or memory that ran out, is a Problem, never a plan with less in it.
- discussion.init_plan :: proc(i: Init) -> (plan: Plan, p: Problem)¶
-
init_plan plans a new catalog in i.dir, which must be missing or empty: its definition, configuration, index, workflow, record template, and a process draft. It changes nothing; initialize makes the catalog.
- discussion.initialize :: proc(i: Init) -> (p: Problem)¶
-
initialize makes the catalog init_plan plans. It writes it whole into a folder beside i.dir, checks it as the catalog commands would, and only then moves it into place: a failure leaves nothing behind, and an existing file or folder with contents is never changed.
- discussion.load :: proc(dir: string, prefix := DEFAULT_PREFIX) -> (Catalog, Problem)¶
-
load reads the discussion directory dir into a catalog allocated in the context arena: its records (records/*.rst, or *.typ in an older catalog), the numbers its registry reserves, and its definition (.discussion.json), when it has one. prefix names the records』 fields; a definition’s prefix must match it. It fails with a Problem, and changes nothing, when an update awaits recovery, a record is unreadable, too large, or malformed, or two records claim one number or slug.
- discussion.lock :: proc(dir: string, prefix := DEFAULT_PREFIX) -> (file: ^os.File, p: Problem)¶
-
lock takes the lock of the catalog in dir (.PREFIX.lock) and returns its file, which the caller holds while it loads, plans, and applies, and closes to release; another command holding it is a Problem. A kernel lock is released even if the process crashes. The lock file is kept: unlinking it would let two processes lock different files at one path.
- discussion.new_plan :: proc(o: Options, c: Catalog) -> (plan: Plan, p: Problem)¶
-
new_plan plans a new draft record titled o.identifier: its file, made from the catalog’s template, and the refreshed index. It changes nothing; apply writes the plan. A bad or taken slug, an unknown label, or no author (o.author, or Git’s user.name) is a Problem.
- discussion.next_number :: proc(o: Options, c: Catalog) -> (int, Problem)¶
-
next_number is the number a promoted draft takes: o.number when it is free, else one past the highest that a record, the registry’s reservation, or a PREFIX/NUMBER branch of the repository in o.dir holds, and at least the numbering’s start. A number already reserved, or above the numbering’s limit, is a Problem.
- discussion.now :: proc() -> datetime.DateTime¶
-
now is the moment a change or a build is stamped with. As in other reproducible builds, SOURCE_DATE_EPOCH (seconds since 1970, in UTC) sets it; otherwise it is the local time, in the local time zone, which stays loaded for the life of the process.
- discussion.number_value :: proc(p: Process, number: string) -> (int, bool)¶
-
number_value is the value of a permanent number written as p writes it, or false: a draft, zero, more than nine digits, or a number with other padding.
- discussion.out_of_memory :: proc(path: string) -> Problem¶
-
out_of_memory is discussion.memory (exit 3), the problem of work whose memory ran out. Nothing in it is allocated but path, which the caller already holds.
- discussion.parse_record :: proc(path, source: string, prefix := DEFAULT_PREFIX, labels: []string = nil) -> (r: Record, p: Problem)¶
-
parse_record reads the metadata of the record at path from source: RST fields (:gds-number: 0007) for a .rst file, or the #let gds-… lines of an older Typst record, both with prefix’s name. The record borrows path and source. labels is the vocabulary its labels must come from: nil is the prefix’s default (see vocabulary). A missing, repeated, unknown, or invalid field, a bad slug, or dates out of order is a Problem.
- discussion.prefix_of :: proc(p: string) -> string¶
-
prefix_of is the prefix p names, or DEFAULT_PREFIX for 「」.
- discussion.problem :: proc(code, title, path, message, hint: string, exit := 1) -> Problem¶
-
problem makes a Problem: its code, title, the path it concerns, what went wrong, a hint, and the exit status the command returns for it.
- discussion.process_of :: proc(c: Catalog) -> Process¶
-
process_of is c’s process, or the default one for a catalog that sets none.
- discussion.read_config :: proc(path, source: string) -> (Definition, Problem)¶
-
read_config reads a discussion.toml. Unknown settings, missing ones, and a process that does not hold together (a move to a state that does not exist, a draft that could skip promotion) are Problems that name the file and line.
- discussion.read_record :: proc(c: Catalog, path, source: string) -> (Record, Problem)¶
-
read_record reads a record of the catalog c from source, as load does: its metadata is checked against c’s prefix, labels, and process. The record borrows path and source.
- discussion.recover :: proc(dir: string, dry_run: bool, prefix := DEFAULT_PREFIX) -> (p: Problem)¶
-
recover finishes an interrupted apply: it restores every file the journal names to its original contents and removes the journal; dry_run only checks that it can. No journal is no work. A file edited since the interruption is a Problem, and nothing is restored.
- discussion.render_config :: proc(d: Definition) -> (string, Problem)¶
-
render_config writes d as a discussion.toml: every setting, with a comment on each, so a catalog’s process can be read and changed in one place. dsc config prints it; init writes it. Memory that ran out is discussion.memory, never a shortened file.
- discussion.replace_field :: proc(source, key, literal: string, prefix := DEFAULT_PREFIX) -> (string, Problem)¶
-
replace_field returns source with the metadata field key set to literal, a quoted Typst string (「\」accepted\」」) or, for authors and labels, a tuple of them ((「Ada」,)). An RST record keeps its own notation: plain text, and JSON arrays for authors and labels. Only the field’s line changes: every other byte of source, line endings included, stays as it was. A literal that does not parse, a field the record does not have, or memory that ran out is a Problem, never a shortened text.
- discussion.resolve :: proc(c: Catalog, id: string) -> (Record, Problem)¶
-
resolve finds the one record an identifier names: its number (7 or 「0007」), slug, title, or file name. The record borrows the catalog; no match, or more than one, is a Problem that lists the candidates.
- discussion.state_named :: proc(p: Process, name: string) -> (State, bool)¶
-
state_named is the state of p called name, or false.
- discussion.today :: proc() -> string¶
-
today is now’s date, as YYYY-MM-DD.
- discussion.unnumbered :: proc(p: Process, state: string) -> bool¶
-
unnumbered tells whether a record without a number may be in state: the draft state, or one a draft may move to without promotion.
- discussion.valid_prefix :: proc(p: string) -> bool¶
-
valid_prefix tells whether p can name a catalog: 2 to 16 lowercase ASCII letters.
- discussion.vocabulary :: proc(c: Catalog) -> []string¶
-
vocabulary is the labels c’s records may carry, or nil when any well-formed label is allowed.
Constants
- discussion.CONFIG_FILE :: "discussion.toml"¶
-
CONFIG_FILE is a catalog’s configuration: its identity, the process its records follow, and how they are numbered. A catalog without one follows DEFAULT_PROCESS.
- discussion.DEFAULT_PREFIX :: "gds"¶
-
DEFAULT_PREFIX is the prefix of a catalog, record, or option that names none: Guidedog’s own discussions (GDS).
- discussion.DEFINITION_FILE :: ".discussion.json"¶
-
DEFINITION_FILE is the identity of a catalog made by version 0.2.1, before CONFIG_FILE: its prefix, name, author, and labels, as JSON. It is still read, and a catalog that has it follows the default process; CONFIG_FILE takes precedence.
- discussion.DRAFT_NUMBER :: "XXXXX"¶
-
DRAFT_NUMBER is the number of a record that has none yet.
- discussion.LABELS¶
-
LABELS are the labels of GDS 0001. A gds catalog uses them unless its definition names others; another catalog accepts any label its definition allows (see Definition).
- discussion.MAX_NUMBER :: 999_999_999¶
-
MAX_NUMBER is the highest number any catalog may give a record.
- discussion.STATES :: []string{"prediscussion", "discussion", "accepted", "published", "committed", "abandoned"}¶
-
STATES are the lifecycle states of a record, in their usual order.
- discussion.TYPES :: []string{"Standards Track", "Process", "Informational"}¶
-
TYPES are the kinds of record.