import { ALGORITHM_SECTION_ICON } from "#configuration/icons/grammar.icons"; import { ALGORITHM_SECTION_ID } from "#core/ids/grammar.ids"; import { PAG_LANGUAGE } from "#configuration/constants/code.constants"; import type { Section } from "#types/document.types"; const SEPARATE_SAMPLE = "# · ANALYZE -> FIND -> EXTRACT -> CREATE -> VERIFY\n# chosen because the request asks to split a unit that mixes two concerns\n\n# NODE 1 — ANALYZE THE UNIT [epistemic · analysis · logic · yields: set]\n@genesis: difference\nCONTRACT:\n input: \n transform: READ_RESOURCE INTO ; ANALYZE_CONTENT AGAINST INTO \n output: , each naming the lines that carry it\nHANDOFF GATE:\n [check] read from (evidence: the read returned content)\n [check] holds more than one entry (evidence: a count above one) over: lines measured: / \n [check] every names its lines (evidence: no concern with an empty range)\n result: pass -> NODE 2 | unread -> REPAIR (owner: NODE 1) | unknown -> BLOCKED\n\n# NODE 2 — FIND THE SEAMS [epistemic · ontology · set-theory · yields: set]\n@genesis: existence\nCONTRACT:\n input: from NODE 1\n transform: SEARCH_CONTENT FOR INTO \n output: \nHANDOFF GATE:\n [check] every lies between two (evidence: two concern ids per seam) over: measured: / \n [check] no cuts a single statement (evidence: each seam on a statement boundary)\n [check] is non-empty, or the unit is reported as one that does not split (evidence: a count, or the report)\n result: pass -> NODE 3 | does not split -> TERMINATE | unknown -> BLOCKED\n\n# NODE 3 — EXTRACT THE CONCERN [epistemic · reasoning · graph · yields: edge-list]\n@genesis: relation\nCONTRACT:\n input: from NODE 2\n transform: EXTRACT_FACTS FROM INTO \n preserves: every reference between and the rest\n output: , and every reference between it and the rest\nHANDOFF GATE:\n [check] carries every line of (evidence: the line ranges match) over: lines measured: / \n [check] minus carries the rest (evidence: the two ranges partition the source)\n [check] every reference between the two is named (evidence: an edge per reference)\n result: pass -> NODE 4 | partition broken -> REPAIR (owner: NODE 2) | unknown -> BLOCKED\n\n# NODE 4 — CREATE THE NEW UNIT [epistemic · formalisation · computation · yields: artifact]\n@genesis: structure\nCONTRACT:\n input: from NODE 3\n transform: COMPOSE_ARTIFACT FROM USING ; PERSIST_ARTIFACT TO \n output: \n freshness: fingerprint() + fingerprint(this document)\nHANDOFF GATE:\n [check] persisted (evidence: a read of returns it)\n [check] declares what it imports from (evidence: the import list) over: references measured: / \n [check] declares what it imports from (evidence: the import list)\n refuse: exists and was not read before PERSIST_ARTIFACT\n result: pass -> NODE 5 | undeclared import -> REPAIR (owner: NODE 4) | unknown -> BLOCKED\n\n# NODE 5 — VERIFY THE SPLIT [evaluative · verification · logic · yields: boolean]\n@genesis: constraint\nCONTRACT:\n input: from NODE 4\n transform: EXECUTE_TOOL {toolchain.verify_command} INTO ; VALIDATE_ARTIFACT AGAINST \n output: \nHANDOFF GATE:\n [check] green on one full run (evidence: the run's own output) over: the run's steps measured: / \n [check] no circular dependency between and (evidence: the import graph)\n [check] every consumer of resolves (evidence: the typecheck)\n refuse: a run that would mutate the tree before EXECUTE_TOOL\n standing: moved-set \n result: pass -> TERMINATE | red -> REPAIR (owner: NODE 3) | unknown -> BLOCKED"; const ENFORCE_SAMPLE = "# · ANALYZE -> CREATE -> LINK -> EXECUTE -> VERIFY\n# chosen because a rule held by attention needs a check that holds it\n\n# NODE 1 — ANALYZE THE SHAPE [epistemic · analysis · logic · yields: set]\n@genesis: difference\nCONTRACT:\n input: \n transform: ANALYZE_CONTENT AGAINST INTO \n output: , with its one fix\nHANDOFF GATE:\n [check] names a structure, never an instance (evidence: no vendor, symbol or path in it)\n [check] every violation seen is an instance of (evidence: one match per violation) over: measured: / \n [check] one fix is stated for (evidence: the fix sentence)\n result: pass -> NODE 2 | instance named -> REPAIR (owner: NODE 1) | unknown -> BLOCKED\n\n# NODE 2 — CREATE THE CHECK [epistemic · formalisation · computation · yields: artifact]\n@genesis: structure\nCONTRACT:\n input: from NODE 1\n transform: COMPOSE_ARTIFACT FROM USING ; PERSIST_ARTIFACT TO {project.rule_home}\n output: \n freshness: fingerprint() + fingerprint(this document)\nHANDOFF GATE:\n [check] persisted (evidence: a read of {project.rule_home} returns it)\n [check] reports and states its fix (evidence: its message)\n [check] names no vendor, symbol or path (evidence: a scan of its literals) over: its literals measured: / \n refuse: {project.rule_home} already holds a check of that name before PERSIST_ARTIFACT\n result: pass -> NODE 3 | instance literal -> REPAIR (owner: NODE 2) | unknown -> BLOCKED\n\n# NODE 3 — LINK THE CHECK [epistemic · reasoning · graph · yields: edge-list]\n@genesis: relation\nCONTRACT:\n input: from NODE 2\n transform: LINK TO \n output: the registry entry\nHANDOFF GATE:\n [check] resolves from the registry (evidence: a lookup returns it)\n [check] is active (evidence: the entry)\n [check] nothing else in the registry changed (evidence: a diff of the entries) over: registry entries measured: / \n result: pass -> NODE 4 | unresolved -> REPAIR (owner: NODE 3) | unknown -> BLOCKED\n\n# NODE 4 — PROVE IT FIRES [epistemic · formalisation · analysis · yields: procedure]\n@genesis: transformation\nCONTRACT:\n input: the registry entry from NODE 3\n transform: PERSIST_ARTIFACT TO ; EXECUTE_TOOL {toolchain.lint_command} INTO ; RESTORE \n output: \nHANDOFF GATE:\n [check] names under (evidence: the report line)\n [check] carries the expected message (evidence: the message text)\n [check] restored (evidence: a read returns the original) over: probes measured: / \n refuse: names a real file before PERSIST_ARTIFACT\n result: pass -> NODE 5 | silent -> REPAIR (owner: NODE 2) | unknown -> BLOCKED\n\n# NODE 5 — VERIFY THE TREE [evaluative · verification · logic · yields: boolean]\n@genesis: constraint\nCONTRACT:\n input: from NODE 4\n transform: EXECUTE_TOOL {toolchain.verify_command} INTO ; VALIDATE_ARTIFACT AGAINST \n output: \nHANDOFF GATE:\n [check] green on one full run (evidence: the run's own output)\n [check] every real occurrence of repaired in this change (evidence: the check reports none) over: occurrences measured: / \n [check] caught each of them before the repair (evidence: the first run's report)\n refuse: a run that would mutate the tree before EXECUTE_TOOL\n standing: moved-set \n result: pass -> TERMINATE | occurrence remains -> REPAIR (owner: NODE 1) | unknown -> BLOCKED"; const GATE_PROTOCOL_SAMPLE = "# · ANALYZE -> VERIFY -> REPORT · appended to every plan\n\n# NODE N — VERIFY THE REASONING [evaluative · verification · logic · yields: boolean]\n@genesis: constraint\nCONTRACT:\n input: every node above\n transform: ANALYZE_CONTENT AGAINST INTO ; VALIDATE_ARTIFACT every IN AGAINST ; REPORT_RESULT TO \n output: , with every gate, its evidence, and what it reached\nHANDOFF GATE:\n [check] is empty (evidence: a count of zero) over: measured: / \n [check] every supported by evidence, none by the absence of a contradiction (evidence: an evidence entry per claim)\n [check] names what the run reached before what it found (evidence: the report's first line)\n standing: moved-set \n result: pass -> TERMINATE | weak gate -> REPAIR (owner: the earliest node whose gate is weak) | unknown -> BLOCKED"; const SHAPE_DIAGRAM = 'flowchart TB\n chain["A verb chain"]\n nodes["Nodes · one per verb, tagged with the stage its verb derives"]\n contract["A contract · reads the prior output, yields one record"]\n gate["A gate · three to five checks over the node\'s output, each with its evidence and its set"]\n empty["An empty result is a finding · never a skip"]\n slot["A command or a location is a slot · the adapter resolves it"]\n chain --> nodes --> contract --> gate\n gate --> empty\n nodes --> slot'; const TRANSFER_DIAGRAM = 'flowchart LR\n transfers["Transfers to any task of the shape · the chain, the tags, the contract and gate shape"]\n bound["Bound per task · the nouns, the sources, the thresholds"]\n instance["An instance"]\n example["An example · someone else\'s nouns still inside"]\n transfers --> instance\n bound --> instance\n transfers -. nouns not rebound .-> example'; export const ALGORITHM_SECTION: Section = { icon: ALGORITHM_SECTION_ICON, id: ALGORITHM_SECTION_ID, intro: "An algorithm is a protocol instantiated: the chain expanded into nodes, each headed by its layer, axis, math type and yields and tagged with its genesis stage, each contracted to the prior node's output and closed by an evidence-bearing gate, and every placeholder bound to the task's own nouns. Three instances follow, separate a unit, author an enforcement and verification gate, and the diagrams say what every instance carries beyond its chain, beyond the chain, and what transfers between them and what is bound per task, transfers or bound.", subsections: [ { blocks: [ { application: "Write the chain above the nodes, with the reason it was chosen, so a reader sees the protocol before the instance. Expand one node per verb, tag it with the stage the verb derives, and bind each placeholder to a noun from the task so no placeholder survives into the document. Give each node a contract whose input names the prior output, and close it on three to five checks that name its output, the evidence that settles each and the set at least one ranged over. Route a failure to the earliest node that can supply the missing evidence and an unknown to blocked, refuse before every write, make an empty result a finding rather than a silent skip, and name every command and location as a slot the adapter resolves.", boundary: "A node with two decisions is two nodes, and the examples are not a licence to collapse them.", cause: "The chain is the protocol's contract and the gates are how the contract is checked, so the two transfer together and the nouns do not.", decision: "Bind the task's nouns into the protocol's shape, rather than edit an example until it fits.", failureMode: "A seam search returns nothing, the node is skipped without an entry, the extraction runs over an empty set, and the count that would have exposed the gap is taken over the wrong population.", kind: "lesson", principle: "An algorithm is a protocol with its chain expanded, its nodes tagged and its steps gated.", problem: "An algorithm copied from an example keeps the example's nouns and loses the task's.", validation: "Find a placeholder that survived into the document, a node whose stage disagrees with its verb, a contract whose input names nothing from its predecessor, or a gate whose count is taken over a set smaller than the one it claims. Any of the four is an instance that was copied rather than bound.", }, { kind: "text", text: "In the first instance two checks carry the honesty. An empty seam set is a unit that does not split and is reported as such, because a green over an empty population measures nothing, and the population beside the verdict is what makes that visible. The repair owner on the extraction gate is the seam node, because a bad extraction is usually a bad seam.", }, { kind: "text", text: "The second instance is the shape every rule held by attention takes before it is trusted. The analysis names a shape rather than an instance, because a check that names an instance dies on the next case. The check is proven to fire the way the check comes first describes, and that failure routes back to the node that composed the check, not to the probe; the probe's own write is refused where it would land on a real file.", }, { kind: "text", text: "The third instance is appended to every plan rather than chosen; its gate is the evidence gate of from intent to structure, applied to the plan's own reasoning, and its standing line names what moved beneath the plan while it was checked.", }, { code: SEPARATE_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "separate a unit" }, { code: ENFORCE_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "author an enforcement" }, { code: GATE_PROTOCOL_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "verification gate" }, { caption: "beyond the chain", kind: "mermaid", text: SHAPE_DIAGRAM }, { caption: "transfers or bound", kind: "mermaid", text: TRANSFER_DIAGRAM }, ], title: "Three instances", }, ], title: "Algorithm examples", };