@rolexjs/system 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,241 @@
1
+ # @rolexjs/system
2
+
3
+ A concept world engine. Define concepts, build a tree, link them with relations — the world emerges.
4
+
5
+ This package provides the **rules** of the concept world. It is domain-agnostic — it knows nothing about roles, organizations, or AI agents. The upper layer's job is to **define concepts** and paint the world using these rules.
6
+
7
+ ## The World
8
+
9
+ The world is a graph made of concepts.
10
+
11
+ Every node is a **Structure** — simultaneously three things:
12
+
13
+ - **Concept** — what it is (name + description)
14
+ - **Container** — can have child nodes
15
+ - **Information carrier** — can hold information (e.g. a Gherkin Feature text)
16
+
17
+ There is no special "container" type or "leaf" type. Every node is all three at once.
18
+
19
+ ```
20
+ world
21
+ ├── agent ← concept, also a container
22
+ │ ├── knowledge ← container (has children)
23
+ │ │ ├── pattern ← information carrier
24
+ │ │ │ info: "Feature: ..."
25
+ │ │ └── procedure
26
+ │ │ info: "Feature: ..."
27
+ │ ├── experience ← information carrier (no children)
28
+ │ │ info: "Feature: I learned..."
29
+ │ └── experience ← OR a container (has children)
30
+ │ └── insight
31
+ │ info: "Feature: JWT lesson..."
32
+ └── org
33
+ └── position ──relation──→ agent ← cross-branch link
34
+ ```
35
+
36
+ ### Tree + Relations = Graph
37
+
38
+ - **Tree** (parent → child) provides the hierarchical backbone
39
+ - **Relations** provide cross-branch associations
40
+ - Together they form a graph
41
+
42
+ ## Four Concepts
43
+
44
+ ```
45
+ Structure — the node (what exists)
46
+ Relation — the link (how they connect)
47
+ Process — the change (how it evolves)
48
+ State — the projection (what you see)
49
+ ```
50
+
51
+ ### Structure
52
+
53
+ A Structure defines a type of node in the concept world.
54
+
55
+ ```typescript
56
+ import { structure } from "@rolexjs/system";
57
+
58
+ // Root concept
59
+ const world = structure("world", "The concept world", null);
60
+
61
+ // Child concepts — parent defines where they live in the tree
62
+ const agent = structure("agent", "An agent identity", world);
63
+ const knowledge = structure("knowledge", "What I know", agent);
64
+ const experience = structure("experience", "What I learned", agent);
65
+ const insight = structure("insight", "A specific learning", experience);
66
+ ```
67
+
68
+ The `parent` parameter establishes the tree backbone: `insight` lives under `experience`, which lives under `agent`, which lives under `world`.
69
+
70
+ ### Relation
71
+
72
+ A Relation defines a cross-branch link type on a Structure.
73
+
74
+ ```typescript
75
+ import { structure, relation } from "@rolexjs/system";
76
+
77
+ const agent = structure("agent", "An agent identity", world);
78
+ const org = structure("org", "An organization", world);
79
+
80
+ // position lives under org, and can link to agent
81
+ const position = structure("position", "A role in an organization", org, [
82
+ relation("appointment", "The individual holding this position", agent),
83
+ ]);
84
+ ```
85
+
86
+ Relations are declared on the Structure definition as an array. A Structure can have multiple relations pointing to different concept types.
87
+
88
+ ### Process
89
+
90
+ A Process defines how the world changes — a named composition of graph operations.
91
+
92
+ Five graph primitives:
93
+
94
+ | Primitive | What it does |
95
+ | ----------------- | ---------------------------------------------------- |
96
+ | `create(s)` | Add a child node of structure type `s` |
97
+ | `remove(s)` | Delete a node of structure type `s` and its subtree |
98
+ | `transform(a, b)` | Harvest from structure `a`, produce in structure `b` |
99
+ | `link(s, r)` | Establish relation `r` on structure `s` |
100
+ | `unlink(s, r)` | Remove relation `r` on structure `s` |
101
+
102
+ ```typescript
103
+ import { process, create, remove, transform, link, unlink } from "@rolexjs/system";
104
+
105
+ // Read-only process (no ops) — just projects state
106
+ const identity = process("identity", "Project full identity", agent);
107
+
108
+ // Create process — adds a new concept instance
109
+ const want = process("want", "Declare a goal", agent, create(goal));
110
+
111
+ // Transform process — converts one concept into another
112
+ const achieve = process("achieve", "Complete a goal", goal, transform(goal, insight));
113
+
114
+ // Link process — establishes a cross-branch relation
115
+ const appoint = process("appoint", "Assign to position", position, link(position, "appointment"));
116
+
117
+ // Unlink process — removes a cross-branch relation
118
+ const dismiss = process(
119
+ "dismiss",
120
+ "Remove from position",
121
+ position,
122
+ unlink(position, "appointment")
123
+ );
124
+ ```
125
+
126
+ ### State
127
+
128
+ A State is the projection of a node — a snapshot of its subtree and links.
129
+
130
+ ```typescript
131
+ // State extends Structure, adding:
132
+ interface State extends Structure {
133
+ children?: readonly State[]; // subtree
134
+ links?: readonly { relation: string; target: State }[]; // cross-branch links
135
+ }
136
+ ```
137
+
138
+ State is never stored — it is computed on demand via `runtime.project(node)`.
139
+
140
+ ## Runtime
141
+
142
+ The Runtime is the execution engine. It operates on concept instances (nodes with `id`).
143
+
144
+ ```typescript
145
+ import { createRuntime } from "@rolexjs/system";
146
+
147
+ const rt = createRuntime();
148
+
149
+ // Create instances
150
+ const root = rt.create(null, world);
151
+ const sean = rt.create(root, agent, "Feature: I am Sean...");
152
+ const dp = rt.create(root, org);
153
+ const arch = rt.create(dp, position);
154
+
155
+ // Link them
156
+ rt.link(arch, sean, "appointment");
157
+
158
+ // Project the state
159
+ const state = rt.project(root);
160
+ // → world
161
+ // ├── agent (Sean) info: "Feature: I am Sean..."
162
+ // └── org
163
+ // └── position
164
+ // links: [{ relation: "appointment", target: agent(Sean) }]
165
+
166
+ // Unlink
167
+ rt.unlink(arch, sean, "appointment");
168
+
169
+ // Remove (cleans up subtree + all related links)
170
+ rt.remove(arch);
171
+ ```
172
+
173
+ ### Runtime API
174
+
175
+ | Method | Description |
176
+ | ---------------------------------- | ---------------------------------------------------- |
177
+ | `create(parent, type, info?)` | Create a node. `parent=null` for root. |
178
+ | `remove(node)` | Remove a node, its subtree, and all related links. |
179
+ | `transform(source, target, info?)` | Produce a new node in target's branch. |
180
+ | `link(from, to, relation)` | Establish a cross-branch relation. Idempotent. |
181
+ | `unlink(from, to, relation)` | Remove a cross-branch relation. |
182
+ | `project(node)` | Compute the current state of a node and its subtree. |
183
+
184
+ ## Defining Your World
185
+
186
+ This package provides the rules. Your job is to define the concepts.
187
+
188
+ **Step 1: Define the concept tree** — what kinds of things exist and how they nest.
189
+
190
+ ```typescript
191
+ const society = structure("society", "The world", null);
192
+ const individual = structure("individual", "An agent", society);
193
+ const persona = structure("persona", "Who I am", individual);
194
+ const goal = structure("goal", "What I pursue", individual);
195
+ const plan = structure("plan", "How to achieve it", goal);
196
+ const task = structure("task", "Concrete work", plan);
197
+ ```
198
+
199
+ **Step 2: Define relations** — what connects across branches.
200
+
201
+ ```typescript
202
+ const org = structure("organization", "A group", society);
203
+ const position = structure("position", "A role in the group", org, [
204
+ relation("appointment", "Who holds this", individual),
205
+ ]);
206
+ ```
207
+
208
+ **Step 3: Define processes** — how the world changes.
209
+
210
+ ```typescript
211
+ const want = process("want", "Declare a goal", individual, create(goal));
212
+ const design = process("design", "Plan for a goal", goal, create(plan));
213
+ const achieve = process("achieve", "Complete a goal", goal, transform(goal, conclusion));
214
+ const appoint = process("appoint", "Assign to position", position, link(position, "appointment"));
215
+ ```
216
+
217
+ **Step 4: Run it** — create instances, link them, project state.
218
+
219
+ ```typescript
220
+ const rt = createRuntime();
221
+ const world = rt.create(null, society);
222
+ const sean = rt.create(world, individual, "Feature: I am Sean...");
223
+ const myGoal = rt.create(sean, goal, "Feature: Build auth system...");
224
+ const myPlan = rt.create(myGoal, plan, "Feature: Auth plan...");
225
+ ```
226
+
227
+ The rules are fixed. The world is yours to paint.
228
+
229
+ ## Universal Formula
230
+
231
+ ```
232
+ State = Process(Structure, Information?)
233
+ ```
234
+
235
+ Everything reduces to this: a Process operates on a Structure (optionally with Information), and produces a State.
236
+
237
+ ## Install
238
+
239
+ ```bash
240
+ bun add @rolexjs/system
241
+ ```
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Structure — the universal node of the system graph.
3
+ *
4
+ * Every node is a Structure:
5
+ * - What it is (name + description)
6
+ * - Where it lives (parent — tree backbone)
7
+ * - What it carries (information — Gherkin Feature source)
8
+ * - What it relates to (relations — cross-branch links)
9
+ *
10
+ * Tree (parent-child) provides the hierarchical backbone.
11
+ * Relations provide cross-branch associations.
12
+ * Together they form a graph.
13
+ *
14
+ * Type definitions have no ref (schema).
15
+ * Runtime instances have ref (assigned by runtime).
16
+ * Every node can carry information AND have children.
17
+ *
18
+ * Identifiers:
19
+ * ref — graph engine internal reference (e.g., "n3", "e5"), assigned by runtime
20
+ * id — user-facing kebab-case identifier (e.g., "sean", "build-auth")
21
+ * alias — alternative names for lookup (e.g., ["Sean", "姜山"])
22
+ */
23
+ /** Relation — a cross-branch link type between structures. */
24
+ interface Relation {
25
+ /** The relation name (e.g., "appointment"). */
26
+ readonly name: string;
27
+ /** What this relation means. */
28
+ readonly description: string;
29
+ /** The target structure type this relation points to. */
30
+ readonly target: Structure;
31
+ }
32
+ interface Structure {
33
+ /** Graph engine internal reference (e.g., "n3", "e5"), assigned by runtime. */
34
+ readonly ref?: string;
35
+ /** User-facing kebab-case identifier (e.g., "sean", "build-auth"). */
36
+ readonly id?: string;
37
+ /** Alternative names for lookup (e.g., ["Sean", "姜山"]). */
38
+ readonly alias?: readonly string[];
39
+ /** The structure name (e.g., "goal", "persona", "task"). */
40
+ readonly name: string;
41
+ /** What this structure is. */
42
+ readonly description: string;
43
+ /** Parent structure. null = root of the graph. */
44
+ readonly parent: Structure | null;
45
+ /** Gherkin Feature source text. */
46
+ readonly information?: string;
47
+ /** Relations to other structure types (cross-branch links). */
48
+ readonly relations?: readonly Relation[];
49
+ }
50
+ /**
51
+ * relation — declare a cross-branch link type.
52
+ */
53
+ declare const relation: (name: string, description: string, target: Structure) => Relation;
54
+ /**
55
+ * structure — declare a type of node in the system graph.
56
+ */
57
+ declare const structure: (name: string, description: string, parent: Structure | null, relations?: Relation[]) => Structure;
58
+
59
+ /**
60
+ * Process — how the system graph changes.
61
+ *
62
+ * Five graph primitives:
63
+ * create — add a child node under a parent
64
+ * remove — delete a node and its subtree
65
+ * transform — harvest from one branch, produce in another
66
+ * link — establish a cross-branch relation
67
+ * unlink — remove a cross-branch relation
68
+ *
69
+ * Universal formula:
70
+ * State = Process(Structure, Information?)
71
+ */
72
+
73
+ /** create — add a new child node of a structure type. */
74
+ interface Create {
75
+ readonly op: "create";
76
+ readonly structure: Structure;
77
+ }
78
+ /** remove — delete a node (and its subtree). */
79
+ interface Remove {
80
+ readonly op: "remove";
81
+ readonly structure: Structure;
82
+ }
83
+ /** transform — harvest from one structure, produce another in a different branch. */
84
+ interface Transform {
85
+ readonly op: "transform";
86
+ readonly from: Structure;
87
+ readonly to: Structure;
88
+ }
89
+ /** link — establish a cross-branch relation. */
90
+ interface Link {
91
+ readonly op: "link";
92
+ readonly structure: Structure;
93
+ readonly relation: string;
94
+ }
95
+ /** unlink — remove a cross-branch relation. */
96
+ interface Unlink {
97
+ readonly op: "unlink";
98
+ readonly structure: Structure;
99
+ readonly relation: string;
100
+ }
101
+ /** A single graph operation. */
102
+ type GraphOp = Create | Remove | Transform | Link | Unlink;
103
+ /**
104
+ * Process — a named composition of graph operations.
105
+ *
106
+ * Universal formula:
107
+ * State = Process(Structure, Information?)
108
+ */
109
+ interface Process {
110
+ /** The process name (e.g., "want", "achieve", "reflect"). */
111
+ readonly name: string;
112
+ /** What this process does. */
113
+ readonly description: string;
114
+ /** The structure type this process targets. */
115
+ readonly target: Structure;
116
+ /** The graph operations this process performs, in order. */
117
+ readonly ops: readonly GraphOp[];
118
+ }
119
+ /**
120
+ * State — the projection of a node after a process executes.
121
+ *
122
+ * A State is a Structure snapshot with its subtree and links.
123
+ */
124
+ interface State extends Structure {
125
+ /** Child states (subtree projection). */
126
+ readonly children?: readonly State[];
127
+ /** Cross-branch links from this node. */
128
+ readonly links?: readonly {
129
+ readonly relation: string;
130
+ readonly target: State;
131
+ }[];
132
+ /** Origin of this node in a merged projection: prototype (read-only) or instance (mutable). */
133
+ readonly origin?: "prototype" | "instance";
134
+ }
135
+ declare const create: (structure: Structure) => Create;
136
+ declare const remove: (structure: Structure) => Remove;
137
+ declare const transform: (from: Structure, to: Structure) => Transform;
138
+ declare const link: (structure: Structure, relation: string) => Link;
139
+ declare const unlink: (structure: Structure, relation: string) => Unlink;
140
+ declare const process: (name: string, description: string, target: Structure, ...ops: GraphOp[]) => Process;
141
+
142
+ /**
143
+ * mergeState — union merge two State trees.
144
+ *
145
+ * Prototype mechanism: merge a base (prototype) with an overlay (instance).
146
+ * Children are unioned, not overwritten. Links are unioned and deduplicated.
147
+ *
148
+ * Matching rules for children:
149
+ * - Same name + same id (both defined) → recursive merge
150
+ * - Same name + both no id + one each → recursive merge (structural singleton)
151
+ * - Everything else → include from both sides
152
+ */
153
+
154
+ declare const mergeState: (base: State, overlay: State) => State;
155
+
156
+ /**
157
+ * Prototype — a source of base State trees for merging.
158
+ *
159
+ * A prototype provides a pre-configured State tree (template) that gets
160
+ * merged with an instance State via mergeState.
161
+ *
162
+ * Matching is by id: if prototype and instance share the same id,
163
+ * they are the same entity — prototype provides the base,
164
+ * instance provides the overlay.
165
+ *
166
+ * activate(id) = mergeState(prototype.resolve(id), runtime.project(id))
167
+ */
168
+
169
+ /** A source that resolves prototype State trees by id. */
170
+ interface Prototype {
171
+ /** Resolve a prototype State by id. Returns undefined if no prototype exists. */
172
+ resolve(id: string): Promise<State | undefined>;
173
+ }
174
+ /** Create an in-memory prototype source. */
175
+ declare const createPrototype: () => Prototype & {
176
+ /** Register a State tree as a prototype (keyed by state.id). */
177
+ register(state: State): void;
178
+ };
179
+
180
+ /**
181
+ * Runtime — execution engine for the system graph.
182
+ *
183
+ * Six operations:
184
+ * create — add a child node under a parent
185
+ * remove — delete a node and its subtree
186
+ * transform — produce from one branch into another
187
+ * link — establish a cross-branch relation
188
+ * unlink — remove a cross-branch relation
189
+ * project — read the current state
190
+ *
191
+ * State = Process(Structure, Information?)
192
+ */
193
+
194
+ interface Runtime {
195
+ /** Create a child node (parent=null for root). Type is the structure template. */
196
+ create(parent: Structure | null, type: Structure, information?: string, id?: string, alias?: readonly string[]): Structure;
197
+ /** Remove a node and its subtree. */
198
+ remove(node: Structure): void;
199
+ /** Produce a new node in target structure's branch, sourced from another branch. */
200
+ transform(source: Structure, target: Structure, information?: string): Structure;
201
+ /** Establish a bidirectional cross-branch relation between two nodes. */
202
+ link(from: Structure, to: Structure, relation: string, reverse: string): void;
203
+ /** Remove a bidirectional cross-branch relation between two nodes. */
204
+ unlink(from: Structure, to: Structure, relation: string, reverse: string): void;
205
+ /** Project the current state of a node and its subtree (including links). */
206
+ project(node: Structure): State;
207
+ /** Return all root nodes (nodes without a parent edge). */
208
+ roots(): Structure[];
209
+ }
210
+ declare const createRuntime: () => Runtime;
211
+
212
+ export { type Create, type GraphOp, type Link, type Process, type Prototype, type Relation, type Remove, type Runtime, type State, type Structure, type Transform, type Unlink, create, createPrototype, createRuntime, link, mergeState, process, relation, remove, structure, transform, unlink };
package/dist/index.js ADDED
@@ -0,0 +1,312 @@
1
+ // src/structure.ts
2
+ var relation = (name, description, target) => ({
3
+ name,
4
+ description,
5
+ target
6
+ });
7
+ var structure = (name, description, parent, relations) => ({
8
+ name,
9
+ description,
10
+ parent,
11
+ ...relations ? { relations } : {}
12
+ });
13
+
14
+ // src/process.ts
15
+ var create = (structure2) => ({ op: "create", structure: structure2 });
16
+ var remove = (structure2) => ({ op: "remove", structure: structure2 });
17
+ var transform = (from, to) => ({
18
+ op: "transform",
19
+ from,
20
+ to
21
+ });
22
+ var link = (structure2, relation2) => ({
23
+ op: "link",
24
+ structure: structure2,
25
+ relation: relation2
26
+ });
27
+ var unlink = (structure2, relation2) => ({
28
+ op: "unlink",
29
+ structure: structure2,
30
+ relation: relation2
31
+ });
32
+ var process = (name, description, target, ...ops) => ({
33
+ name,
34
+ description,
35
+ target,
36
+ ops
37
+ });
38
+
39
+ // src/merge.ts
40
+ var mergeState = (base, overlay) => {
41
+ const taggedBase = tagOrigin(base, "prototype");
42
+ const taggedOverlay = tagOrigin(overlay, "instance");
43
+ const mergedChildren = mergeChildren(taggedBase.children, taggedOverlay.children);
44
+ const mergedLinks = mergeLinks(taggedBase.links, taggedOverlay.links);
45
+ return {
46
+ ...taggedBase,
47
+ // overlay scalar properties take precedence when present
48
+ ...overlay.ref ? { ref: overlay.ref } : {},
49
+ ...overlay.id ? { id: overlay.id } : {},
50
+ ...overlay.information ? { information: overlay.information } : {},
51
+ ...overlay.alias ? { alias: overlay.alias } : {},
52
+ ...mergedChildren ? { children: mergedChildren } : {},
53
+ ...mergedLinks ? { links: mergedLinks } : {},
54
+ // root node with overlay ref is instance
55
+ origin: overlay.ref ? "instance" : "prototype"
56
+ };
57
+ };
58
+ var tagOrigin = (state, origin) => ({
59
+ ...state,
60
+ origin,
61
+ ...state.children ? { children: state.children.map((c) => tagOrigin(c, origin)) } : {}
62
+ });
63
+ var mergeChildren = (baseChildren, overlayChildren) => {
64
+ if (!baseChildren && !overlayChildren) return void 0;
65
+ if (!baseChildren) return overlayChildren;
66
+ if (!overlayChildren) return baseChildren;
67
+ const result = [];
68
+ const baseByName = groupByName(baseChildren);
69
+ const overlayByName = groupByName(overlayChildren);
70
+ const allNames = /* @__PURE__ */ new Set([...baseByName.keys(), ...overlayByName.keys()]);
71
+ for (const name of allNames) {
72
+ const baseGroup = baseByName.get(name) ?? [];
73
+ const overlayGroup = overlayByName.get(name) ?? [];
74
+ if (baseGroup.length === 0) {
75
+ result.push(...overlayGroup);
76
+ continue;
77
+ }
78
+ if (overlayGroup.length === 0) {
79
+ result.push(...baseGroup);
80
+ continue;
81
+ }
82
+ const matchedOverlay = /* @__PURE__ */ new Set();
83
+ const unmatchedBase = [];
84
+ for (const b of baseGroup) {
85
+ if (b.id) {
86
+ const oIdx = overlayGroup.findIndex((o, i) => !matchedOverlay.has(i) && o.id === b.id);
87
+ if (oIdx >= 0) {
88
+ result.push(mergeState(b, overlayGroup[oIdx]));
89
+ matchedOverlay.add(oIdx);
90
+ } else {
91
+ unmatchedBase.push(b);
92
+ }
93
+ } else {
94
+ unmatchedBase.push(b);
95
+ }
96
+ }
97
+ const unmatchedOverlay = overlayGroup.filter((_, i) => !matchedOverlay.has(i));
98
+ const noIdBase = unmatchedBase.filter((s) => !s.id);
99
+ const hasIdBase = unmatchedBase.filter((s) => s.id);
100
+ const noIdOverlay = unmatchedOverlay.filter((s) => !s.id);
101
+ const hasIdOverlay = unmatchedOverlay.filter((s) => s.id);
102
+ if (noIdBase.length === 1 && noIdOverlay.length === 1) {
103
+ result.push(mergeState(noIdBase[0], noIdOverlay[0]));
104
+ } else {
105
+ result.push(...noIdBase, ...noIdOverlay);
106
+ }
107
+ result.push(...hasIdBase, ...hasIdOverlay);
108
+ }
109
+ return result;
110
+ };
111
+ var mergeLinks = (baseLinks, overlayLinks) => {
112
+ if (!baseLinks && !overlayLinks) return void 0;
113
+ if (!baseLinks) return overlayLinks;
114
+ if (!overlayLinks) return baseLinks;
115
+ const seen = /* @__PURE__ */ new Set();
116
+ const result = [];
117
+ for (const link2 of [...baseLinks, ...overlayLinks]) {
118
+ const key = `${link2.relation}:${link2.target.id ?? link2.target.ref ?? link2.target.name}`;
119
+ if (!seen.has(key)) {
120
+ seen.add(key);
121
+ result.push(link2);
122
+ }
123
+ }
124
+ return result;
125
+ };
126
+ var groupByName = (states) => {
127
+ const map = /* @__PURE__ */ new Map();
128
+ for (const s of states) {
129
+ const group = map.get(s.name);
130
+ if (group) {
131
+ group.push(s);
132
+ } else {
133
+ map.set(s.name, [s]);
134
+ }
135
+ }
136
+ return map;
137
+ };
138
+
139
+ // src/prototype.ts
140
+ var createPrototype = () => {
141
+ const prototypes = /* @__PURE__ */ new Map();
142
+ return {
143
+ async resolve(id) {
144
+ return prototypes.get(id);
145
+ },
146
+ register(state) {
147
+ if (!state.id) {
148
+ throw new Error("Prototype state must have an id");
149
+ }
150
+ prototypes.set(state.id, state);
151
+ }
152
+ };
153
+ };
154
+
155
+ // src/runtime.ts
156
+ var createRuntime = () => {
157
+ const nodes = /* @__PURE__ */ new Map();
158
+ const links = /* @__PURE__ */ new Map();
159
+ let counter = 0;
160
+ const nextRef = () => `e${++counter}`;
161
+ const findByStructure = (structure2) => {
162
+ for (const treeNode of nodes.values()) {
163
+ if (treeNode.node.name === structure2.name) return treeNode;
164
+ }
165
+ return void 0;
166
+ };
167
+ const removeSubtree = (ref) => {
168
+ const treeNode = nodes.get(ref);
169
+ if (!treeNode) return;
170
+ for (const childRef of [...treeNode.children]) {
171
+ removeSubtree(childRef);
172
+ }
173
+ links.delete(ref);
174
+ for (const [fromRef, fromLinks] of links.entries()) {
175
+ const filtered = fromLinks.filter((l) => l.toId !== ref);
176
+ if (filtered.length === 0) {
177
+ links.delete(fromRef);
178
+ } else {
179
+ links.set(fromRef, filtered);
180
+ }
181
+ }
182
+ nodes.delete(ref);
183
+ };
184
+ const projectRef = (ref) => {
185
+ const treeNode = nodes.get(ref);
186
+ return { ...treeNode.node, children: [] };
187
+ };
188
+ const projectNode = (ref) => {
189
+ const treeNode = nodes.get(ref);
190
+ const nodeLinks = links.get(ref);
191
+ return {
192
+ ...treeNode.node,
193
+ children: treeNode.children.map(projectNode),
194
+ ...nodeLinks && nodeLinks.length > 0 ? {
195
+ links: nodeLinks.map((l) => ({
196
+ relation: l.relation,
197
+ target: projectRef(l.toId)
198
+ }))
199
+ } : {}
200
+ };
201
+ };
202
+ const createNode = (parentRef, type, information, id, alias) => {
203
+ const ref = nextRef();
204
+ const node = {
205
+ ref,
206
+ ...id ? { id } : {},
207
+ ...alias && alias.length > 0 ? { alias } : {},
208
+ name: type.name,
209
+ description: type.description,
210
+ parent: type.parent,
211
+ information
212
+ };
213
+ const treeNode = { node, parent: parentRef, children: [] };
214
+ nodes.set(ref, treeNode);
215
+ if (parentRef) {
216
+ const parentTreeNode = nodes.get(parentRef);
217
+ if (!parentTreeNode) throw new Error(`Parent not found: ${parentRef}`);
218
+ parentTreeNode.children.push(ref);
219
+ }
220
+ return node;
221
+ };
222
+ return {
223
+ create(parent, type, information, id, alias) {
224
+ return createNode(parent?.ref ?? null, type, information, id, alias);
225
+ },
226
+ remove(node) {
227
+ if (!node.ref) return;
228
+ const treeNode = nodes.get(node.ref);
229
+ if (!treeNode) return;
230
+ if (treeNode.parent) {
231
+ const parentTreeNode = nodes.get(treeNode.parent);
232
+ if (parentTreeNode) {
233
+ parentTreeNode.children = parentTreeNode.children.filter((r) => r !== node.ref);
234
+ }
235
+ }
236
+ removeSubtree(node.ref);
237
+ },
238
+ transform(_source, target, information) {
239
+ const targetParent = target.parent;
240
+ if (!targetParent) {
241
+ throw new Error(`Cannot transform to root structure: ${target.name}`);
242
+ }
243
+ const parentTreeNode = findByStructure(targetParent);
244
+ if (!parentTreeNode) {
245
+ throw new Error(`No node found for structure: ${targetParent.name}`);
246
+ }
247
+ return createNode(parentTreeNode.node.ref, target, information);
248
+ },
249
+ link(from, to, relationName, reverseName) {
250
+ if (!from.ref) throw new Error("Source node has no ref");
251
+ if (!to.ref) throw new Error("Target node has no ref");
252
+ const fromLinks = links.get(from.ref) ?? [];
253
+ if (!fromLinks.some((l) => l.toId === to.ref && l.relation === relationName)) {
254
+ fromLinks.push({ toId: to.ref, relation: relationName });
255
+ links.set(from.ref, fromLinks);
256
+ }
257
+ const toLinks = links.get(to.ref) ?? [];
258
+ if (!toLinks.some((l) => l.toId === from.ref && l.relation === reverseName)) {
259
+ toLinks.push({ toId: from.ref, relation: reverseName });
260
+ links.set(to.ref, toLinks);
261
+ }
262
+ },
263
+ unlink(from, to, relationName, reverseName) {
264
+ if (!from.ref || !to.ref) return;
265
+ const fromLinks = links.get(from.ref);
266
+ if (fromLinks) {
267
+ const filtered = fromLinks.filter(
268
+ (l) => !(l.toId === to.ref && l.relation === relationName)
269
+ );
270
+ if (filtered.length === 0) links.delete(from.ref);
271
+ else links.set(from.ref, filtered);
272
+ }
273
+ const toLinks = links.get(to.ref);
274
+ if (toLinks) {
275
+ const filtered = toLinks.filter(
276
+ (l) => !(l.toId === from.ref && l.relation === reverseName)
277
+ );
278
+ if (filtered.length === 0) links.delete(to.ref);
279
+ else links.set(to.ref, filtered);
280
+ }
281
+ },
282
+ project(node) {
283
+ if (!node.ref || !nodes.has(node.ref)) {
284
+ throw new Error(`Node not found: ${node.ref}`);
285
+ }
286
+ return projectNode(node.ref);
287
+ },
288
+ roots() {
289
+ const result = [];
290
+ for (const treeNode of nodes.values()) {
291
+ if (treeNode.parent === null) {
292
+ result.push(treeNode.node);
293
+ }
294
+ }
295
+ return result;
296
+ }
297
+ };
298
+ };
299
+ export {
300
+ create,
301
+ createPrototype,
302
+ createRuntime,
303
+ link,
304
+ mergeState,
305
+ process,
306
+ relation,
307
+ remove,
308
+ structure,
309
+ transform,
310
+ unlink
311
+ };
312
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/structure.ts","../src/process.ts","../src/merge.ts","../src/prototype.ts","../src/runtime.ts"],"sourcesContent":["/**\n * Structure — the universal node of the system graph.\n *\n * Every node is a Structure:\n * - What it is (name + description)\n * - Where it lives (parent — tree backbone)\n * - What it carries (information — Gherkin Feature source)\n * - What it relates to (relations — cross-branch links)\n *\n * Tree (parent-child) provides the hierarchical backbone.\n * Relations provide cross-branch associations.\n * Together they form a graph.\n *\n * Type definitions have no ref (schema).\n * Runtime instances have ref (assigned by runtime).\n * Every node can carry information AND have children.\n *\n * Identifiers:\n * ref — graph engine internal reference (e.g., \"n3\", \"e5\"), assigned by runtime\n * id — user-facing kebab-case identifier (e.g., \"sean\", \"build-auth\")\n * alias — alternative names for lookup (e.g., [\"Sean\", \"姜山\"])\n */\n\n// ===== Relation =====\n\n/** Relation — a cross-branch link type between structures. */\nexport interface Relation {\n /** The relation name (e.g., \"appointment\"). */\n readonly name: string;\n\n /** What this relation means. */\n readonly description: string;\n\n /** The target structure type this relation points to. */\n readonly target: Structure;\n}\n\n// ===== Structure =====\n\nexport interface Structure {\n /** Graph engine internal reference (e.g., \"n3\", \"e5\"), assigned by runtime. */\n readonly ref?: string;\n\n /** User-facing kebab-case identifier (e.g., \"sean\", \"build-auth\"). */\n readonly id?: string;\n\n /** Alternative names for lookup (e.g., [\"Sean\", \"姜山\"]). */\n readonly alias?: readonly string[];\n\n /** The structure name (e.g., \"goal\", \"persona\", \"task\"). */\n readonly name: string;\n\n /** What this structure is. */\n readonly description: string;\n\n /** Parent structure. null = root of the graph. */\n readonly parent: Structure | null;\n\n /** Gherkin Feature source text. */\n readonly information?: string;\n\n /** Relations to other structure types (cross-branch links). */\n readonly relations?: readonly Relation[];\n}\n\n// ===== Constructors =====\n\n/**\n * relation — declare a cross-branch link type.\n */\nexport const relation = (name: string, description: string, target: Structure): Relation => ({\n name,\n description,\n target,\n});\n\n/**\n * structure — declare a type of node in the system graph.\n */\nexport const structure = (\n name: string,\n description: string,\n parent: Structure | null,\n relations?: Relation[]\n): Structure => ({\n name,\n description,\n parent,\n ...(relations ? { relations } : {}),\n});\n","/**\n * Process — how the system graph changes.\n *\n * Five graph primitives:\n * create — add a child node under a parent\n * remove — delete a node and its subtree\n * transform — harvest from one branch, produce in another\n * link — establish a cross-branch relation\n * unlink — remove a cross-branch relation\n *\n * Universal formula:\n * State = Process(Structure, Information?)\n */\nimport type { Structure } from \"./structure.js\";\n\n// ===== Graph Primitives =====\n\n/** create — add a new child node of a structure type. */\nexport interface Create {\n readonly op: \"create\";\n readonly structure: Structure;\n}\n\n/** remove — delete a node (and its subtree). */\nexport interface Remove {\n readonly op: \"remove\";\n readonly structure: Structure;\n}\n\n/** transform — harvest from one structure, produce another in a different branch. */\nexport interface Transform {\n readonly op: \"transform\";\n readonly from: Structure;\n readonly to: Structure;\n}\n\n/** link — establish a cross-branch relation. */\nexport interface Link {\n readonly op: \"link\";\n readonly structure: Structure;\n readonly relation: string;\n}\n\n/** unlink — remove a cross-branch relation. */\nexport interface Unlink {\n readonly op: \"unlink\";\n readonly structure: Structure;\n readonly relation: string;\n}\n\n/** A single graph operation. */\nexport type GraphOp = Create | Remove | Transform | Link | Unlink;\n\n// ===== Process =====\n\n/**\n * Process — a named composition of graph operations.\n *\n * Universal formula:\n * State = Process(Structure, Information?)\n */\nexport interface Process {\n /** The process name (e.g., \"want\", \"achieve\", \"reflect\"). */\n readonly name: string;\n\n /** What this process does. */\n readonly description: string;\n\n /** The structure type this process targets. */\n readonly target: Structure;\n\n /** The graph operations this process performs, in order. */\n readonly ops: readonly GraphOp[];\n}\n\n// ===== State =====\n\n/**\n * State — the projection of a node after a process executes.\n *\n * A State is a Structure snapshot with its subtree and links.\n */\nexport interface State extends Structure {\n /** Child states (subtree projection). */\n readonly children?: readonly State[];\n\n /** Cross-branch links from this node. */\n readonly links?: readonly { readonly relation: string; readonly target: State }[];\n\n /** Origin of this node in a merged projection: prototype (read-only) or instance (mutable). */\n readonly origin?: \"prototype\" | \"instance\";\n}\n\n// ===== Constructors =====\n\nexport const create = (structure: Structure): Create => ({ op: \"create\", structure });\n\nexport const remove = (structure: Structure): Remove => ({ op: \"remove\", structure });\n\nexport const transform = (from: Structure, to: Structure): Transform => ({\n op: \"transform\",\n from,\n to,\n});\n\nexport const link = (structure: Structure, relation: string): Link => ({\n op: \"link\",\n structure,\n relation,\n});\n\nexport const unlink = (structure: Structure, relation: string): Unlink => ({\n op: \"unlink\",\n structure,\n relation,\n});\n\nexport const process = (\n name: string,\n description: string,\n target: Structure,\n ...ops: GraphOp[]\n): Process => ({\n name,\n description,\n target,\n ops,\n});\n","/**\n * mergeState — union merge two State trees.\n *\n * Prototype mechanism: merge a base (prototype) with an overlay (instance).\n * Children are unioned, not overwritten. Links are unioned and deduplicated.\n *\n * Matching rules for children:\n * - Same name + same id (both defined) → recursive merge\n * - Same name + both no id + one each → recursive merge (structural singleton)\n * - Everything else → include from both sides\n */\nimport type { State } from \"./process.js\";\n\nexport const mergeState = (base: State, overlay: State): State => {\n const taggedBase = tagOrigin(base, \"prototype\");\n const taggedOverlay = tagOrigin(overlay, \"instance\");\n const mergedChildren = mergeChildren(taggedBase.children, taggedOverlay.children);\n const mergedLinks = mergeLinks(taggedBase.links, taggedOverlay.links);\n\n return {\n ...taggedBase,\n // overlay scalar properties take precedence when present\n ...(overlay.ref ? { ref: overlay.ref } : {}),\n ...(overlay.id ? { id: overlay.id } : {}),\n ...(overlay.information ? { information: overlay.information } : {}),\n ...(overlay.alias ? { alias: overlay.alias } : {}),\n ...(mergedChildren ? { children: mergedChildren } : {}),\n ...(mergedLinks ? { links: mergedLinks } : {}),\n // root node with overlay ref is instance\n origin: overlay.ref ? \"instance\" : \"prototype\",\n };\n};\n\n/** Tag all nodes in a state tree with an origin marker. */\nconst tagOrigin = (state: State, origin: \"prototype\" | \"instance\"): State => ({\n ...state,\n origin,\n ...(state.children ? { children: state.children.map((c) => tagOrigin(c, origin)) } : {}),\n});\n\nconst mergeChildren = (\n baseChildren?: readonly State[],\n overlayChildren?: readonly State[]\n): readonly State[] | undefined => {\n if (!baseChildren && !overlayChildren) return undefined;\n if (!baseChildren) return overlayChildren;\n if (!overlayChildren) return baseChildren;\n\n const result: State[] = [];\n\n // Group children by name\n const baseByName = groupByName(baseChildren);\n const overlayByName = groupByName(overlayChildren);\n const allNames = new Set([...baseByName.keys(), ...overlayByName.keys()]);\n\n for (const name of allNames) {\n const baseGroup = baseByName.get(name) ?? [];\n const overlayGroup = overlayByName.get(name) ?? [];\n\n if (baseGroup.length === 0) {\n result.push(...overlayGroup);\n continue;\n }\n if (overlayGroup.length === 0) {\n result.push(...baseGroup);\n continue;\n }\n\n // Match by id\n const matchedOverlay = new Set<number>();\n const unmatchedBase: State[] = [];\n\n for (const b of baseGroup) {\n if (b.id) {\n const oIdx = overlayGroup.findIndex((o, i) => !matchedOverlay.has(i) && o.id === b.id);\n if (oIdx >= 0) {\n result.push(mergeState(b, overlayGroup[oIdx]));\n matchedOverlay.add(oIdx);\n } else {\n unmatchedBase.push(b);\n }\n } else {\n unmatchedBase.push(b);\n }\n }\n\n const unmatchedOverlay = overlayGroup.filter((_, i) => !matchedOverlay.has(i));\n\n // Singleton merge: same name, no id, exactly one on each side\n const noIdBase = unmatchedBase.filter((s) => !s.id);\n const hasIdBase = unmatchedBase.filter((s) => s.id);\n const noIdOverlay = unmatchedOverlay.filter((s) => !s.id);\n const hasIdOverlay = unmatchedOverlay.filter((s) => s.id);\n\n if (noIdBase.length === 1 && noIdOverlay.length === 1) {\n result.push(mergeState(noIdBase[0], noIdOverlay[0]));\n } else {\n result.push(...noIdBase, ...noIdOverlay);\n }\n\n result.push(...hasIdBase, ...hasIdOverlay);\n }\n\n return result;\n};\n\nconst mergeLinks = (\n baseLinks?: State[\"links\"],\n overlayLinks?: State[\"links\"]\n): State[\"links\"] | undefined => {\n if (!baseLinks && !overlayLinks) return undefined;\n if (!baseLinks) return overlayLinks;\n if (!overlayLinks) return baseLinks;\n\n const seen = new Set<string>();\n const result: { readonly relation: string; readonly target: State }[] = [];\n\n for (const link of [...baseLinks, ...overlayLinks]) {\n const key = `${link.relation}:${link.target.id ?? link.target.ref ?? link.target.name}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push(link);\n }\n }\n\n return result;\n};\n\nconst groupByName = (states: readonly State[]): Map<string, State[]> => {\n const map = new Map<string, State[]>();\n for (const s of states) {\n const group = map.get(s.name);\n if (group) {\n group.push(s);\n } else {\n map.set(s.name, [s]);\n }\n }\n return map;\n};\n","/**\n * Prototype — a source of base State trees for merging.\n *\n * A prototype provides a pre-configured State tree (template) that gets\n * merged with an instance State via mergeState.\n *\n * Matching is by id: if prototype and instance share the same id,\n * they are the same entity — prototype provides the base,\n * instance provides the overlay.\n *\n * activate(id) = mergeState(prototype.resolve(id), runtime.project(id))\n */\nimport type { State } from \"./process.js\";\n\n// ===== Prototype interface =====\n\n/** A source that resolves prototype State trees by id. */\nexport interface Prototype {\n /** Resolve a prototype State by id. Returns undefined if no prototype exists. */\n resolve(id: string): Promise<State | undefined>;\n}\n\n// ===== In-memory implementation =====\n\n/** Create an in-memory prototype source. */\nexport const createPrototype = (): Prototype & {\n /** Register a State tree as a prototype (keyed by state.id). */\n register(state: State): void;\n} => {\n const prototypes = new Map<string, State>();\n\n return {\n async resolve(id) {\n return prototypes.get(id);\n },\n\n register(state) {\n if (!state.id) {\n throw new Error(\"Prototype state must have an id\");\n }\n prototypes.set(state.id, state);\n },\n };\n};\n","/**\n * Runtime — execution engine for the system graph.\n *\n * Six operations:\n * create — add a child node under a parent\n * remove — delete a node and its subtree\n * transform — produce from one branch into another\n * link — establish a cross-branch relation\n * unlink — remove a cross-branch relation\n * project — read the current state\n *\n * State = Process(Structure, Information?)\n */\n\nimport type { State } from \"./process.js\";\nimport type { Structure } from \"./structure.js\";\n\n// ===== Runtime interface =====\n\nexport interface Runtime {\n /** Create a child node (parent=null for root). Type is the structure template. */\n create(\n parent: Structure | null,\n type: Structure,\n information?: string,\n id?: string,\n alias?: readonly string[]\n ): Structure;\n\n /** Remove a node and its subtree. */\n remove(node: Structure): void;\n\n /** Produce a new node in target structure's branch, sourced from another branch. */\n transform(source: Structure, target: Structure, information?: string): Structure;\n\n /** Establish a bidirectional cross-branch relation between two nodes. */\n link(from: Structure, to: Structure, relation: string, reverse: string): void;\n\n /** Remove a bidirectional cross-branch relation between two nodes. */\n unlink(from: Structure, to: Structure, relation: string, reverse: string): void;\n\n /** Project the current state of a node and its subtree (including links). */\n project(node: Structure): State;\n\n /** Return all root nodes (nodes without a parent edge). */\n roots(): Structure[];\n}\n\n// ===== In-memory implementation =====\n\ninterface TreeNode {\n node: Structure;\n parent: string | null;\n children: string[];\n}\n\ninterface LinkEntry {\n toId: string;\n relation: string;\n}\n\nexport const createRuntime = (): Runtime => {\n const nodes = new Map<string, TreeNode>();\n const links = new Map<string, LinkEntry[]>();\n let counter = 0;\n const nextRef = () => `e${++counter}`;\n\n const findByStructure = (structure: Structure): TreeNode | undefined => {\n for (const treeNode of nodes.values()) {\n if (treeNode.node.name === structure.name) return treeNode;\n }\n return undefined;\n };\n\n const removeSubtree = (ref: string): void => {\n const treeNode = nodes.get(ref);\n if (!treeNode) return;\n for (const childRef of [...treeNode.children]) {\n removeSubtree(childRef);\n }\n // Clean up links from this node\n links.delete(ref);\n // Clean up links to this node\n for (const [fromRef, fromLinks] of links.entries()) {\n const filtered = fromLinks.filter((l) => l.toId !== ref);\n if (filtered.length === 0) {\n links.delete(fromRef);\n } else {\n links.set(fromRef, filtered);\n }\n }\n nodes.delete(ref);\n };\n\n const projectRef = (ref: string): State => {\n const treeNode = nodes.get(ref)!;\n return { ...treeNode.node, children: [] };\n };\n\n const projectNode = (ref: string): State => {\n const treeNode = nodes.get(ref)!;\n const nodeLinks = links.get(ref);\n return {\n ...treeNode.node,\n children: treeNode.children.map(projectNode),\n ...(nodeLinks && nodeLinks.length > 0\n ? {\n links: nodeLinks.map((l) => ({\n relation: l.relation,\n target: projectRef(l.toId),\n })),\n }\n : {}),\n };\n };\n\n const createNode = (\n parentRef: string | null,\n type: Structure,\n information?: string,\n id?: string,\n alias?: readonly string[]\n ): Structure => {\n const ref = nextRef();\n const node: Structure = {\n ref,\n ...(id ? { id } : {}),\n ...(alias && alias.length > 0 ? { alias } : {}),\n name: type.name,\n description: type.description,\n parent: type.parent,\n information,\n };\n const treeNode: TreeNode = { node, parent: parentRef, children: [] };\n nodes.set(ref, treeNode);\n\n if (parentRef) {\n const parentTreeNode = nodes.get(parentRef);\n if (!parentTreeNode) throw new Error(`Parent not found: ${parentRef}`);\n parentTreeNode.children.push(ref);\n }\n\n return node;\n };\n\n return {\n create(parent, type, information, id, alias) {\n return createNode(parent?.ref ?? null, type, information, id, alias);\n },\n\n remove(node) {\n if (!node.ref) return;\n const treeNode = nodes.get(node.ref);\n if (!treeNode) return;\n\n if (treeNode.parent) {\n const parentTreeNode = nodes.get(treeNode.parent);\n if (parentTreeNode) {\n parentTreeNode.children = parentTreeNode.children.filter((r) => r !== node.ref);\n }\n }\n\n removeSubtree(node.ref);\n },\n\n transform(_source, target, information) {\n const targetParent = target.parent;\n if (!targetParent) {\n throw new Error(`Cannot transform to root structure: ${target.name}`);\n }\n\n const parentTreeNode = findByStructure(targetParent);\n if (!parentTreeNode) {\n throw new Error(`No node found for structure: ${targetParent.name}`);\n }\n\n return createNode(parentTreeNode.node.ref!, target, information);\n },\n\n link(from, to, relationName, reverseName) {\n if (!from.ref) throw new Error(\"Source node has no ref\");\n if (!to.ref) throw new Error(\"Target node has no ref\");\n\n // Forward: from → to\n const fromLinks = links.get(from.ref) ?? [];\n if (!fromLinks.some((l) => l.toId === to.ref && l.relation === relationName)) {\n fromLinks.push({ toId: to.ref, relation: relationName });\n links.set(from.ref, fromLinks);\n }\n\n // Reverse: to → from\n const toLinks = links.get(to.ref) ?? [];\n if (!toLinks.some((l) => l.toId === from.ref && l.relation === reverseName)) {\n toLinks.push({ toId: from.ref, relation: reverseName });\n links.set(to.ref, toLinks);\n }\n },\n\n unlink(from, to, relationName, reverseName) {\n if (!from.ref || !to.ref) return;\n\n // Forward\n const fromLinks = links.get(from.ref);\n if (fromLinks) {\n const filtered = fromLinks.filter(\n (l) => !(l.toId === to.ref && l.relation === relationName)\n );\n if (filtered.length === 0) links.delete(from.ref);\n else links.set(from.ref, filtered);\n }\n\n // Reverse\n const toLinks = links.get(to.ref);\n if (toLinks) {\n const filtered = toLinks.filter(\n (l) => !(l.toId === from.ref && l.relation === reverseName)\n );\n if (filtered.length === 0) links.delete(to.ref);\n else links.set(to.ref, filtered);\n }\n },\n\n project(node) {\n if (!node.ref || !nodes.has(node.ref)) {\n throw new Error(`Node not found: ${node.ref}`);\n }\n return projectNode(node.ref);\n },\n\n roots() {\n const result: Structure[] = [];\n for (const treeNode of nodes.values()) {\n if (treeNode.parent === null) {\n result.push(treeNode.node);\n }\n }\n return result;\n },\n };\n};\n"],"mappings":";AAsEO,IAAM,WAAW,CAAC,MAAc,aAAqB,YAAiC;AAAA,EAC3F;AAAA,EACA;AAAA,EACA;AACF;AAKO,IAAM,YAAY,CACvB,MACA,aACA,QACA,eACe;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;AACnC;;;ACMO,IAAM,SAAS,CAACA,gBAAkC,EAAE,IAAI,UAAU,WAAAA,WAAU;AAE5E,IAAM,SAAS,CAACA,gBAAkC,EAAE,IAAI,UAAU,WAAAA,WAAU;AAE5E,IAAM,YAAY,CAAC,MAAiB,QAA8B;AAAA,EACvE,IAAI;AAAA,EACJ;AAAA,EACA;AACF;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AM,IAAI,KAAK,GAAG;AACpC,UAAI,WAAW;AACb,cAAM,WAAW,UAAU;AAAA,UACzB,CAAC,MAAM,EAAE,EAAE,SAAS,GAAG,OAAO,EAAE,aAAa;AAAA,QAC/C;AACA,YAAI,SAAS,WAAW,EAAG,OAAM,OAAO,KAAK,GAAG;AAAA,YAC3C,OAAM,IAAI,KAAK,KAAK,QAAQ;AAAA,MACnC;AAGA,YAAM,UAAU,MAAM,IAAI,GAAG,GAAG;AAChC,UAAI,SAAS;AACX,cAAM,WAAW,QAAQ;AAAA,UACvB,CAAC,MAAM,EAAE,EAAE,SAAS,KAAK,OAAO,EAAE,aAAa;AAAA,QACjD;AACA,YAAI,SAAS,WAAW,EAAG,OAAM,OAAO,GAAG,GAAG;AAAA,YACzC,OAAM,IAAI,GAAG,KAAK,QAAQ;AAAA,MACjC;AAAA,IACF;AAAA,IAEA,QAAQ,MAAM;AACZ,UAAI,CAAC,KAAK,OAAO,CAAC,MAAM,IAAI,KAAK,GAAG,GAAG;AACrC,cAAM,IAAI,MAAM,mBAAmB,KAAK,GAAG,EAAE;AAAA,MAC/C;AACA,aAAO,YAAY,KAAK,GAAG;AAAA,IAC7B;AAAA,IAEA,QAAQ;AACN,YAAM,SAAsB,CAAC;AAC7B,iBAAW,YAAY,MAAM,OAAO,GAAG;AACrC,YAAI,SAAS,WAAW,MAAM;AAC5B,iBAAO,KAAK,SAAS,IAAI;AAAA,QAC3B;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["structure","relation","link","structure"]}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@rolexjs/system",
3
+ "version": "0.1.0",
4
+ "description": "RoleX Systems Theory — six primitives + declarative process composition",
5
+ "keywords": [
6
+ "rolex",
7
+ "systems-theory",
8
+ "system",
9
+ "process",
10
+ "define"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/Deepractice/RoleX.git",
15
+ "directory": "packages/system"
16
+ },
17
+ "license": "MIT",
18
+ "engines": {
19
+ "node": ">=22.0.0"
20
+ },
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "bun": "./src/index.ts",
28
+ "default": "./dist/index.js"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "lint": "biome lint .",
37
+ "typecheck": "tsc --noEmit",
38
+ "clean": "rm -rf dist"
39
+ },
40
+ "dependencies": {},
41
+ "devDependencies": {},
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }