import { PAG_LANGUAGE } from "#configuration/constants/code.constants"; import { STRUCTURE_SECTION_ICON } from "#configuration/icons/grammar.icons"; import { STRUCTURE_SECTION_ID } from "#core/ids/grammar.ids"; import type { Section } from "#types/document.types"; const SKELETON = '---\nname: \ntype: WORKFLOW\nversion: 1.0.0\n---\n\nTHIS WORKFLOW EXECUTES \n\n%% META %%:\n priority: \n trust: = TRUSTED, = UNTRUSTED\n objective: ""\n jurisdiction: | external: \n recursion_limit: \n\n# THE FOUR LAYERS · each answers one question about this document\n# substrate — how does the artifact come to be grounds the order of the nodes, named on each by @genesis\n# epistemic — how is it known orient · see · derive · project · act\n# conative — what is worth doing intent · constrain mandatory, always\n# evaluative — is it right, and are we done verify · commit · terminate mandatory, always\n\n# YIELDS-SHAPE LEGEND · every decision resolves to a typed shape\n# set-theory -> set|boolean · logic -> boolean · graph -> edge-list · optimisation -> boolean|ranking · computation -> procedure\n\n# SEMANTIC OPERATION BOUNDARY · nodes say WHAT as operations; an adapter decides HOW, and the core names no tool or path\n\n# THE LOOP SPINE · transitions declared once, every node cites it\n# node · layer · axis · yields · transition out\n\n# NODE 1 — ORIENT … NODE 10 — TERMINATE · each with its four-slot tag, its genesis stage, its contract and one evidence-bearing gate\n\n# REPAIR EDGE · verify refutes back to the earliest invalid node, bounded by recursion_limit\n\n# CROSS-NODE INVARIANTS\nINVARIANT : over: binds: objector: \n\nREPORT:\n subject: \n verdict: pass | fail | unknown\n domain: declared measured \n completion: saturated complete verified '; const TYPE_SHAPE = "# a type binds a document to a reasoning model and to the axis of the loop it sits on\n\n# cognition · how a system perceives, acts and adapts\nTHIS AGENT PERFORMS axis: reasoning\nTHIS WORKFLOW EXECUTES axis: formalisation\nTHIS PROMPT IS axis: formalisation\nTHIS COMMAND EXECUTES axis: formalisation\n\n# pattern-cycle · how pattern-work proceeds\nTHIS PROTOCOL DEFINES axis: formalisation\nTHIS CHECKLIST PROVIDES axis: formalisation\nTHIS TASK EXECUTES axis: formalisation\nTHIS INSTRUCTION IS axis: formalisation\nTHIS COMPOSITION RENDERS axis: formalisation\nTHIS POLICY ENFORCES axis: teleology\nTHIS TEMPLATE IMPLEMENTS axis: representation\n\n# epistemology · how a pattern is known\nTHIS TEST PERFORMS axis: verification\nTHIS VERIFICATION PERFORMS axis: verification\nTHIS AUDIT AUDITS axis: verification\nTHIS DEBUG RESOLVES axis: analysis\nTHIS DISTILLATION DISTILLS axis: reasoning\nTHIS TRANSLATION AUDITS axis: representation"; const ORDER_DIAGRAM = 'flowchart TB\n front["Header block · name, type, version"]\n decl["Declaration · THIS TYPE VERB description"]\n meta["META · priority, trust, objective, bounds"]\n frame["The four layers, the shape legend, the operation boundary"]\n substrate["The substrate · how the artifact comes to be"]\n spine["The spine · transitions declared once"]\n nodes["Nodes · each with a contract and one gate"]\n repair["The repair edge · bounded"]\n rules["Cross-node invariants · one record each"]\n report["The report · what was measured, over what, and whether the three conditions coincide"]\n front --> decl --> meta --> frame --> substrate --> spine --> nodes --> repair --> rules --> report'; const TYPE_DIAGRAM = 'flowchart LR\n type["The declared type"]\n verb["Its default verb"]\n model["The reasoning model that walks it"]\n axis["The axis of the loop it sits on"]\n reader["A reader knows what kind of instruction this is, and what will walk it"]\n type --> verb --> reader\n type --> model --> reader\n type --> axis --> reader'; export const STRUCTURE_SECTION: Section = { icon: STRUCTURE_SECTION_ICON, id: STRUCTURE_SECTION_ID, intro: "A document announces what kind of instruction it is before it instructs, which is the orient stage of the loop written down: what exists is declared before anything is done with it. A document is a self-describing structure, laid out as skeleton and ordered as parts in order draws, and one that opens with a directive has left its own contract implicit. The type it declares is one of the types, and what a type fixes is what that one line settles before any node is walked.", subsections: [ { blocks: [ { application: "Declare before instructing: the header, the declaration, the meta block, then the frame the nodes cite, and close with the repair edge and the invariants.", boundary: "A fragment reused inside other documents carries no header of its own, because the enclosing document already declared the contract. A fragment that declares a second type is two documents.", cause: "A reader classifies a document from its first lines and reads everything after against that guess.", decision: "Fix the contract on the first line with a type, rather than leaving the reader to infer it from the directives below.", failureMode: "A reader cannot tell whether a document is a standing policy or a one-time task, walks a policy once and drops it, and the rules it carried apply to nothing.", kind: "lesson", principle: "A document declares what it is before it says what to do.", problem: "A document with no declared type has a contract nobody stated, so every reader supplies their own.", validation: "Cover everything below the declaration and ask what the document is for, what will walk it and how it will be used. A declaration that cannot answer all three is missing a type or an intent.", }, { kind: "text", text: "The meta block settles four things before any node runs. The priority between sources, so a disagreement is decided before it arises, and the trust anchor, so a claim from an untrusted source is never promoted to evidence by being read. The jurisdiction, so what the document may touch and what it declares outside itself are stated rather than assumed, which is the boundary the honest gaps draws for a system, and a recursion limit, so a repair loop terminates. Choosing the type is choosing the contract, the reasoning model and the axis at once, and the verb makes the choice legible on the first line.", }, { kind: "text", text: "The substrate and the spine are declared once and cited by every node. The substrate orders the nodes, as node design derives, and each node names its stage on it. The spine declares every transition: which node sequences to which, where a failed verification refutes back, and where the loop terminates. A node names its place on both and inherits the rest, which is why a document reads as one structure rather than ten documents. The document closes with its invariant records and a report, the verdict written as a representation a later checker can challenge, which is what a report, not a checkbox asks of a run.", }, { code: SKELETON, kind: "code", language: PAG_LANGUAGE, title: "skeleton" }, { code: TYPE_SHAPE, kind: "code", language: PAG_LANGUAGE, title: "the types" }, { caption: "parts in order", kind: "mermaid", text: ORDER_DIAGRAM }, { caption: "what a type fixes", kind: "mermaid", text: TYPE_DIAGRAM }, ], title: "Declare, then instruct", }, ], title: "Document structure", };