import { PAG_LANGUAGE } from "#configuration/constants/code.constants"; import { PATTERN_SECTION_ICON } from "#configuration/icons/grammar.icons"; import { PATTERN_SECTION_ID } from "#core/ids/grammar.ids"; import type { Section } from "#types/document.types"; const BINDING_SAMPLE = '# NODE 1 — ORIENT [epistemic · ontology · set-theory · yields: run-context]\n@purpose: "Bind the run to exactly one phase kind before touching anything, so the op-set is a contract rather than restraint"\n@cue: "DISCLOSE_THEN_BIND"\n\nCONTRACT:\n input: \n transform: detect the phase kind -> bind its allowed and forbidden operations -> bind the one artifact it emits\n constraints: INVESTIGATE and ACTION are mutually exclusive; the checks that heal rewrite the tree, so they belong to ACTION\n output: run_context { phase, allowed_ops, forbidden_ops, artifact }\n handoff: phase bound to exactly one AND the two op-sets disjoint (yields: boolean)\n\nFUNCTION bind_phase(invocation):\n DETERMINE kind FROM invocation # INVESTIGATE | ACTION\n IF kind == "INVESTIGATE":\n RETURN {phase: "INVESTIGATE", allowed_ops: [DISCOVER_RESOURCES, READ_RESOURCE, SEARCH_CONTENT, ANALYZE_CONTENT], forbidden_ops: [, ], artifact: }\n IF kind == "ACTION":\n RETURN {phase: "ACTION", allowed_ops: [, PERSIST_ARTIFACT, EXECUTE_TOOL], forbidden_ops: [], artifact: }\n\nHANDOFF GATE (evidence-bearing):\n rule_id: "ORIENT" yields: boolean\n [check] phase bound to exactly one of INVESTIGATE | ACTION (evidence: run_context.phase)\n [check] allowed and forbidden op-sets are disjoint (evidence: run_context.allowed_ops, forbidden_ops)\n [check] the artifact the phase emits is the one its kind emits (evidence: run_context.artifact)\n result: pass -> NODE 2 | undetectable kind -> REPAIR (owner: NODE 1) | unknown -> BLOCKED'; const ADMISSIBLE_SAMPLE = '# NODE 7 — CONSTRAIN [conative · teleology · optimisation · yields: admissibility boolean]\n@purpose: "Ask after the operations exist whether they stayed inside the bound op-set · a declaration is not evidence that it held"\n@cue: "ADMISSIBLE_BEFORE_VERIFY"\n\nCONTRACT:\n input: observations + run_context\n transform: for each observation -> did it mutate under INVESTIGATE, did it discover under ACTION\n constraints: a breach routes to the node that owns the fix, never a repair in place, because repairing in place is the same breach in the node that found it\n output: admissibility { ok, op_violations[] }\n handoff: GATE — op-sets honoured (yields: boolean)\n\nFUNCTION assess_admissibility(observations, run_context):\n DECLARE op_violations: array\n SET op_violations = []\n FOR EACH o IN observations:\n IF run_context.phase == "INVESTIGATE" AND o CAUSED : APPEND {claim: o.claim, violation: "mutation under INVESTIGATE"} TO op_violations\n IF run_context.phase == "ACTION" AND o DISCOVERED : APPEND {claim: o.claim, violation: "discovery under ACTION"} TO op_violations\n RETURN {ok: op_violations.length == 0, op_violations: op_violations}\n\nHANDOFF GATE (teleology admissibility gate):\n rule_id: "CONSTRAIN" yields: boolean\n [check] admissibility.op_violations.length == 0 (evidence: INVESTIGATE no mutation / ACTION no discovery)\n [check] every observation was classified against the phase (evidence: one verdict per observation) over: observations measured: / \n [check] every breach names the node that owns the fix (evidence: op_violations[].owner)\n result: pass -> NODE 8 | a breach -> REPAIR (owner: NODE 6) | unknown -> BLOCKED'; const CYCLE_SAMPLE = "# the shape that follows is a cycle rather than a line · the edge back is where a missed repair is caught\nINVESTIGATE -> \nACTION -> \nINVESTIGATE -> \nSTOP when "; const BINDING_DIAGRAM = 'flowchart TB\n phase["A run"]\n kind{"Bound to which?"}\n inv["INVESTIGATE · discovers, never fixes · emits a report"]\n act["ACTION · fixes against known evidence, never discovers · emits a log"]\n mixed["Both · mutated under a read-only contract, findings describe a tree that moved"]\n phase --> kind\n kind -- one --> inv\n kind -- the other --> act\n kind -. neither, or both .-> mixed'; const CYCLE_DIAGRAM = 'flowchart LR\n i1["Investigate"]\n a1["Act"]\n i2["Investigate · verify"]\n stop["Stop · every gap resolved or carried with a reason"]\n i1 --> a1 --> i2\n i2 -- gaps remain --> a1\n i2 -- none --> stop'; export const PATTERN_SECTION: Section = { icon: PATTERN_SECTION_ICON, id: PATTERN_SECTION_ID, intro: "A run is bound to exactly one of two kinds before it touches anything, the binding agents as executed contracts derives and two kinds draws. The orient node binds the kind, as binding the kind writes, and the constrain node asks afterwards whether it held, which admissibility writes; the cycle and cycle, not line are the shape the two kinds make together.", subsections: [ { blocks: [ { application: "Bind every run to one kind in its orient node, and derive the operations it permits and forbids from that kind rather than listing them by hand. Let an investigation discover, read, search and analyze, and let it persist exactly one report. Let an action read the report, repair each gap in dependency order, and log what changed. Verify in the constrain node, after the operations exist, that each stayed inside its set, and route a breach to the node that owns the fix.", boundary: "A single-party task with one read and one write is one action run, and splitting it into an investigation and an action doubles the document for nothing. The binding matters where the findings will be read by a party that did not produce them.", cause: "A finding is a claim about a tree, and a tree the finder also mutated is a different tree from the one the finding describes.", decision: "Bind the kind in the orient node before any operation, over declaring it in prose and trusting the op-set to hold.", failureMode: "A run finds a defect, repairs it in passing, and reports the defect as open, so the next run repairs it again against a tree where it no longer exists.", kind: "lesson", principle: "A run investigates or acts, and the two op-sets share nothing.", problem: "A run asked to look starts repairing what it sees.", validation: "List the operations of a run and mark each as reading or writing. A run with both kinds is unbound, and the first write is where it splits.", }, { kind: "text", text: "The binding is a property of the run, declared in its orient node before any operation, and the op-sets follow from it, which is state isolation applied to a run. An investigation may discover resources, read them, search them and analyze them, and it may persist one artifact: the report. It may not edit, write elsewhere or execute a command that mutates, which includes the verification chain, because the chain's early stages rewrite the tree. An action may persist, execute and fix, and it may not widen its scope, because a scope discovered mid-action is a finding nobody reported and nobody will verify. The method teaches the same binding under agents as executed contracts; here it is one node's contract.", }, { kind: "text", text: "The shape that follows is a cycle rather than a line. Investigate, then act, then investigate again to verify what the action did, and stop when the second investigation finds every gap resolved or carried forward with a reason. Each investigation reads the same report and removes what is settled, so the report converges rather than accumulating. A fixed pipeline of positions cannot express this, because it has no edge back, and the edge back is where a repair that missed is caught.", }, { kind: "text", text: "A run declared as an investigation can still contain a write that nobody noticed, and a check that reads the declaration passes it. So the constrain node verifies the observations against the op-set the binding declared, and a breach routes to the node that owns the fix rather than being repaired in place, because repairing it in place is the same breach in the node that found it.", }, { code: BINDING_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "binding the kind" }, { code: ADMISSIBLE_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "admissibility" }, { code: CYCLE_SAMPLE, kind: "code", language: PAG_LANGUAGE, title: "the cycle" }, { caption: "two kinds", kind: "mermaid", text: BINDING_DIAGRAM }, { caption: "cycle, not line", kind: "mermaid", text: CYCLE_DIAGRAM }, ], title: "Investigate or act", }, ], title: "Phase binding", };