/** * Structure — the universal node of the system graph. * * Every node is a Structure: * - What it is (name + description) * - Where it lives (parent — tree backbone) * - What it carries (information — Gherkin Feature source) * - What it relates to (relations — cross-branch links) * * Tree (parent-child) provides the hierarchical backbone. * Relations provide cross-branch associations. * Together they form a graph. * * Type definitions have no ref (schema). * Runtime instances have ref (assigned by runtime). * Every node can carry information AND have children. * * Identifiers: * ref — graph engine internal reference (e.g., "n3", "e5"), assigned by runtime * id — user-facing kebab-case identifier (e.g., "sean", "build-auth") * alias — alternative names for lookup (e.g., ["Sean", "姜山"]) */ /** Relation — a cross-branch link type between structures. */ interface Relation { /** The relation name (e.g., "appointment"). */ readonly name: string; /** What this relation means. */ readonly description: string; /** The target structure type this relation points to. */ readonly target: Structure; } interface Structure { /** Graph engine internal reference (e.g., "n3", "e5"), assigned by runtime. */ readonly ref?: string; /** User-facing kebab-case identifier (e.g., "sean", "build-auth"). */ readonly id?: string; /** Alternative names for lookup (e.g., ["Sean", "姜山"]). */ readonly alias?: readonly string[]; /** The structure name (e.g., "goal", "persona", "task"). */ readonly name: string; /** What this structure is. */ readonly description: string; /** Parent structure. null = root of the graph. */ readonly parent: Structure | null; /** Gherkin Feature source text. */ readonly information?: string; /** Relations to other structure types (cross-branch links). */ readonly relations?: readonly Relation[]; /** Generic label (e.g., "done", "abandoned"). */ readonly tag?: string; } /** * relation — declare a cross-branch link type. */ declare const relation: (name: string, description: string, target: Structure) => Relation; /** * structure — declare a type of node in the system graph. */ declare const structure: (name: string, description: string, parent: Structure | null, relations?: Relation[]) => Structure; /** * Process — how the system graph changes. * * Five graph primitives: * create — add a child node under a parent * remove — delete a node and its subtree * transform — harvest from one branch, produce in another * link — establish a cross-branch relation * unlink — remove a cross-branch relation * * Universal formula: * State = Process(Structure, Information?) */ /** create — add a new child node of a structure type. */ interface Create { readonly op: "create"; readonly structure: Structure; } /** remove — delete a node (and its subtree). */ interface Remove { readonly op: "remove"; readonly structure: Structure; } /** transform — harvest from one structure, produce another in a different branch. */ interface Transform { readonly op: "transform"; readonly from: Structure; readonly to: Structure; } /** link — establish a cross-branch relation. */ interface Link { readonly op: "link"; readonly structure: Structure; readonly relation: string; } /** unlink — remove a cross-branch relation. */ interface Unlink { readonly op: "unlink"; readonly structure: Structure; readonly relation: string; } /** A single graph operation. */ type GraphOp = Create | Remove | Transform | Link | Unlink; /** * Process — a named composition of graph operations. * * Universal formula: * State = Process(Structure, Information?) */ interface Process { /** The process name (e.g., "want", "achieve", "reflect"). */ readonly name: string; /** What this process does. */ readonly description: string; /** The structure type this process targets. */ readonly target: Structure; /** The graph operations this process performs, in order. */ readonly ops: readonly GraphOp[]; } /** * State — the projection of a node after a process executes. * * A State is a Structure snapshot with its subtree and links. */ interface State extends Structure { /** Child states (subtree projection). */ readonly children?: readonly State[]; /** Cross-branch links from this node. */ readonly links?: readonly { readonly relation: string; readonly target: State; }[]; /** Origin of this node in a merged projection: prototype (read-only) or instance (mutable). */ readonly origin?: "prototype" | "instance"; } declare const create: (structure: Structure) => Create; declare const remove: (structure: Structure) => Remove; declare const transform: (from: Structure, to: Structure) => Transform; declare const link: (structure: Structure, relation: string) => Link; declare const unlink: (structure: Structure, relation: string) => Unlink; declare const process: (name: string, description: string, target: Structure, ...ops: GraphOp[]) => Process; /** * Initializer — bootstrap the world on first run. * * Ensures built-in prototypes are settled and foundational structures * are created before any runtime operations. * * Idempotent: subsequent calls after initialization are no-ops. */ /** Bootstrap the world — settle built-in prototypes and create foundational structures. */ interface Initializer { /** Run initialization if not already done. Idempotent. */ bootstrap(): Promise; } /** * Runtime — execution engine for the system graph. * * Six operations: * create — add a child node under a parent * remove — delete a node and its subtree * transform — produce from one branch into another * link — establish a cross-branch relation * unlink — remove a cross-branch relation * project — read the current state * * State = Process(Structure, Information?) */ interface Runtime { /** Create a child node (parent=null for root). Type is the structure template. */ create(parent: Structure | null, type: Structure, information?: string, id?: string, alias?: readonly string[]): Promise; /** Remove a node and its subtree. */ remove(node: Structure): Promise; /** Move a node to target structure's branch, preserving its subtree. Updates type and optionally information. */ transform(source: Structure, target: Structure, information?: string): Promise; /** Establish a bidirectional cross-branch relation between two nodes. */ link(from: Structure, to: Structure, relation: string, reverse: string): Promise; /** Remove a bidirectional cross-branch relation between two nodes. */ unlink(from: Structure, to: Structure, relation: string, reverse: string): Promise; /** Set a tag on a node (e.g., "done", "abandoned"). */ tag(node: Structure, tag: string): Promise; /** Project the current state of a node and its subtree (including links). */ project(node: Structure): Promise; /** Return all root nodes (nodes without a parent edge). */ roots(): Promise; } declare const createRuntime: () => Runtime; export { type Create, type GraphOp, type Initializer, type Link, type Process, type Relation, type Remove, type Runtime, type State, type Structure, type Transform, type Unlink, create, createRuntime, link, process, relation, remove, structure, transform, unlink };