import { DEFINITION_SECTION_ICON } from "#configuration/icons/grammar.icons"; import { DEFINITION_SECTION_ID } from "#core/ids/grammar.ids"; import { PAG_LANGUAGE } from "#configuration/constants/code.constants"; import type { Section } from "#types/document.types"; const MINIMAL_DOCUMENT = '---\nname: \ntype: TASK\nversion: 1.0.0\n---\n\nTHIS TASK EXECUTES \n\n%% META %%:\n objective: ""\n jurisdiction: | external: everything else\n recursion_limit: \n\n# NODE 1 — [epistemic · analysis · logic · yields: boolean]\n@genesis: existence\nCONTRACT:\n input: \n transform: READ_RESOURCE INTO ; VALIDATE_ARTIFACT AGAINST \n output: , validated\nHANDOFF GATE:\n [check] read from (evidence: the read returned content)\n [check] conforms to (evidence: the validator\'s report) over: records measured: / \n [check] every . carries the fields NODE 2 reads (evidence: no record with a missing field)\n result: pass -> NODE 2 | unread or nonconforming -> REPAIR (owner: NODE 1) | unknown -> BLOCKED\n\n# NODE 2 — [epistemic · reasoning · set-theory · yields: set]\n@genesis: difference\nCONTRACT:\n input: from NODE 1\n transform: FOR EACH IN .: ANALYZE_CONTENT AGAINST INTO ; IF .: APPEND TO \n output: \nHANDOFF GATE:\n [check] every analyzed (evidence: one finding per item) over: . measured: / \n [check] holds every that met (evidence: the two counts match)\n [check] no outside appears in (evidence: every result item present in )\n result: pass -> TERMINATE | count mismatch -> REPAIR (owner: NODE 1) | unknown -> BLOCKED\n\n# CROSS-NODE INVARIANTS\nINVARIANT validate-before-persist: is validated before anything is persisted over: every node binds: the reader objector: [check] conforms to at NODE 1\nINVARIANT source-untouched: is never modified in place over: binds: the reader objector: none\n\nREPORT:\n subject: NODE 2\n verdict: pass | fail | unknown\n domain: declared measured \n completion: saturated complete verified '; const STAGE_SAMPLE = "# each construct of a document is one stage of the reasoning loop, written down\ndeclaration orient what kind of instruction exists, and what it may touch yields: a set\nkeyword directive see the lens the intent is read through yields: a structured line\nnode project what follows what, as a contract yields: an edge-list\ncontrol flow act which branch, which iteration yields: a procedure\nsemantic operation act which effect, bound to a result yields: a procedure\ninvariant record constrain what is admissible, and what would object yields: a boolean\nhandoff gate verify what evidence closes the node, over what set yields: pass, fail or unknown\nreport commit the verdict as a representation a checker can challenge yields: an artifact\nwell-formedness terminate whether the document may be trusted yields: a boolean"; const CONTRACT_DIAGRAM = 'flowchart TB\n prose["Prose · \'get the data and check it\'"]\n interpret["The model interprets · what is get, what is check, what counts as valid"]\n variance["A different completion each run"]\n pag["A directive · READ data FROM source, VALIDATE data AGAINST schema"]\n pattern["The model completes a pattern it has seen"]\n narrow["A narrower set of completions · still probabilistic"]\n prose --> interpret --> variance\n pag --> pattern --> narrow'; const ENGINE_DIAGRAM = 'flowchart TB\n doc["A document · typed, contracted, gated, bounded"]\n scan["A scan · checks the shape, deterministic"]\n loop["A reasoning loop · orient, intent, see, derive, project, act, constrain, verify, commit, terminate"]\n binding["A binding · maps each operation to a tool, each slot to a value"]\n output["Output · a sample, unverified until read"]\n doc --> scan\n doc --> loop --> output\n loop -- an effect --> binding\n doc -. has no runtime of its own .-> output'; export const DEFINITION_SECTION: Section = { icon: DEFINITION_SECTION_ICON, id: DEFINITION_SECTION_ID, intro: "Pattern Abstract Grammar is a structured instruction format for AI systems. A document written in it declares what kind of instruction it is and what it may touch, and draws every operative word from a closed vocabulary of uppercase tokens grounded in a reasoning ontology. It groups the work into nodes that each read the prior node's output and close on a gate of checkable conditions with their evidence and their population, states its boundaries as invariant records, and closes with a report, which is the whole of minimal document. Each of those constructs is one stage of a reasoning loop written down, as construct to stage lists, so the document is the loop made legible; prose or directive shows where the variance enters without it, and scan, loop, binding what walks it. Why it works says what the tokens buy, and limits says what the grammar never reaches.", subsections: [ { blocks: [ { application: "Write an instruction as a PAG document when a reasoning loop will walk it: declare its type, state a checkable objective, decompose the work into nodes with contracts, close each node on three to five checks someone can settle with evidence, and bound the whole with invariants.", boundary: "A prompt that asks one question in passing gains nothing from a node structure. The grammar earns its cost where the document will be walked more than once, read by more than one party, or trusted to have done what it says.", cause: "An implicit contract leaves the model to supply the terms, and it supplies them from the completion, so they vary with it.", decision: "Type the instruction rather than sharpen its prose: a declared type, tokens from a closed set and gates with checkable exits, over a longer or more careful sentence.", failureMode: "The same request run twice yields two plausible results, and nobody can say which sentence was read differently.", kind: "lesson", principle: "An instruction is an explicit contract, not a request in prose.", problem: "An instruction written as prose leaves its terms to whoever reads it.", validation: "Hand the same document to the model twice and compare the outputs against the gates. Where both runs pass every gate, the structure held; where one fails, the failing gate names the sentence that was still prose.", }, { kind: "text", text: "A document has no runtime. What walks it is a reasoning loop, the loop the methodology page teaches, and every construct of the grammar is one of its stages made explicit. The document type names which reasoning model walks it and on which axis of that loop it sits, and an adapter outside the document maps each semantic operation to the tool that performs it.", }, { kind: "text", text: "Two checks apply to a document, and they are different kinds of thing. A scan checks its shape, and it is static analysis, deterministic and cheap, which is what makes the grammar parsable. The loop checks its meaning, and that is not deterministic, because the loop is walked by a model.", }, { code: MINIMAL_DOCUMENT, kind: "code", language: PAG_LANGUAGE, title: "minimal document" }, { code: STAGE_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "construct to stage" }, { caption: "prose or directive", kind: "mermaid", text: CONTRACT_DIAGRAM }, { caption: "scan, loop, binding", kind: "mermaid", text: ENGINE_DIAGRAM }, ], title: "A contract, not a request", }, ], title: "What PAG is", };