@claude-flow/cli 3.19.0 → 3.21.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 (76) hide show
  1. package/dist/src/agenticow/speculative-exploration.d.ts +148 -0
  2. package/dist/src/agenticow/speculative-exploration.d.ts.map +1 -0
  3. package/dist/src/agenticow/speculative-exploration.js +218 -0
  4. package/dist/src/agenticow/speculative-exploration.js.map +1 -0
  5. package/dist/src/commands/autopilot.d.ts.map +1 -1
  6. package/dist/src/commands/autopilot.js +45 -0
  7. package/dist/src/commands/autopilot.js.map +1 -1
  8. package/dist/src/commands/neural.d.ts.map +1 -1
  9. package/dist/src/commands/neural.js +366 -12
  10. package/dist/src/commands/neural.js.map +1 -1
  11. package/dist/src/mcp-client.d.ts.map +1 -1
  12. package/dist/src/mcp-client.js +6 -1
  13. package/dist/src/mcp-client.js.map +1 -1
  14. package/dist/src/mcp-tools/agent-execute-core.d.ts.map +1 -1
  15. package/dist/src/mcp-tools/agent-execute-core.js +33 -0
  16. package/dist/src/mcp-tools/agent-execute-core.js.map +1 -1
  17. package/dist/src/mcp-tools/agent-tools.d.ts.map +1 -1
  18. package/dist/src/mcp-tools/agent-tools.js +47 -1
  19. package/dist/src/mcp-tools/agent-tools.js.map +1 -1
  20. package/dist/src/mcp-tools/agenticow-loader.d.ts +59 -0
  21. package/dist/src/mcp-tools/agenticow-loader.d.ts.map +1 -0
  22. package/dist/src/mcp-tools/agenticow-loader.js +105 -0
  23. package/dist/src/mcp-tools/agenticow-loader.js.map +1 -0
  24. package/dist/src/mcp-tools/agenticow-speculate-tools.d.ts +24 -0
  25. package/dist/src/mcp-tools/agenticow-speculate-tools.d.ts.map +1 -0
  26. package/dist/src/mcp-tools/agenticow-speculate-tools.js +202 -0
  27. package/dist/src/mcp-tools/agenticow-speculate-tools.js.map +1 -0
  28. package/dist/src/mcp-tools/agenticow-tools.d.ts.map +1 -1
  29. package/dist/src/mcp-tools/agenticow-tools.js +186 -79
  30. package/dist/src/mcp-tools/agenticow-tools.js.map +1 -1
  31. package/dist/src/mcp-tools/index.d.ts +1 -0
  32. package/dist/src/mcp-tools/index.d.ts.map +1 -1
  33. package/dist/src/mcp-tools/index.js +2 -0
  34. package/dist/src/mcp-tools/index.js.map +1 -1
  35. package/dist/src/ruvector/index.d.ts +1 -1
  36. package/dist/src/ruvector/index.d.ts.map +1 -1
  37. package/dist/src/ruvector/index.js +1 -1
  38. package/dist/src/ruvector/index.js.map +1 -1
  39. package/dist/src/ruvector/lora-adapter.d.ts +35 -0
  40. package/dist/src/ruvector/lora-adapter.d.ts.map +1 -1
  41. package/dist/src/ruvector/lora-adapter.js +108 -1
  42. package/dist/src/ruvector/lora-adapter.js.map +1 -1
  43. package/dist/src/ruvector/router-trajectory.d.ts +33 -0
  44. package/dist/src/ruvector/router-trajectory.d.ts.map +1 -1
  45. package/dist/src/ruvector/router-trajectory.js +31 -0
  46. package/dist/src/ruvector/router-trajectory.js.map +1 -1
  47. package/dist/src/ruvector/run-transcript-recorder.d.ts +154 -0
  48. package/dist/src/ruvector/run-transcript-recorder.d.ts.map +1 -0
  49. package/dist/src/ruvector/run-transcript-recorder.js +209 -0
  50. package/dist/src/ruvector/run-transcript-recorder.js.map +1 -0
  51. package/dist/src/services/checkpoint-gate.d.ts +140 -0
  52. package/dist/src/services/checkpoint-gate.d.ts.map +1 -0
  53. package/dist/src/services/checkpoint-gate.js +223 -0
  54. package/dist/src/services/checkpoint-gate.js.map +1 -0
  55. package/dist/src/services/distill-oracle.d.ts +190 -0
  56. package/dist/src/services/distill-oracle.d.ts.map +1 -0
  57. package/dist/src/services/distill-oracle.js +349 -0
  58. package/dist/src/services/distill-oracle.js.map +1 -0
  59. package/dist/src/services/fable-harness.d.ts +168 -0
  60. package/dist/src/services/fable-harness.d.ts.map +1 -0
  61. package/dist/src/services/fable-harness.js +347 -0
  62. package/dist/src/services/fable-harness.js.map +1 -0
  63. package/dist/src/services/native-training.d.ts +28 -0
  64. package/dist/src/services/native-training.d.ts.map +1 -1
  65. package/dist/src/services/native-training.js +62 -5
  66. package/dist/src/services/native-training.js.map +1 -1
  67. package/dist/src/services/swarm-memory-branches.d.ts +135 -0
  68. package/dist/src/services/swarm-memory-branches.d.ts.map +1 -0
  69. package/dist/src/services/swarm-memory-branches.js +213 -0
  70. package/dist/src/services/swarm-memory-branches.js.map +1 -0
  71. package/dist/src/services/weight-eft.d.ts +305 -0
  72. package/dist/src/services/weight-eft.d.ts.map +1 -0
  73. package/dist/src/services/weight-eft.js +296 -0
  74. package/dist/src/services/weight-eft.js.map +1 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +5 -4
@@ -0,0 +1,347 @@
1
+ /**
2
+ * fable-harness.ts — Cost-disciplined headless Fable LLM-as-judge harness.
3
+ *
4
+ * This is TIER 2 of the tiered `resolved` oracle (see distill-oracle.ts). When
5
+ * a trajectory has NO mechanical test spec to execute, we judge whether its
6
+ * completion actually resolved the task with a headless Fable model — a smarter
7
+ * proxy than the structural verifier, but still a proxy (provenance tag
8
+ * `judge:fable`, never presented as ground truth per ADR-169).
9
+ *
10
+ * ── MEASURED COST DATA (load-bearing — this file is built around it) ────────
11
+ * `claude -p --model claude-fable-5 --output-format json` costs, per call:
12
+ * • ~$1.56 when launched FROM THE PROJECT DIR — it auto-loads CLAUDE.md and
13
+ * ~56k cache tokens of project context we do NOT want for judging.
14
+ * • ~$0.34 from a CLEAN empty cwd with `--append-system-prompt` for the role.
15
+ * • ~$0.02/item when we BATCH ~20 items into a single call (context amortizes
16
+ * ~free across the batch).
17
+ *
18
+ * Therefore this harness MUST, and does:
19
+ * 1. run `claude -p` from a FRESH EMPTY TEMP cwd — never the project dir, so
20
+ * no CLAUDE.md / project context is loaded (the 5x cost driver);
21
+ * 2. carry the judge/reflect role via `--append-system-prompt`, not a project
22
+ * system prompt;
23
+ * 3. BATCH N items per call (default 20) so per-item cost collapses to ~$0.02;
24
+ * 4. pass `--max-budget-usd` as a hard per-call cap and stop launching batches
25
+ * once the cumulative measured spend reaches the caller's budget;
26
+ * 5. be OPT-IN and OFF BY DEFAULT — nothing here runs unless a caller
27
+ * explicitly constructs the harness AND provides a budget cap.
28
+ *
29
+ * SAFETY: constructing this class spends nothing. Only `judgeBatch` /
30
+ * `reflectFailures` spawn `claude`, and only when `maxBudgetUsd > 0`. The
31
+ * `spawnClaude` implementation is injectable so tests never touch the real CLI.
32
+ *
33
+ * @module services/fable-harness
34
+ */
35
+ import { spawn } from 'child_process';
36
+ import { mkdtemp, rm } from 'fs/promises';
37
+ import { tmpdir } from 'os';
38
+ import { join } from 'path';
39
+ // ── Cost model (measured — exported so callers/docs share one source) ────────
40
+ export const FABLE_COST_MODEL = {
41
+ /** Measured $/call when launched from the project dir (loads CLAUDE.md). Anti-pattern. */
42
+ perCallProjectCwdUsd: 1.56,
43
+ /** Measured $/call from a clean cwd with --append-system-prompt. */
44
+ perCallCleanCwdUsd: 0.34,
45
+ /** Measured amortized $/item when batching ~20 items per call. */
46
+ perItemBatchedUsd: 0.02,
47
+ /** Default items per `claude -p` call. */
48
+ defaultBatchSize: 20,
49
+ /** The judge model. */
50
+ model: 'claude-fable-5',
51
+ };
52
+ /**
53
+ * Estimate the USD cost of judging `itemCount` items in batches of `batchSize`.
54
+ * Uses the measured amortized per-item figure; callers use this to size a
55
+ * budget cap before opting in.
56
+ */
57
+ export function estimateFableCostUsd(itemCount, batchSize = FABLE_COST_MODEL.defaultBatchSize) {
58
+ if (itemCount <= 0)
59
+ return 0;
60
+ const batches = Math.ceil(itemCount / Math.max(1, batchSize));
61
+ // Amortized per-item dominates; add a tiny floor per batch for the base call.
62
+ const perItem = itemCount * FABLE_COST_MODEL.perItemBatchedUsd;
63
+ const perBatchFloor = batches * 0.0; // per-item figure already includes base amortization
64
+ return Number((perItem + perBatchFloor).toFixed(4));
65
+ }
66
+ // ── Prompt templates (carried via --append-system-prompt) ────────────────────
67
+ const JUDGE_SYSTEM_PROMPT = [
68
+ 'You are a strict evaluator judging whether an agent trajectory RESOLVED its task.',
69
+ 'You receive a JSON array of items: [{id, task, output}].',
70
+ 'For each item decide if `output` genuinely and correctly resolves `task`.',
71
+ 'Be conservative: plausible-but-unverified or partial completions are NOT resolved.',
72
+ 'Reply with ONLY a JSON array, one object per input id, no prose:',
73
+ '[{"id": "...", "resolved": true|false, "confidence": 0.0-1.0, "reason": "<one sentence>"}]',
74
+ ].join('\n');
75
+ const REFLECT_SYSTEM_PROMPT = [
76
+ 'You are a failure-analysis expert supporting reflective mutation (GEPA/evolve).',
77
+ 'You receive a JSON array of items: [{id, task, output, failureHint?}].',
78
+ 'For each item, classify the failure and propose a concrete mutation hint.',
79
+ 'Reply with ONLY a JSON array, one object per input id, no prose:',
80
+ '[{"id":"...","failureClass":"<short label>","diagnosis":"<one sentence>","mutationHint":"<actionable>"}]',
81
+ ].join('\n');
82
+ // ── Default spawner (real CLI) ───────────────────────────────────────────────
83
+ /**
84
+ * Default `claude -p` spawner. Pipes the prompt via stdin (never as an argv
85
+ * positional — mirrors the #1852 fix so shell metachars in prompts are never
86
+ * re-tokenized), runs in the provided (temp) cwd, and returns stdout/stderr.
87
+ * Parses `total_cost_usd` from the `--output-format json` envelope when present.
88
+ */
89
+ export const defaultSpawnClaude = (argv, stdinPrompt, cwd, opts) => new Promise((resolve) => {
90
+ let child;
91
+ try {
92
+ child = spawn('claude', argv, {
93
+ cwd,
94
+ env: { ...process.env, CLAUDE_ENTRYPOINT: 'fable-judge' },
95
+ stdio: ['pipe', 'pipe', 'pipe'],
96
+ windowsHide: true,
97
+ });
98
+ }
99
+ catch (err) {
100
+ resolve({ stdout: '', stderr: err instanceof Error ? err.message : String(err), code: null });
101
+ return;
102
+ }
103
+ let stdout = '';
104
+ let stderr = '';
105
+ let done = false;
106
+ const finish = (r) => {
107
+ if (done)
108
+ return;
109
+ done = true;
110
+ clearTimeout(timer);
111
+ resolve(r);
112
+ };
113
+ const timer = setTimeout(() => {
114
+ try {
115
+ child.kill('SIGTERM');
116
+ }
117
+ catch { /* already dead */ }
118
+ finish({ stdout, stderr: stderr || `timed out after ${opts.timeoutMs}ms`, code: null });
119
+ }, opts.timeoutMs);
120
+ timer.unref?.();
121
+ try {
122
+ child.stdin?.end(stdinPrompt);
123
+ }
124
+ catch { /* surfaced via error */ }
125
+ child.stdout?.on('data', (d) => { stdout += d.toString(); });
126
+ child.stderr?.on('data', (d) => { stderr += d.toString(); });
127
+ child.on('error', (e) => finish({ stdout, stderr: e.message, code: null }));
128
+ child.on('close', (code) => {
129
+ finish({ stdout, stderr, code, costUsd: parseCostFromEnvelope(stdout) });
130
+ });
131
+ });
132
+ /** Pull `total_cost_usd`/`cost_usd` out of a claude `--output-format json` envelope. */
133
+ export function parseCostFromEnvelope(stdout) {
134
+ const env = tryParseJson(stdout);
135
+ if (env && typeof env === 'object') {
136
+ const o = env;
137
+ for (const k of ['total_cost_usd', 'cost_usd', 'costUsd']) {
138
+ if (typeof o[k] === 'number')
139
+ return o[k];
140
+ }
141
+ }
142
+ return undefined;
143
+ }
144
+ // ── Harness ──────────────────────────────────────────────────────────────
145
+ export class FableHarness {
146
+ model;
147
+ batchSize;
148
+ maxBudgetUsd;
149
+ timeoutMs;
150
+ spawnClaude;
151
+ spentUsd = 0;
152
+ constructor(opts = {}) {
153
+ this.model = opts.model ?? FABLE_COST_MODEL.model;
154
+ this.batchSize = Math.max(1, opts.batchSize ?? FABLE_COST_MODEL.defaultBatchSize);
155
+ this.maxBudgetUsd = opts.maxBudgetUsd ?? 0;
156
+ this.timeoutMs = opts.timeoutMs ?? 5 * 60 * 1000;
157
+ this.spawnClaude = opts.spawnClaude ?? defaultSpawnClaude;
158
+ }
159
+ /** Cumulative measured spend across all calls this harness has made. */
160
+ getSpentUsd() {
161
+ return Number(this.spentUsd.toFixed(4));
162
+ }
163
+ /** True when a positive budget cap is configured (a precondition for any spend). */
164
+ isEnabled() {
165
+ return this.maxBudgetUsd > 0;
166
+ }
167
+ /**
168
+ * Judge a set of items in batches. Returns one JudgeResult per input id that
169
+ * the model returned. Items that fall outside the budget, or that the model
170
+ * omits, are simply absent from the result — the caller (distill-oracle) is
171
+ * responsible for falling back to the structural proxy for those.
172
+ *
173
+ * Spends $0 and returns [] when no budget cap is configured.
174
+ */
175
+ async judgeBatch(items) {
176
+ if (items.length === 0)
177
+ return [];
178
+ if (!this.isEnabled())
179
+ return [];
180
+ const out = [];
181
+ for (const batch of chunk(items, this.batchSize)) {
182
+ if (this.spentUsd >= this.maxBudgetUsd)
183
+ break;
184
+ const parsed = await this.runBatch(JUDGE_SYSTEM_PROMPT, batch);
185
+ for (const raw of parsed) {
186
+ const r = normalizeJudge(raw);
187
+ if (r)
188
+ out.push(r);
189
+ }
190
+ }
191
+ return out;
192
+ }
193
+ /**
194
+ * Reflective failure analysis over items — the second cost-disciplined entry
195
+ * point, used by GEPA/evolve for mutation hints. Same batching + budget
196
+ * discipline as judgeBatch. Returns [] when no budget cap is configured.
197
+ */
198
+ async reflectFailures(items) {
199
+ if (items.length === 0)
200
+ return [];
201
+ if (!this.isEnabled())
202
+ return [];
203
+ const out = [];
204
+ for (const batch of chunk(items, this.batchSize)) {
205
+ if (this.spentUsd >= this.maxBudgetUsd)
206
+ break;
207
+ const parsed = await this.runBatch(REFLECT_SYSTEM_PROMPT, batch);
208
+ for (const raw of parsed) {
209
+ const r = normalizeReflect(raw);
210
+ if (r)
211
+ out.push(r);
212
+ }
213
+ }
214
+ return out;
215
+ }
216
+ /** Build the argv for a `claude -p` call. Exposed shape for testability. */
217
+ buildArgv(systemPrompt) {
218
+ const perCallCap = Math.max(0, this.maxBudgetUsd - this.spentUsd);
219
+ return [
220
+ '-p',
221
+ '--model', this.model,
222
+ '--output-format', 'json',
223
+ '--append-system-prompt', systemPrompt,
224
+ '--max-budget-usd', String(round(perCallCap)),
225
+ ];
226
+ }
227
+ /**
228
+ * Run one batch: create a FRESH EMPTY temp cwd (critical — no project
229
+ * context), spawn `claude -p` there with the role via --append-system-prompt,
230
+ * pipe the batch JSON to stdin, parse the verdict array out of the envelope,
231
+ * and account the measured spend.
232
+ */
233
+ async runBatch(systemPrompt, batch) {
234
+ const argv = this.buildArgv(systemPrompt);
235
+ const stdinPrompt = JSON.stringify(batch);
236
+ const cwd = await mkdtemp(join(tmpdir(), 'ruflo-fable-'));
237
+ try {
238
+ const res = await this.spawnClaude(argv, stdinPrompt, cwd, { timeoutMs: this.timeoutMs });
239
+ // Account spend: prefer measured envelope cost, else the amortized estimate.
240
+ this.spentUsd += typeof res.costUsd === 'number'
241
+ ? res.costUsd
242
+ : estimateFableCostUsd(batch.length, this.batchSize);
243
+ if (res.code !== 0 && !res.stdout)
244
+ return [];
245
+ return extractVerdictArray(res.stdout);
246
+ }
247
+ finally {
248
+ await rm(cwd, { recursive: true, force: true }).catch(() => { });
249
+ }
250
+ }
251
+ }
252
+ // ── Parsing helpers ──────────────────────────────────────────────────────
253
+ /**
254
+ * Extract the model's verdict array. `claude -p --output-format json` wraps the
255
+ * assistant text in an envelope `{ result: "<text>", ... }`; the text is itself
256
+ * the JSON array we asked for. Handle both the enveloped and bare forms, and
257
+ * arrays fenced in ```json blocks.
258
+ */
259
+ export function extractVerdictArray(stdout) {
260
+ const trimmed = (stdout ?? '').trim();
261
+ if (!trimmed)
262
+ return [];
263
+ // 1. Enveloped: parse envelope, then its `result` field.
264
+ const env = tryParseJson(trimmed);
265
+ if (env && typeof env === 'object' && !Array.isArray(env)) {
266
+ const result = env.result;
267
+ if (typeof result === 'string') {
268
+ const inner = findJsonArray(result);
269
+ if (inner)
270
+ return inner;
271
+ }
272
+ // Some envelopes embed the array directly.
273
+ const direct = env.results;
274
+ if (Array.isArray(direct))
275
+ return direct;
276
+ }
277
+ if (Array.isArray(env))
278
+ return env;
279
+ // 2. Bare text: find a JSON array anywhere in stdout.
280
+ const arr = findJsonArray(trimmed);
281
+ return arr ?? [];
282
+ }
283
+ function findJsonArray(text) {
284
+ const fenced = text.match(/```(?:json)?\s*(\[[\s\S]*?\])\s*```/);
285
+ if (fenced) {
286
+ const v = tryParseJson(fenced[1]);
287
+ if (Array.isArray(v))
288
+ return v;
289
+ }
290
+ const bare = text.match(/\[[\s\S]*\]/);
291
+ if (bare) {
292
+ const v = tryParseJson(bare[0]);
293
+ if (Array.isArray(v))
294
+ return v;
295
+ }
296
+ return null;
297
+ }
298
+ function normalizeJudge(raw) {
299
+ if (!raw || typeof raw !== 'object')
300
+ return null;
301
+ const o = raw;
302
+ if (typeof o.id !== 'string')
303
+ return null;
304
+ return {
305
+ id: o.id,
306
+ resolved: o.resolved === true || o.resolved === 'true',
307
+ confidence: clamp01(typeof o.confidence === 'number' ? o.confidence : Number(o.confidence)),
308
+ reason: typeof o.reason === 'string' ? o.reason : '',
309
+ };
310
+ }
311
+ function normalizeReflect(raw) {
312
+ if (!raw || typeof raw !== 'object')
313
+ return null;
314
+ const o = raw;
315
+ if (typeof o.id !== 'string')
316
+ return null;
317
+ return {
318
+ id: o.id,
319
+ failureClass: typeof o.failureClass === 'string' ? o.failureClass : 'unknown',
320
+ diagnosis: typeof o.diagnosis === 'string' ? o.diagnosis : '',
321
+ mutationHint: typeof o.mutationHint === 'string' ? o.mutationHint : '',
322
+ };
323
+ }
324
+ function tryParseJson(s) {
325
+ try {
326
+ return JSON.parse(s);
327
+ }
328
+ catch {
329
+ return undefined;
330
+ }
331
+ }
332
+ function chunk(arr, size) {
333
+ const out = [];
334
+ for (let i = 0; i < arr.length; i += size)
335
+ out.push(arr.slice(i, i + size));
336
+ return out;
337
+ }
338
+ function clamp01(n) {
339
+ if (!Number.isFinite(n))
340
+ return 0;
341
+ return Math.max(0, Math.min(1, n));
342
+ }
343
+ function round(n) {
344
+ return Math.round(n * 100) / 100;
345
+ }
346
+ export default FableHarness;
347
+ //# sourceMappingURL=fable-harness.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fable-harness.js","sourceRoot":"","sources":["../../../src/services/fable-harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AC,CAAC;IAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,KAAK,CAAC,CAAS;IACtB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;AACnC,CAAC;AAED,eAAe,YAAY,CAAC"}
@@ -25,6 +25,14 @@ export interface NativeTrainingResult {
25
25
  earlyStopped: boolean;
26
26
  checkpointPath?: string;
27
27
  checkpointBytes?: number;
28
+ /** True when training resumed from a --resume checkpoint. */
29
+ resumed?: boolean;
30
+ /**
31
+ * How the resume happened: 'resumeFrom' (ruvllm >=2.6.0 — restores epoch
32
+ * position + optimizer state) or 'loadCheckpoint' (2.5.7 fallback —
33
+ * weights only, training restarts from epoch 0).
34
+ */
35
+ resumeMode?: 'resumeFrom' | 'loadCheckpoint';
28
36
  }
29
37
  export interface NativeTrainingOptions {
30
38
  embeddings: Float32Array[];
@@ -32,9 +40,29 @@ export interface NativeTrainingOptions {
32
40
  batchSize: number;
33
41
  learningRate: number;
34
42
  dim: number;
43
+ /**
44
+ * Validation holdout fraction (0..1). >0 makes the pipeline report
45
+ * bestValLoss + early-stopping; 0 (or omitted) disables validation.
46
+ * validationSplit exists in ruvllm 2.5.7 — no version gate needed.
47
+ */
48
+ validationSplit?: number;
49
+ /**
50
+ * Resume weights (and, on >=2.6.0, epoch position) from this checkpoint
51
+ * BEFORE training. A missing/invalid path throws ResumeFailedError — an
52
+ * explicit --resume must fail loudly, never silently fresh-train.
53
+ */
54
+ resumeFrom?: string;
35
55
  /** When set, the TRAINED pipeline checkpoints here (ruvllm >=2.5.7). */
36
56
  checkpointPath?: string;
37
57
  }
58
+ /**
59
+ * Thrown when an explicit --resume checkpoint cannot be found or loaded.
60
+ * Distinct from the generic "native unavailable → null" degradation so the
61
+ * caller can surface a loud, exit-1 failure rather than fresh training.
62
+ */
63
+ export declare class ResumeFailedError extends Error {
64
+ constructor(message: string);
65
+ }
38
66
  export declare function nativeTrainingAvailable(): boolean;
39
67
  export declare function runNativeTraining(opts: NativeTrainingOptions): Promise<NativeTrainingResult | null>;
40
68
  //# sourceMappingURL=native-training.d.ts.map
@@ -1 +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"}
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;IACzB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC;CAC9C;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;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,uBAAuB,IAAI,OAAO,CAOjD;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,qBAAqB,GAC1B,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAsGtC"}
@@ -19,6 +19,17 @@
19
19
  import { createRequire } from 'module';
20
20
  import { mkdirSync, existsSync } from 'fs';
21
21
  import { dirname } from 'path';
22
+ /**
23
+ * Thrown when an explicit --resume checkpoint cannot be found or loaded.
24
+ * Distinct from the generic "native unavailable → null" degradation so the
25
+ * caller can surface a loud, exit-1 failure rather than fresh training.
26
+ */
27
+ export class ResumeFailedError extends Error {
28
+ constructor(message) {
29
+ super(message);
30
+ this.name = 'ResumeFailedError';
31
+ }
32
+ }
22
33
  export function nativeTrainingAvailable() {
23
34
  try {
24
35
  createRequire(import.meta.url).resolve('@ruvector/ruvllm');
@@ -29,19 +40,53 @@ export function nativeTrainingAvailable() {
29
40
  }
30
41
  }
31
42
  export async function runNativeTraining(opts) {
32
- const { embeddings, epochs, batchSize, learningRate, dim, checkpointPath } = opts;
43
+ const { embeddings, epochs, batchSize, learningRate, dim, validationSplit, resumeFrom, checkpointPath } = opts;
33
44
  if (embeddings.length < 2)
34
45
  return null;
35
46
  try {
36
47
  const req = createRequire(import.meta.url);
37
48
  const ruvllm = req('@ruvector/ruvllm');
38
- const pipeline = new ruvllm.TrainingPipeline({
49
+ const pipelineConfig = {
39
50
  learningRate,
40
51
  batchSize,
41
52
  epochs,
42
53
  inputDim: dim,
43
54
  outputDim: dim,
44
- });
55
+ };
56
+ // 0 (or omitted) disables validation; only pass a real holdout through.
57
+ if (typeof validationSplit === 'number' && validationSplit > 0) {
58
+ pipelineConfig.validationSplit = validationSplit;
59
+ }
60
+ const pipeline = new ruvllm.TrainingPipeline(pipelineConfig);
61
+ // Resume BEFORE training. Prefer resumeFrom() (2.6.0 — epoch position +
62
+ // optimizer state); fall back to loadCheckpoint() (2.5.7 — weights only).
63
+ // Any failure with an explicit --resume is loud (ResumeFailedError),
64
+ // never silent fresh training.
65
+ let resumed = false;
66
+ let resumeMode;
67
+ if (resumeFrom) {
68
+ if (!existsSync(resumeFrom)) {
69
+ throw new ResumeFailedError(`--resume checkpoint not found: ${resumeFrom}`);
70
+ }
71
+ try {
72
+ if (typeof pipeline.resumeFrom === 'function') {
73
+ pipeline.resumeFrom(resumeFrom);
74
+ resumeMode = 'resumeFrom';
75
+ }
76
+ else {
77
+ const ok = pipeline.loadCheckpoint(resumeFrom);
78
+ if (ok === false)
79
+ throw new Error('loadCheckpoint returned false');
80
+ resumeMode = 'loadCheckpoint';
81
+ }
82
+ resumed = true;
83
+ }
84
+ catch (e) {
85
+ if (e instanceof ResumeFailedError)
86
+ throw e;
87
+ throw new ResumeFailedError(`--resume failed to load checkpoint ${resumeFrom}: ${e.message}`);
88
+ }
89
+ }
45
90
  // Pattern-alignment pairs, chunked into pipeline batches.
46
91
  const inputs = [];
47
92
  const targets = [];
@@ -55,13 +100,21 @@ export async function runNativeTraining(opts) {
55
100
  pipeline.addBatch(inputs.slice(i, i + batchSize), targets.slice(i, i + batchSize), qualities.slice(i, i + batchSize));
56
101
  }
57
102
  const r = pipeline.train();
103
+ // When validation is disabled the pipeline reports Infinity for
104
+ // bestValLoss — normalize any non-finite value to null so downstream
105
+ // "bestValLoss !== null ⇒ validation ran" holds for the results table.
106
+ const bestValLoss = typeof r.bestValLoss === 'number' && Number.isFinite(r.bestValLoss)
107
+ ? r.bestValLoss
108
+ : null;
58
109
  const result = {
59
110
  epochs: r.epochs,
60
111
  steps: r.steps,
61
112
  finalLoss: r.finalLoss,
62
- bestValLoss: r.bestValLoss ?? null,
113
+ bestValLoss,
63
114
  durationMs: r.durationMs,
64
115
  earlyStopped: !!r.earlyStopped,
116
+ resumed,
117
+ resumeMode,
65
118
  };
66
119
  if (checkpointPath) {
67
120
  try {
@@ -77,7 +130,11 @@ export async function runNativeTraining(opts) {
77
130
  }
78
131
  return result;
79
132
  }
80
- catch {
133
+ catch (err) {
134
+ // An explicit --resume failure must propagate as a loud error; every
135
+ // other failure degrades to null so callers fall back to the WASM path.
136
+ if (err instanceof ResumeFailedError)
137
+ throw err;
81
138
  return null;
82
139
  }
83
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"native-training.js","sourceRoot":"","sources":["../../../src/services/native-training.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAuB/B,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC;QACH,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC3D,OAAO,I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