@claude-flow/cli 3.18.2 → 3.19.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.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Native training via @ruvector/ruvllm's TrainingPipeline (#2549 follow-up).
3
+ *
4
+ * `neural train` historically trained only on the RuVector WASM path
5
+ * (MicroLoRA + InfoNCE) and its "checkpoint" was a freshly-constructed
6
+ * adapter's weights — the native TrainingPipeline (real epochs, loss
7
+ * history, early stopping, EWC registration, disk checkpoints since
8
+ * ruvllm 2.5.7) was never exercised. This service routes the LoRA
9
+ * training leg through it.
10
+ *
11
+ * Batch formulation: pattern-alignment pairs — input = embedding[i],
12
+ * target = embedding[i+1 mod n], quality 1.0 — the MSE analogue of the
13
+ * WASM path's anchor→positive contrastive objective (adjacent training
14
+ * items belong to the same pattern family by construction).
15
+ *
16
+ * Graceful: returns null when @ruvector/ruvllm is absent or anything
17
+ * throws — callers fall back to the WASM path.
18
+ */
19
+ export interface NativeTrainingResult {
20
+ epochs: number;
21
+ steps: number;
22
+ finalLoss: number;
23
+ bestValLoss: number | null;
24
+ durationMs: number;
25
+ earlyStopped: boolean;
26
+ checkpointPath?: string;
27
+ checkpointBytes?: number;
28
+ }
29
+ export interface NativeTrainingOptions {
30
+ embeddings: Float32Array[];
31
+ epochs: number;
32
+ batchSize: number;
33
+ learningRate: number;
34
+ dim: number;
35
+ /** When set, the TRAINED pipeline checkpoints here (ruvllm >=2.5.7). */
36
+ checkpointPath?: string;
37
+ }
38
+ export declare function nativeTrainingAvailable(): boolean;
39
+ export declare function runNativeTraining(opts: NativeTrainingOptions): Promise<NativeTrainingResult | null>;
40
+ //# sourceMappingURL=native-training.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-training.d.ts","sourceRoot":"","sources":["../../../src/services/native-training.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,YAAY,EAAE,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAOjD;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA0DtC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Native training via @ruvector/ruvllm's TrainingPipeline (#2549 follow-up).
3
+ *
4
+ * `neural train` historically trained only on the RuVector WASM path
5
+ * (MicroLoRA + InfoNCE) and its "checkpoint" was a freshly-constructed
6
+ * adapter's weights — the native TrainingPipeline (real epochs, loss
7
+ * history, early stopping, EWC registration, disk checkpoints since
8
+ * ruvllm 2.5.7) was never exercised. This service routes the LoRA
9
+ * training leg through it.
10
+ *
11
+ * Batch formulation: pattern-alignment pairs — input = embedding[i],
12
+ * target = embedding[i+1 mod n], quality 1.0 — the MSE analogue of the
13
+ * WASM path's anchor→positive contrastive objective (adjacent training
14
+ * items belong to the same pattern family by construction).
15
+ *
16
+ * Graceful: returns null when @ruvector/ruvllm is absent or anything
17
+ * throws — callers fall back to the WASM path.
18
+ */
19
+ import { createRequire } from 'module';
20
+ import { mkdirSync, existsSync } from 'fs';
21
+ import { dirname } from 'path';
22
+ export function nativeTrainingAvailable() {
23
+ try {
24
+ createRequire(import.meta.url).resolve('@ruvector/ruvllm');
25
+ return true;
26
+ }
27
+ catch {
28
+ return false;
29
+ }
30
+ }
31
+ export async function runNativeTraining(opts) {
32
+ const { embeddings, epochs, batchSize, learningRate, dim, checkpointPath } = opts;
33
+ if (embeddings.length < 2)
34
+ return null;
35
+ try {
36
+ const req = createRequire(import.meta.url);
37
+ const ruvllm = req('@ruvector/ruvllm');
38
+ const pipeline = new ruvllm.TrainingPipeline({
39
+ learningRate,
40
+ batchSize,
41
+ epochs,
42
+ inputDim: dim,
43
+ outputDim: dim,
44
+ });
45
+ // Pattern-alignment pairs, chunked into pipeline batches.
46
+ const inputs = [];
47
+ const targets = [];
48
+ const qualities = [];
49
+ for (let i = 0; i < embeddings.length; i++) {
50
+ inputs.push(Array.from(embeddings[i]));
51
+ targets.push(Array.from(embeddings[(i + 1) % embeddings.length]));
52
+ qualities.push(1.0);
53
+ }
54
+ for (let i = 0; i < inputs.length; i += batchSize) {
55
+ pipeline.addBatch(inputs.slice(i, i + batchSize), targets.slice(i, i + batchSize), qualities.slice(i, i + batchSize));
56
+ }
57
+ const r = pipeline.train();
58
+ const result = {
59
+ epochs: r.epochs,
60
+ steps: r.steps,
61
+ finalLoss: r.finalLoss,
62
+ bestValLoss: r.bestValLoss ?? null,
63
+ durationMs: r.durationMs,
64
+ earlyStopped: !!r.earlyStopped,
65
+ };
66
+ if (checkpointPath) {
67
+ try {
68
+ mkdirSync(dirname(checkpointPath), { recursive: true });
69
+ const saved = pipeline.saveCheckpoint(checkpointPath);
70
+ // <2.5.7 returns undefined and writes nothing — verify on disk.
71
+ if (existsSync(checkpointPath)) {
72
+ result.checkpointPath = checkpointPath;
73
+ result.checkpointBytes = saved?.bytes;
74
+ }
75
+ }
76
+ catch { /* checkpoint is best-effort; training result stands */ }
77
+ }
78
+ return result;
79
+ }
80
+ catch {
81
+ return null;
82
+ }
83
+ }
84
+ //# sourceMappingURL=native-training.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