@seanhogg/builderforce-memory-engine 2026.9.34 → 2026.10.2
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/dist/evermind/delta_wire.d.ts +26 -2
- package/dist/evermind/delta_wire.d.ts.map +1 -1
- package/dist/evermind/delta_wire.js +46 -4
- package/dist/evermind/delta_wire.js.map +1 -1
- package/dist/evermind/index.d.ts +5 -5
- package/dist/evermind/index.d.ts.map +1 -1
- package/dist/evermind/index.js +2 -2
- package/dist/evermind/index.js.map +1 -1
- package/dist/evermind/merge.d.ts +28 -0
- package/dist/evermind/merge.d.ts.map +1 -1
- package/dist/evermind/merge.js +33 -0
- package/dist/evermind/merge.js.map +1 -1
- package/dist/evermind/ml_head.d.ts +28 -0
- package/dist/evermind/ml_head.d.ts.map +1 -0
- package/dist/evermind/ml_head.js +47 -0
- package/dist/evermind/ml_head.js.map +1 -0
- package/dist/evermind/package.d.ts +9 -0
- package/dist/evermind/package.d.ts.map +1 -1
- package/dist/evermind/package.js +20 -0
- package/dist/evermind/package.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/limbic/index.d.ts +3 -0
- package/dist/limbic/index.d.ts.map +1 -1
- package/dist/limbic/index.js +3 -0
- package/dist/limbic/index.js.map +1 -1
- package/dist/limbic/limbic_model.d.ts.map +1 -1
- package/dist/limbic/limbic_model.js +1 -3
- package/dist/limbic/limbic_model.js.map +1 -1
- package/dist/limbic/limbic_task.d.ts +22 -0
- package/dist/limbic/limbic_task.d.ts.map +1 -0
- package/dist/limbic/limbic_task.js +45 -0
- package/dist/limbic/limbic_task.js.map +1 -0
- package/dist/limbic/limbic_trainer.d.ts +17 -30
- package/dist/limbic/limbic_trainer.d.ts.map +1 -1
- package/dist/limbic/limbic_trainer.js +38 -144
- package/dist/limbic/limbic_trainer.js.map +1 -1
- package/dist/ml/classical/anomaly_composite.d.ts +32 -0
- package/dist/ml/classical/anomaly_composite.d.ts.map +1 -0
- package/dist/ml/classical/anomaly_composite.js +29 -0
- package/dist/ml/classical/anomaly_composite.js.map +1 -0
- package/dist/ml/classical/ewma.d.ts +37 -0
- package/dist/ml/classical/ewma.d.ts.map +1 -0
- package/dist/ml/classical/ewma.js +48 -0
- package/dist/ml/classical/ewma.js.map +1 -0
- package/dist/ml/classical/gbm.d.ts +42 -0
- package/dist/ml/classical/gbm.d.ts.map +1 -0
- package/dist/ml/classical/gbm.js +117 -0
- package/dist/ml/classical/gbm.js.map +1 -0
- package/dist/ml/classical/index.d.ts +52 -0
- package/dist/ml/classical/index.d.ts.map +1 -0
- package/dist/ml/classical/index.js +49 -0
- package/dist/ml/classical/index.js.map +1 -0
- package/dist/ml/classical/isolation_forest.d.ts +37 -0
- package/dist/ml/classical/isolation_forest.d.ts.map +1 -0
- package/dist/ml/classical/isolation_forest.js +72 -0
- package/dist/ml/classical/isolation_forest.js.map +1 -0
- package/dist/ml/classical/kmeans.d.ts +31 -0
- package/dist/ml/classical/kmeans.d.ts.map +1 -0
- package/dist/ml/classical/kmeans.js +112 -0
- package/dist/ml/classical/kmeans.js.map +1 -0
- package/dist/ml/classical/knn.d.ts +51 -0
- package/dist/ml/classical/knn.d.ts.map +1 -0
- package/dist/ml/classical/knn.js +69 -0
- package/dist/ml/classical/knn.js.map +1 -0
- package/dist/ml/classical/linear.d.ts +29 -0
- package/dist/ml/classical/linear.d.ts.map +1 -0
- package/dist/ml/classical/linear.js +114 -0
- package/dist/ml/classical/linear.js.map +1 -0
- package/dist/ml/classical/logistic.d.ts +31 -0
- package/dist/ml/classical/logistic.d.ts.map +1 -0
- package/dist/ml/classical/logistic.js +111 -0
- package/dist/ml/classical/logistic.js.map +1 -0
- package/dist/ml/classical/math.d.ts +26 -0
- package/dist/ml/classical/math.d.ts.map +1 -0
- package/dist/ml/classical/math.js +90 -0
- package/dist/ml/classical/math.js.map +1 -0
- package/dist/ml/classical/naive_bayes.d.ts +28 -0
- package/dist/ml/classical/naive_bayes.d.ts.map +1 -0
- package/dist/ml/classical/naive_bayes.js +72 -0
- package/dist/ml/classical/naive_bayes.js.map +1 -0
- package/dist/ml/classical/robust_z.d.ts +38 -0
- package/dist/ml/classical/robust_z.d.ts.map +1 -0
- package/dist/ml/classical/robust_z.js +47 -0
- package/dist/ml/classical/robust_z.js.map +1 -0
- package/dist/ml/dense_head.d.ts +33 -0
- package/dist/ml/dense_head.d.ts.map +1 -0
- package/dist/ml/dense_head.js +140 -0
- package/dist/ml/dense_head.js.map +1 -0
- package/dist/ml/eval_loss.d.ts +15 -0
- package/dist/ml/eval_loss.d.ts.map +1 -0
- package/dist/ml/eval_loss.js +20 -0
- package/dist/ml/eval_loss.js.map +1 -0
- package/dist/ml/features.d.ts +25 -0
- package/dist/ml/features.d.ts.map +1 -0
- package/dist/ml/features.js +46 -0
- package/dist/ml/features.js.map +1 -0
- package/dist/ml/federate.d.ts +56 -0
- package/dist/ml/federate.d.ts.map +1 -0
- package/dist/ml/federate.js +99 -0
- package/dist/ml/federate.js.map +1 -0
- package/dist/ml/head_trainer.d.ts +78 -0
- package/dist/ml/head_trainer.d.ts.map +1 -0
- package/dist/ml/head_trainer.js +182 -0
- package/dist/ml/head_trainer.js.map +1 -0
- package/dist/ml/index.d.ts +23 -0
- package/dist/ml/index.d.ts.map +1 -0
- package/dist/ml/index.js +11 -0
- package/dist/ml/index.js.map +1 -0
- package/dist/ml/registry.d.ts +20 -0
- package/dist/ml/registry.d.ts.map +1 -0
- package/dist/ml/registry.js +43 -0
- package/dist/ml/registry.js.map +1 -0
- package/dist/ml/run.d.ts +103 -0
- package/dist/ml/run.d.ts.map +1 -0
- package/dist/ml/run.js +169 -0
- package/dist/ml/run.js.map +1 -0
- package/dist/ml/tasks/experience.d.ts +127 -0
- package/dist/ml/tasks/experience.d.ts.map +1 -0
- package/dist/ml/tasks/experience.js +213 -0
- package/dist/ml/tasks/experience.js.map +1 -0
- package/dist/ml/tasks/index.d.ts +10 -0
- package/dist/ml/tasks/index.d.ts.map +1 -0
- package/dist/ml/tasks/index.js +28 -0
- package/dist/ml/tasks/index.js.map +1 -0
- package/dist/ml/tasks/local_success.d.ts +55 -0
- package/dist/ml/tasks/local_success.d.ts.map +1 -0
- package/dist/ml/tasks/local_success.js +77 -0
- package/dist/ml/tasks/local_success.js.map +1 -0
- package/dist/ml/tasks/run_anomaly.d.ts +52 -0
- package/dist/ml/tasks/run_anomaly.d.ts.map +1 -0
- package/dist/ml/tasks/run_anomaly.js +50 -0
- package/dist/ml/tasks/run_anomaly.js.map +1 -0
- package/dist/ml/train.d.ts +59 -0
- package/dist/ml/train.d.ts.map +1 -0
- package/dist/ml/train.js +84 -0
- package/dist/ml/train.js.map +1 -0
- package/dist/ml/types.d.ts +115 -0
- package/dist/ml/types.d.ts.map +1 -0
- package/dist/ml/types.js +24 -0
- package/dist/ml/types.js.map +1 -0
- package/dist/moe/moe_model.d.ts.map +1 -1
- package/dist/moe/moe_model.js +1 -16
- package/dist/moe/moe_model.js.map +1 -1
- package/dist/training/cpu_ops.d.ts +2 -0
- package/dist/training/cpu_ops.d.ts.map +1 -1
- package/dist/training/cpu_ops.js +16 -0
- package/dist/training/cpu_ops.js.map +1 -1
- package/package.json +1 -1
- package/src/evermind/delta_wire.ts +63 -4
- package/src/evermind/index.ts +7 -3
- package/src/evermind/merge.ts +59 -0
- package/src/evermind/ml_head.ts +63 -0
- package/src/evermind/package.ts +24 -0
- package/src/index.ts +17 -1
- package/src/limbic/index.ts +5 -0
- package/src/limbic/limbic_model.ts +1 -4
- package/src/limbic/limbic_task.ts +62 -0
- package/src/limbic/limbic_trainer.ts +41 -208
- package/src/ml/classical/anomaly_composite.ts +46 -0
- package/src/ml/classical/ewma.ts +74 -0
- package/src/ml/classical/gbm.ts +144 -0
- package/src/ml/classical/index.ts +82 -0
- package/src/ml/classical/isolation_forest.ts +88 -0
- package/src/ml/classical/kmeans.ts +120 -0
- package/src/ml/classical/knn.ts +102 -0
- package/src/ml/classical/linear.ts +119 -0
- package/src/ml/classical/logistic.ts +125 -0
- package/src/ml/classical/math.ts +93 -0
- package/src/ml/classical/naive_bayes.ts +84 -0
- package/src/ml/classical/robust_z.ts +74 -0
- package/src/ml/dense_head.ts +157 -0
- package/src/ml/eval_loss.ts +27 -0
- package/src/ml/features.ts +61 -0
- package/src/ml/federate.ts +130 -0
- package/src/ml/head_trainer.ts +247 -0
- package/src/ml/index.ts +57 -0
- package/src/ml/registry.ts +44 -0
- package/src/ml/run.ts +222 -0
- package/src/ml/tasks/experience.ts +293 -0
- package/src/ml/tasks/index.ts +30 -0
- package/src/ml/tasks/local_success.ts +118 -0
- package/src/ml/tasks/run_anomaly.ts +84 -0
- package/src/ml/train.ts +120 -0
- package/src/ml/types.ts +135 -0
- package/src/moe/moe_model.ts +1 -13
- package/src/training/cpu_ops.ts +14 -0
package/src/ml/types.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ml/types.ts — the ML task catalog contract (docs/ml-task-catalog.md §3).
|
|
3
|
+
*
|
|
4
|
+
* One bounded question Evermind answers without an LLM is ONE data row: how its
|
|
5
|
+
* input becomes a vector, which engines may answer it (in preference order), how
|
|
6
|
+
* it trains, and what its output means. Pure types — no vscode, no DOM, no network.
|
|
7
|
+
* (Imports only the leaf `evermind/ml_head.ts`; evermind/ never imports ml/.)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** The shape of the question. */
|
|
11
|
+
export type MlTaskKind = "classify" | "regress" | "cluster" | "anomaly" | "rank";
|
|
12
|
+
|
|
13
|
+
/** Pure-TypeScript algorithms that run everywhere (`ml/classical/`). */
|
|
14
|
+
export type ClassicalAlgorithm =
|
|
15
|
+
| "knn"
|
|
16
|
+
| "naive-bayes"
|
|
17
|
+
| "logistic"
|
|
18
|
+
| "linear"
|
|
19
|
+
| "kmeans"
|
|
20
|
+
| "robust-z"
|
|
21
|
+
| "ewma"
|
|
22
|
+
/** robust z + EWMA as one fitted engine (`classical/anomaly_composite.ts`). */
|
|
23
|
+
| "anomaly-composite"
|
|
24
|
+
| "isolation-forest"
|
|
25
|
+
| "gbm-small";
|
|
26
|
+
|
|
27
|
+
/** An engine that can answer a task. Cloud engines are a port the HOST supplies. */
|
|
28
|
+
export type MlEngineRef =
|
|
29
|
+
| { tier: "local"; engine: "classical"; algorithm: ClassicalAlgorithm }
|
|
30
|
+
| { tier: "local"; engine: "head"; head: "mlp" | "linear" }
|
|
31
|
+
| { tier: "local"; engine: "onnx"; model: string }
|
|
32
|
+
| { tier: "cloud"; engine: "workers-ai"; model: string };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Which engines a run may use — the person's inference setting.
|
|
36
|
+
* - `local-only`: local tiers only, never the network.
|
|
37
|
+
* - `hybrid`: local first, the cloud port when no local engine can answer (or the
|
|
38
|
+
* local answer is below the caller's confidence floor).
|
|
39
|
+
* - `specific`: exactly the engine the caller names.
|
|
40
|
+
*/
|
|
41
|
+
export type InferenceMode = "local-only" | "hybrid" | "specific";
|
|
42
|
+
|
|
43
|
+
/** What an engine returns before the task decodes it. */
|
|
44
|
+
export interface MlPrediction {
|
|
45
|
+
/**
|
|
46
|
+
* classify: one probability per label; regress: the predicted value(s);
|
|
47
|
+
* cluster: `[clusterId]`; anomaly: `[score]` where ≥ 1 is anomalous;
|
|
48
|
+
* rank: one score per candidate.
|
|
49
|
+
*/
|
|
50
|
+
scores: number[];
|
|
51
|
+
/** Calibrated confidence in [0, 1]. */
|
|
52
|
+
confidence: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** A fitted model that answers on a feature vector. */
|
|
56
|
+
export interface MlPredictor {
|
|
57
|
+
predict(x: Float32Array): MlPrediction;
|
|
58
|
+
/** Trainable state as one flat vector — present on models that federate. */
|
|
59
|
+
exportParams?(): Float32Array;
|
|
60
|
+
/** Load a flat vector produced by {@link exportParams} (e.g. after a merge). */
|
|
61
|
+
importParams?(params: ArrayLike<number>): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** How an input becomes a vector: an embedded text part, numeric fields, or both. */
|
|
65
|
+
export interface FeatureSpec<I> {
|
|
66
|
+
/** Text to embed (needs an embedder in the run context). */
|
|
67
|
+
text?: (input: I) => string;
|
|
68
|
+
/** Numeric fields, already on a stable scale (so federated weights mean the same thing everywhere). */
|
|
69
|
+
numeric?: (input: I) => number[];
|
|
70
|
+
/** Names of the numeric fields, index-aligned — documentation and Insights labels. */
|
|
71
|
+
numericNames?: readonly string[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One labelled training example in feature space. */
|
|
75
|
+
export interface MlSample {
|
|
76
|
+
x: Float32Array;
|
|
77
|
+
/** classify: class index; regress: target value; cluster/anomaly: ignored. */
|
|
78
|
+
y: number;
|
|
79
|
+
/** Sample weight (default 1). */
|
|
80
|
+
weight?: number;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** How a task trains. Absent on the task = rule-based or pre-trained only. */
|
|
84
|
+
export interface TrainSpec {
|
|
85
|
+
/** Fewer labelled examples than this and the task stays untrained. */
|
|
86
|
+
minSamples: number;
|
|
87
|
+
/** Fraction held out for the eval gate (default 0.2). */
|
|
88
|
+
holdoutFraction?: number;
|
|
89
|
+
/**
|
|
90
|
+
* A task-specific fit (e.g. a composite of two classical detectors). When absent
|
|
91
|
+
* the trainer fits the engine named by the run (`ml/train.ts`).
|
|
92
|
+
*/
|
|
93
|
+
fit?: (samples: readonly MlSample[], engine: MlEngineRef) => MlPredictor;
|
|
94
|
+
/** Who trains it when not `ml/train.ts` (e.g. `LimbicTrainer` for `limbic.affect`). */
|
|
95
|
+
trainedBy?: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** What a task's answer means. */
|
|
99
|
+
export interface OutputSpec<O> {
|
|
100
|
+
/** Label set for classify tasks (index-aligned with `MlPrediction.scores`). */
|
|
101
|
+
labels?: readonly string[];
|
|
102
|
+
/** Decode an engine prediction into the task's output. */
|
|
103
|
+
decode(p: MlPrediction): O;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** One bounded question Evermind can answer without an LLM. DATA, not a class tree. */
|
|
107
|
+
export interface MlTask<I = unknown, O = unknown> {
|
|
108
|
+
kind: MlTaskKind;
|
|
109
|
+
/** Stable id, e.g. `experience.quality`. */
|
|
110
|
+
id: string;
|
|
111
|
+
/** One line on what it answers. */
|
|
112
|
+
description: string;
|
|
113
|
+
features: FeatureSpec<I>;
|
|
114
|
+
/** In preference order; filtered by the inference mode. */
|
|
115
|
+
engines: readonly MlEngineRef[];
|
|
116
|
+
train?: TrainSpec;
|
|
117
|
+
output: OutputSpec<O>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Task ids: lowercase dotted segments — defined once with the artifact's head contract. */
|
|
121
|
+
export { ML_TASK_ID_RE } from "../evermind/ml_head.js";
|
|
122
|
+
|
|
123
|
+
/** A stable string key for an engine ref, e.g. `local:classical:logistic`. */
|
|
124
|
+
export function engineKey(ref: MlEngineRef): string {
|
|
125
|
+
switch (ref.engine) {
|
|
126
|
+
case "classical":
|
|
127
|
+
return `local:classical:${ref.algorithm}`;
|
|
128
|
+
case "head":
|
|
129
|
+
return `local:head:${ref.head}`;
|
|
130
|
+
case "onnx":
|
|
131
|
+
return `local:onnx:${ref.model}`;
|
|
132
|
+
case "workers-ai":
|
|
133
|
+
return `cloud:workers-ai:${ref.model}`;
|
|
134
|
+
}
|
|
135
|
+
}
|
package/src/moe/moe_model.ts
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
import { SeededRng } from "../utils/rng.js";
|
|
27
27
|
import { quantizeFp16, dequantizeFp16 } from "../utils/quantization.js";
|
|
28
|
+
import { softmax } from "../training/cpu_ops.js";
|
|
28
29
|
|
|
29
30
|
export interface MoEConfig {
|
|
30
31
|
/** Model (token) dimension — FFN input/output width. Default 64. */
|
|
@@ -462,16 +463,3 @@ export class SharedExpertMoE {
|
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
|
|
465
|
-
/** Numerically-stable softmax over a flat array. */
|
|
466
|
-
function softmax(logits: Float32Array): Float32Array {
|
|
467
|
-
let max = -Infinity;
|
|
468
|
-
for (let i = 0; i < logits.length; i++) if (logits[i]! > max) max = logits[i]!;
|
|
469
|
-
const out = new Float32Array(logits.length);
|
|
470
|
-
let sum = 0;
|
|
471
|
-
for (let i = 0; i < logits.length; i++) {
|
|
472
|
-
out[i] = Math.exp(logits[i]! - max);
|
|
473
|
-
sum += out[i]!;
|
|
474
|
-
}
|
|
475
|
-
for (let i = 0; i < logits.length; i++) out[i] = out[i]! / sum;
|
|
476
|
-
return out;
|
|
477
|
-
}
|
package/src/training/cpu_ops.ts
CHANGED
|
@@ -15,6 +15,20 @@ export function sigmoid(x: number): number {
|
|
|
15
15
|
return 1 / (1 + Math.exp(-x));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/** Numerically-stable softmax over a flat array. */
|
|
19
|
+
export function softmax(logits: ArrayLike<number>): Float32Array {
|
|
20
|
+
let max = -Infinity;
|
|
21
|
+
for (let i = 0; i < logits.length; i++) if (logits[i]! > max) max = logits[i]!;
|
|
22
|
+
const out = new Float32Array(logits.length);
|
|
23
|
+
let sum = 0;
|
|
24
|
+
for (let i = 0; i < logits.length; i++) {
|
|
25
|
+
out[i] = Math.exp(logits[i]! - max);
|
|
26
|
+
sum += out[i]!;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < logits.length; i++) out[i] = out[i]! / sum;
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
/** SiLU(x) = x * sigmoid(x) — mirrors `silu_forward`. */
|
|
19
33
|
export function silu(x: number): number {
|
|
20
34
|
return x / (1 + Math.exp(-x));
|