skynet-graph 1.2.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.
Files changed (213) hide show
  1. package/CONTRIBUTING.md +22 -0
  2. package/LICENSE +661 -0
  3. package/README.md +245 -0
  4. package/bin/sg +20 -0
  5. package/concepts/README.md +23 -0
  6. package/concepts/_substrate/Claim/Confidence/Trusted.json +6 -0
  7. package/concepts/_substrate/Claim/Confidence.json +10 -0
  8. package/concepts/_substrate/Claim/Freshness/Stale.json +7 -0
  9. package/concepts/_substrate/Claim/Freshness.json +5 -0
  10. package/concepts/_substrate/Claim/Verification/Refuted.json +6 -0
  11. package/concepts/_substrate/Claim/Verification.json +6 -0
  12. package/concepts/_substrate/Claim.json +4 -0
  13. package/concepts/_substrate/Frontier/InBeam.json +6 -0
  14. package/concepts/_substrate/Frontier/Stuck.json +6 -0
  15. package/concepts/_substrate/Frontier.json +5 -0
  16. package/concepts/_substrate/Intake/ToTask.json +22 -0
  17. package/concepts/_substrate/Intake/Typed.json +10 -0
  18. package/concepts/_substrate/Intake.json +27 -0
  19. package/concepts/_substrate/Task/Answer.json +12 -0
  20. package/concepts/_substrate/Task/Complexity/Atomic.json +5 -0
  21. package/concepts/_substrate/Task/Complexity/Compound/Expansion.json +7 -0
  22. package/concepts/_substrate/Task/Complexity/Compound.json +6 -0
  23. package/concepts/_substrate/Task/Complexity.json +6 -0
  24. package/concepts/_substrate/Task/EvalComplexity.json +13 -0
  25. package/concepts/_substrate/Task/ReportUp.json +6 -0
  26. package/concepts/_substrate/Task/Rollup.json +10 -0
  27. package/concepts/_substrate/Task.json +5 -0
  28. package/concepts/clinical/Diagnosis/Medication.json +6 -0
  29. package/concepts/clinical/Diagnosis.json +15 -0
  30. package/concepts/clinical/Observation/LabValue/OutOfRange.json +6 -0
  31. package/concepts/clinical/Observation/LabValue.json +5 -0
  32. package/concepts/clinical/Observation.json +6 -0
  33. package/concepts/common/Document/pathBasket.json +6 -0
  34. package/concepts/common/Document.json +3 -0
  35. package/concepts/common/Edge/Distance.json +13 -0
  36. package/concepts/common/Edge/Stay/LongStay.json +8 -0
  37. package/concepts/common/Edge/Stay.json +8 -0
  38. package/concepts/common/Edge/Travel/LongTravel.json +16 -0
  39. package/concepts/common/Edge/Travel/ShortTravel.json +11 -0
  40. package/concepts/common/Edge/Travel/targetNode.json +7 -0
  41. package/concepts/common/Edge/Travel.json +7 -0
  42. package/concepts/common/Edge.json +3 -0
  43. package/concepts/common/Vertice.json +3 -0
  44. package/concepts/supply/Fulfillment.json +10 -0
  45. package/concepts/supply/Inventory/Reorder.json +7 -0
  46. package/concepts/supply/Inventory.json +5 -0
  47. package/concepts/supply/Procurement/SupplierConfirm.json +6 -0
  48. package/concepts/supply/Procurement.json +8 -0
  49. package/concepts/supply/Transport.json +5 -0
  50. package/doc/API.md +556 -0
  51. package/doc/CAPABILITIES.md +373 -0
  52. package/doc/MODELISATION.md +511 -0
  53. package/doc/architecture.md +267 -0
  54. package/doc/concept-as-graph.md +379 -0
  55. package/doc/concept-learning.md +168 -0
  56. package/doc/creative-loop-map.md +202 -0
  57. package/doc/original-2016-doc.md +148 -0
  58. package/doc/usage.md +501 -0
  59. package/lib/authoring/abstract.js +401 -0
  60. package/lib/authoring/abstraction.js +190 -0
  61. package/lib/authoring/adapt.js +393 -0
  62. package/lib/authoring/ancestry.js +216 -0
  63. package/lib/authoring/author.js +147 -0
  64. package/lib/authoring/bounded-merge.js +57 -0
  65. package/lib/authoring/canon.js +158 -0
  66. package/lib/authoring/clock.js +123 -0
  67. package/lib/authoring/combinator.js +92 -0
  68. package/lib/authoring/compete.js +76 -0
  69. package/lib/authoring/compose-hotspot.js +314 -0
  70. package/lib/authoring/compress.js +279 -0
  71. package/lib/authoring/concept-net.js +254 -0
  72. package/lib/authoring/concepts.js +66 -0
  73. package/lib/authoring/context-project.js +277 -0
  74. package/lib/authoring/contract.js +476 -0
  75. package/lib/authoring/corpus-pack.js +125 -0
  76. package/lib/authoring/cost-probe.js +86 -0
  77. package/lib/authoring/crystallize.js +555 -0
  78. package/lib/authoring/dag-decompose.js +256 -0
  79. package/lib/authoring/dataset-adapter.js +253 -0
  80. package/lib/authoring/debug-provider.js +92 -0
  81. package/lib/authoring/decompose.js +343 -0
  82. package/lib/authoring/emittability.js +236 -0
  83. package/lib/authoring/equilibrium.js +160 -0
  84. package/lib/authoring/extract.js +153 -0
  85. package/lib/authoring/forest.js +55 -0
  86. package/lib/authoring/forge-fallback.js +116 -0
  87. package/lib/authoring/givens.js +121 -0
  88. package/lib/authoring/glossary.js +177 -0
  89. package/lib/authoring/grammar-graph.js +191 -0
  90. package/lib/authoring/granularity.js +80 -0
  91. package/lib/authoring/graph-net.js +108 -0
  92. package/lib/authoring/ground.js +148 -0
  93. package/lib/authoring/higher-order.js +85 -0
  94. package/lib/authoring/hotspot.js +132 -0
  95. package/lib/authoring/hysteresis.js +85 -0
  96. package/lib/authoring/index.js +106 -0
  97. package/lib/authoring/lattice-morphism.js +61 -0
  98. package/lib/authoring/lattice-pack.js +148 -0
  99. package/lib/authoring/leaf-io.js +77 -0
  100. package/lib/authoring/library.js +156 -0
  101. package/lib/authoring/lifecycle.js +92 -0
  102. package/lib/authoring/loop.js +193 -0
  103. package/lib/authoring/master-loop.js +132 -0
  104. package/lib/authoring/mdl.js +209 -0
  105. package/lib/authoring/memo-stability.js +122 -0
  106. package/lib/authoring/method-explorer.js +138 -0
  107. package/lib/authoring/method-pack.js +181 -0
  108. package/lib/authoring/method.js +202 -0
  109. package/lib/authoring/mine.js +510 -0
  110. package/lib/authoring/mount.js +119 -0
  111. package/lib/authoring/negotiate.js +100 -0
  112. package/lib/authoring/parametric.js +139 -0
  113. package/lib/authoring/reaggregate.js +75 -0
  114. package/lib/authoring/rebalance.js +157 -0
  115. package/lib/authoring/recall.js +135 -0
  116. package/lib/authoring/registry.js +350 -0
  117. package/lib/authoring/relearn.js +147 -0
  118. package/lib/authoring/retention.js +89 -0
  119. package/lib/authoring/segment-proxy.js +114 -0
  120. package/lib/authoring/serve-leaf.js +64 -0
  121. package/lib/authoring/slot-aware-serve.js +77 -0
  122. package/lib/authoring/sound-invoke.js +59 -0
  123. package/lib/authoring/split-serve.js +74 -0
  124. package/lib/authoring/ste.js +239 -0
  125. package/lib/authoring/stock.js +101 -0
  126. package/lib/authoring/store.js +94 -0
  127. package/lib/authoring/supervise.js +138 -0
  128. package/lib/authoring/support.js +131 -0
  129. package/lib/authoring/task-mirror.js +51 -0
  130. package/lib/authoring/typed-loop.js +160 -0
  131. package/lib/authoring/validate.js +569 -0
  132. package/lib/authoring/widen.js +88 -0
  133. package/lib/combos/appliance.js +189 -0
  134. package/lib/combos/critique.js +377 -0
  135. package/lib/combos/defaults.js +86 -0
  136. package/lib/combos/durable-runner.js +115 -0
  137. package/lib/combos/forge.js +209 -0
  138. package/lib/combos/index.js +86 -0
  139. package/lib/combos/learning-library.js +253 -0
  140. package/lib/combos/mixture-serve.js +193 -0
  141. package/lib/combos/plan-loop.js +192 -0
  142. package/lib/combos/proxy-cache.js +272 -0
  143. package/lib/combos/self-mod.js +94 -0
  144. package/lib/durable/audit.js +102 -0
  145. package/lib/durable/checkpoint-store.js +550 -0
  146. package/lib/durable/fold.js +62 -0
  147. package/lib/durable/interpreter.js +242 -0
  148. package/lib/durable/xlate.js +185 -0
  149. package/lib/graph/Graph.js +2486 -0
  150. package/lib/graph/expr.js +307 -0
  151. package/lib/graph/index.js +26 -0
  152. package/lib/graph/log.js +134 -0
  153. package/lib/graph/objects/Concept.js +382 -0
  154. package/lib/graph/objects/Entity.js +503 -0
  155. package/lib/graph/objects/Node.js +57 -0
  156. package/lib/graph/objects/PathMap.js +557 -0
  157. package/lib/graph/objects/Segment.js +100 -0
  158. package/lib/graph/tasks/stabilize.js +59 -0
  159. package/lib/graph/tasks/taskflow.js +247 -0
  160. package/lib/index.js +122 -0
  161. package/lib/load.js +132 -0
  162. package/lib/providers/backends.js +117 -0
  163. package/lib/providers/borderline.js +129 -0
  164. package/lib/providers/cache.js +226 -0
  165. package/lib/providers/canonicalize.js +198 -0
  166. package/lib/providers/constat.js +107 -0
  167. package/lib/providers/geo.js +53 -0
  168. package/lib/providers/index.js +116 -0
  169. package/lib/providers/intake.js +263 -0
  170. package/lib/providers/llm-local.js +88 -0
  171. package/lib/providers/llm.js +236 -0
  172. package/lib/providers/local-host.js +197 -0
  173. package/lib/providers/merge-consistency.js +162 -0
  174. package/lib/providers/nogood.js +149 -0
  175. package/lib/providers/reason-loop.js +223 -0
  176. package/lib/providers/semiring.js +285 -0
  177. package/lib/providers/solver-fork.js +163 -0
  178. package/lib/providers/stats.js +228 -0
  179. package/lib/providers/verify.js +120 -0
  180. package/lib/runtime/index.js +135 -0
  181. package/lib/runtime/invoke-pool.js +92 -0
  182. package/lib/runtime/protocol.js +210 -0
  183. package/lib/runtime/transport-socket.js +77 -0
  184. package/lib/runtime/worker-entry.js +31 -0
  185. package/lib/sg/cli.js +601 -0
  186. package/lib/sg/log-sinks.js +214 -0
  187. package/lib/sg/mcp.js +395 -0
  188. package/lib/sg/proxy-run.js +66 -0
  189. package/lib/sg/serve-demo.js +185 -0
  190. package/lib/sg/serve.js +205 -0
  191. package/lib/sg/trace.js +118 -0
  192. package/lib/studio/protocol.js +45 -0
  193. package/lib/studio/public/app.js +310 -0
  194. package/lib/studio/public/components/ConceptEditor.js +43 -0
  195. package/lib/studio/public/components/ConceptTree.js +43 -0
  196. package/lib/studio/public/components/CorpusPanel.js +68 -0
  197. package/lib/studio/public/components/ForkTree.js +36 -0
  198. package/lib/studio/public/components/GrammarGraph.js +99 -0
  199. package/lib/studio/public/components/GraphCanvas.js +156 -0
  200. package/lib/studio/public/components/Inspector.js +48 -0
  201. package/lib/studio/public/components/LearningPanel.js +85 -0
  202. package/lib/studio/public/components/PromptConsole.js +46 -0
  203. package/lib/studio/public/components/ProviderTrace.js +39 -0
  204. package/lib/studio/public/components/SessionSplit.js +47 -0
  205. package/lib/studio/public/components/TilingOverlay.js +40 -0
  206. package/lib/studio/public/components/Timeline.js +57 -0
  207. package/lib/studio/public/index.html +26 -0
  208. package/lib/studio/public/styles.css +185 -0
  209. package/lib/studio/public/ws.js +58 -0
  210. package/lib/studio/server.js +130 -0
  211. package/lib/studio/session.js +397 -0
  212. package/lib/studio/studio.js +149 -0
  213. package/package.json +42 -0
@@ -0,0 +1,160 @@
1
+ /*
2
+ * Copyright 2026 Nathanael Braun
3
+ * @author : Nathanael BRAUN <pp9ping@gmail.com>
4
+ *
5
+ * AGPL-3.0-or-later. See <https://www.gnu.org/licenses/>.
6
+ */
7
+ 'use strict';
8
+ /**
9
+ * typed-loop — the fused RECURSIVE TYPED decompose operator (ZERO-CORE, host-side).
10
+ *
11
+ * `loop.js#makeDecomposeProviders` gives the emergent-depth decompose loop (the MODEL decides atomic-vs-split,
12
+ * depth-floored), but its trace is NOT K1-crystallizable/mountable, for THREE confronted reasons (the cont.⁷ #1
13
+ * finding + the 2026-07-02 Laurie confront, verdicts A+B — each reproduced live by `probe-mount-elision.js`):
14
+ * 1. its expand writes PROSE on the children (`label`/`description`) → same typed premise, varying patch →
15
+ * `signatureDetermined` falls → not crystallizable;
16
+ * 2. the children's `EvalComplexity`/`Atomic` verdicts are OTHER casts, so a mined replay template (the
17
+ * per-cast patch) mounts children WITHOUT their self-flags → the providers re-fire on the mounted subtree
18
+ * (Entity.js:165 — the self-flag is the only re-fire guard, #33) → a mount elides NOTHING and can diverge;
19
+ * 3. the structure-discriminating kind is written DATA, on no concept's require/assert → it never reaches the
20
+ * memo surface (`memoSurfaceKeys`) → `premiseOf` can't capture it → one constant signature for all
21
+ * structures → `signature-insufficient` refusal on any heterogeneous corpus.
22
+ *
23
+ * The fused operator fixes all three:
24
+ * - TYPED steps: each child carries `stepKind` — canon-snapped onto a CLOSED enum (`canonValue`: exact +
25
+ * case/ws-normalized + curated ring, FAIL-CLOSED — an out-of-vocab kind never mints a typed fact; it rides
26
+ * `StepKindMiss:true` + the raw surface on the untracked `stepKindRaw`) + `stepIndex`; the created MID node
27
+ * carries the typed `state:'plan-<kind>'`; prose stays on UNTRACKED keys (`TYPED_PROSE_KEYS` → `proseKeys`).
28
+ * - STAMPED eval verdicts (Laurie A): the model decides split-vs-atomic PER STEP at expand time, so the child
29
+ * is born `EvalComplexity:true` + (`Atomic:true` | `NeedsSplit:true`) IN THE SAME PATCH — the mined template
30
+ * carries the re-fire guards, `blendAtSegment` merges them through composites, and a mounted structure
31
+ * actually elides the calls. A step defaults to atomic (`atomic !== false`); the depth floor forces Atomic.
32
+ * A NeedsSplit child whose kind MISSED cannot expand (no typed key) — fail-closed, it escalates to the host.
33
+ * - SIGNATURE-CARRYING requires (Laurie B): `typedLoopConceptTree({ sigKey })` puts the discriminating typed
34
+ * key (default `stepKind`) into Expand's `require`, so the firing premise captures its VALUE and
35
+ * `signatureKeys` discriminate per class. The ROOT task carries the same key from intake.
36
+ *
37
+ * expandFn(scope) -> [{ stepKind, atomic?, name?, description? }, ...]
38
+ */
39
+ const { makeDecomposeProviders, synthesize } = require('./loop.js');
40
+ const { canonValue } = require('../providers/canonicalize.js');
41
+ const { instantiate } = require('./abstract.js');
42
+
43
+ /** Every untracked prose key the operator writes — the crystallizer contract (pass as `proseKeys`). */
44
+ const TYPED_PROSE_KEYS = ['label', 'description', 'answer', 'stepKindRaw'];
45
+
46
+ /** The decompose concept tree with the discriminating typed key IN Expand's require (Laurie B). */
47
+ function typedLoopConceptTree( opts ) {
48
+ opts = opts || {};
49
+ var sigKey = opts.sigKey || 'stepKind',
50
+ t = {
51
+ childConcepts: {
52
+ Task: {
53
+ _id: 'Task', _name: 'Task', require: 'Segment',
54
+ childConcepts: {
55
+ EvalComplexity: { _id: 'EvalComplexity', _name: 'EvalComplexity', require: ['Task'], provider: ['AI::evalComplexity'] },
56
+ Expand : { _id: 'Expand', _name: 'Expand', require: ['Task', 'NeedsSplit', sigKey], provider: ['AI::expand'] },
57
+ Answer : { _id: 'Answer', _name: 'Answer', require: ['Task', 'Atomic'], provider: ['AI::answer'] }
58
+ }
59
+ }
60
+ }
61
+ };
62
+ if ( opts.reactive )
63
+ Object.assign(t.childConcepts.Task.childConcepts, {
64
+ ReportUp: { _id: 'ReportUp', _name: 'ReportUp', require: ['Task', 'Answered', 'parentSeg'], provider: ['AI::reportUp'] },
65
+ Rollup : { _id: 'Rollup', _name: 'Rollup', require: ['Task', 'expandedInto'], ensure: ['$answeredBy.length == $expandedInto.length'], provider: ['AI::rollup'] }
66
+ });
67
+ return t;
68
+ }
69
+
70
+ function makeTypedDecomposeProviders( opts ) {
71
+ opts = opts || {};
72
+ var spec = Array.isArray(opts.stepKinds) ? { enum: opts.stepKinds } : (opts.stepKinds || { enum: [] }),
73
+ maxDepth = opts.maxDepth == null ? 2 : opts.maxDepth,
74
+ maxBranch = opts.maxBranch || 4,
75
+ expandFn = opts.expandFn || function () { return []; },
76
+ stepFacts = opts.stepFacts || [], // TYPED per-step content keys the expand may emit
77
+ base = makeDecomposeProviders(opts); // eval/answer/rollup/reportUp inherited verbatim
78
+
79
+ base.AI.expand = function ( graph, concept, scope, argz, cb ) {
80
+ Promise.resolve(expandFn(scope)).then(function ( raw ) {
81
+ var steps = (raw || []).slice(0, maxBranch);
82
+ if ( !steps.length ) return cb(null, { $_id: '_parent', Expand: true, Atomic: true });// nothing to split -> leaf
83
+ var baseId = scope._._id,
84
+ origin = scope._.originNode,
85
+ target = scope._.targetNode,
86
+ depth = (scope._.depth || 0) + 1,
87
+ floored = depth >= maxDepth,
88
+ childIds = steps.map(function ( _, i ) { return baseId + '_s' + i; }),
89
+ tpl = [{ $_id: '_parent', Expand: true, expandedInto: childIds }],
90
+ prev = origin;
91
+ steps.forEach(function ( st, i ) {
92
+ var last = i === steps.length - 1,
93
+ tnode = last ? target : baseId + '_m' + i,
94
+ snap = canonValue(st.stepKind, spec),
95
+ child = {
96
+ _id: childIds[i], Segment: true, originNode: prev, targetNode: tnode,
97
+ depth: depth, parentSeg: baseId, stepIndex: i,
98
+ label: st.name, description: st.description,
99
+ // the STAMPED verdict (Laurie A): the model decided split-vs-atomic for this step NOW,
100
+ // so the guard is part of THIS patch and a mounted replay cannot re-fire the providers.
101
+ EvalComplexity: true
102
+ };
103
+ if ( floored || st.atomic !== false ) child.Atomic = true; else child.NeedsSplit = true;
104
+ if ( snap.miss ) { child.StepKindMiss = true; child.stepKindRaw = String(st.stepKind); }
105
+ else { child.stepKind = snap.value; if ( snap.via ) child.stepVia = snap.via; }
106
+ // declared TYPED per-step content facts (a placed param, e.g. `group`) ride the child — the trace
107
+ // grain the LGG holes into SLOTS ("under-qualified = abstract = a slot"); NEVER prose, whitelist-only.
108
+ for ( var fi = 0; fi < stepFacts.length; fi++ )
109
+ if ( st[stepFacts[fi]] !== undefined ) child[stepFacts[fi]] = st[stepFacts[fi]];
110
+ // the created MID node carries the typed plan-state (never the external target — frontier untouched);
111
+ // a miss mints NO typed state (fail-closed on the node too).
112
+ if ( !last ) tpl.push(snap.miss ? { _id: tnode, Node: true } : { _id: tnode, Node: true, state: 'plan-' + snap.value });
113
+ tpl.push(child);
114
+ prev = tnode;
115
+ });
116
+ cb(null, tpl);
117
+ }).catch(function ( e ) { cb(null, { $_id: '_parent', Expand: true, Atomic: true, llmError: e.message }); });
118
+ };
119
+ return base;
120
+ }
121
+
122
+ /**
123
+ * Ground a crystallized/composed template for DIRECT mounting on a task segment (the arm's dispatch-mount —
124
+ * a MUTATION, never a racing concept): instantiate holes onto the site, rebase the `$_id:'_parent'` entries
125
+ * onto the root id, and stamp the root's own eval verdict (the mount decision subsumes EvalComplexity — the
126
+ * root eval call is elided too). Returns null if a frontier ref is unbound (never a partial mount).
127
+ *
128
+ * ATOMICITY (the boot race): a live graph stabilizes as soon as the task segment exists — a mount pushed
129
+ * AFTER the segment is seeded races the decompose providers (they fire before the mount lands and the spend
130
+ * is NOT elided). So a mount-hit task must be created WITH its mounted structure in ONE mutation:
131
+ * `site.create` makes the rebased `_parent` entry CREATE the task segment (Segment + frontier + site.facts)
132
+ * instead of updating an existing one.
133
+ * @param tpl candidate.templatesBySig[sig] (relativized)
134
+ * @param site { rootId, origin, target, base?, create?, facts? } base defaults to rootId (fresh id-space);
135
+ * facts = the task's typed facts (e.g. the sig key) when creating.
136
+ */
137
+ function mountTemplate( tpl, site ) {
138
+ var ground = instantiate(tpl, { base: site.base || site.rootId, refs: { origin: site.origin, target: site.target } });
139
+ if ( !ground ) return null;
140
+ var out = (Array.isArray(ground) ? ground : [ground]).map(function ( o ) {
141
+ if ( o && o.$_id === '_parent' ) {
142
+ var r = Object.assign({}, o, { EvalComplexity: true, NeedsSplit: true });
143
+ delete r.$_id;
144
+ if ( site.create )
145
+ Object.assign(r, { _id: site.rootId, Segment: true, originNode: site.origin, targetNode: site.target }, site.facts || {});
146
+ else r.$$_id = site.rootId;
147
+ return r;
148
+ }
149
+ return o;
150
+ });
151
+ return out;
152
+ }
153
+
154
+ module.exports = {
155
+ makeTypedDecomposeProviders: makeTypedDecomposeProviders,
156
+ typedLoopConceptTree : typedLoopConceptTree,
157
+ mountTemplate : mountTemplate,
158
+ TYPED_PROSE_KEYS : TYPED_PROSE_KEYS,
159
+ synthesize : synthesize
160
+ };