claude-flow 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 (36) hide show
  1. package/package.json +2 -2
  2. package/v3/@claude-flow/cli/dist/src/agenticow/speculative-exploration.d.ts +148 -0
  3. package/v3/@claude-flow/cli/dist/src/agenticow/speculative-exploration.js +218 -0
  4. package/v3/@claude-flow/cli/dist/src/commands/autopilot.js +45 -0
  5. package/v3/@claude-flow/cli/dist/src/commands/neural.js +366 -12
  6. package/v3/@claude-flow/cli/dist/src/mcp-client.js +6 -1
  7. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-execute-core.js +33 -0
  8. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +47 -1
  9. package/v3/@claude-flow/cli/dist/src/mcp-tools/agenticow-loader.d.ts +59 -0
  10. package/v3/@claude-flow/cli/dist/src/mcp-tools/agenticow-loader.js +105 -0
  11. package/v3/@claude-flow/cli/dist/src/mcp-tools/agenticow-speculate-tools.d.ts +24 -0
  12. package/v3/@claude-flow/cli/dist/src/mcp-tools/agenticow-speculate-tools.js +202 -0
  13. package/v3/@claude-flow/cli/dist/src/mcp-tools/agenticow-tools.js +186 -79
  14. package/v3/@claude-flow/cli/dist/src/mcp-tools/index.d.ts +1 -0
  15. package/v3/@claude-flow/cli/dist/src/mcp-tools/index.js +2 -0
  16. package/v3/@claude-flow/cli/dist/src/ruvector/index.d.ts +1 -1
  17. package/v3/@claude-flow/cli/dist/src/ruvector/index.js +1 -1
  18. package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.d.ts +35 -0
  19. package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.js +108 -1
  20. package/v3/@claude-flow/cli/dist/src/ruvector/router-trajectory.d.ts +33 -0
  21. package/v3/@claude-flow/cli/dist/src/ruvector/router-trajectory.js +31 -0
  22. package/v3/@claude-flow/cli/dist/src/ruvector/run-transcript-recorder.d.ts +154 -0
  23. package/v3/@claude-flow/cli/dist/src/ruvector/run-transcript-recorder.js +209 -0
  24. package/v3/@claude-flow/cli/dist/src/services/checkpoint-gate.d.ts +140 -0
  25. package/v3/@claude-flow/cli/dist/src/services/checkpoint-gate.js +223 -0
  26. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.d.ts +190 -0
  27. package/v3/@claude-flow/cli/dist/src/services/distill-oracle.js +349 -0
  28. package/v3/@claude-flow/cli/dist/src/services/fable-harness.d.ts +168 -0
  29. package/v3/@claude-flow/cli/dist/src/services/fable-harness.js +347 -0
  30. package/v3/@claude-flow/cli/dist/src/services/native-training.d.ts +28 -0
  31. package/v3/@claude-flow/cli/dist/src/services/native-training.js +62 -5
  32. package/v3/@claude-flow/cli/dist/src/services/swarm-memory-branches.d.ts +135 -0
  33. package/v3/@claude-flow/cli/dist/src/services/swarm-memory-branches.js +213 -0
  34. package/v3/@claude-flow/cli/dist/src/services/weight-eft.d.ts +305 -0
  35. package/v3/@claude-flow/cli/dist/src/services/weight-eft.js +296 -0
  36. package/v3/@claude-flow/cli/package.json +5 -4
@@ -0,0 +1,296 @@
1
+ /**
2
+ * weight-eft.ts — Optional-dependency service wrapper around
3
+ * `@metaharness/weight-eft` (agenticow / ADR-150 weight-eft slice).
4
+ *
5
+ * WHAT THIS SHIPS (and what it deliberately does NOT)
6
+ * ---------------------------------------------------
7
+ * This service turns ruflo's captured run transcripts into AUDITED TRAINING
8
+ * DATA + a COST-PARETO measurement + a GPU TRAINING PLAN. It does NOT train a
9
+ * model and it does NOT "reduce escalation":
10
+ * - `runExport` → SFT (OpenAI chat) + DPO (TRL preference) JSONL + a guard
11
+ * report (contamination / reward-hack / long-context). $0.
12
+ * - `runPlan` → the GPU training plan + the exact `ruvllm microlora`
13
+ * command a GPU host would run. $0 dry-run — never spawns.
14
+ * - `runEval` → the cost-Pareto delta folded from two CascadeOutcome[]. $0.
15
+ * - `runRemoteTrain` → an SSH-based remote-GPU invocation. DRY-RUN by default
16
+ * (prints commands + read-only preflight); real compute only
17
+ * behind explicit `execute && yes`. This is the ONLY path
18
+ * that can spend, and it spends on the USER's host, not $0.
19
+ *
20
+ * HARD HONESTY RULE (do not overclaim): weight-eft's own `train` never spawns
21
+ * (its README §Status), and no GPU tune has run here. `resolved` in the
22
+ * captured archive is a PROXY (ruflo has no SWE-bench gold oracle) — the SFT
23
+ * data-quality caveat stands. Nothing here claims ruflo "trains a model" as a
24
+ * $0/local capability.
25
+ *
26
+ * ADR-150 GRACEFUL DEGRADATION
27
+ * ----------------------------
28
+ * `@metaharness/weight-eft` is an OPTIONAL dependency. Every entry point loads
29
+ * it via a dynamic import through `loadWeightEft()` and returns a structured
30
+ * `{ degraded: true }` result when it is absent — never a throw. There is NO
31
+ * static `import … from '@metaharness/weight-eft'` anywhere in this file; the
32
+ * types below are LOCAL mirrors so tsc stays green with the package removed.
33
+ *
34
+ * @module services/weight-eft
35
+ */
36
+ import { spawnSync } from 'node:child_process';
37
+ const WEIGHT_EFT_PKG = '@metaharness/weight-eft';
38
+ /**
39
+ * Load `@metaharness/weight-eft` (optional dep). Returns the module or `null`
40
+ * when it is absent/broken. Never throws. The specifier is held in a variable
41
+ * so tsc does not statically resolve the package (keeps the build green when
42
+ * the optional dep is removed — ADR-150).
43
+ */
44
+ export async function loadWeightEft(importer) {
45
+ const load = importer ?? (() => import(/* @vite-ignore */ WEIGHT_EFT_PKG));
46
+ try {
47
+ const mod = (await load());
48
+ const api = (mod && typeof mod.exportTrainingData === 'function' ? mod : mod?.default);
49
+ if (!api || typeof api.exportTrainingData !== 'function')
50
+ return null;
51
+ return api;
52
+ }
53
+ catch {
54
+ return null; // MODULE_NOT_FOUND or any load error → degraded
55
+ }
56
+ }
57
+ /**
58
+ * Map captured ruflo run transcripts to the DarwinTrajectory[] contract the
59
+ * weight-eft exporter codes against. PURE + synchronous — this is the seam the
60
+ * archive-builder unit test exercises.
61
+ *
62
+ * A record is skipped (not thrown) when it lacks the minimum an exporter needs:
63
+ * an instance_id and a non-empty messages array. `resolved` is copied verbatim
64
+ * and its proxy provenance is tallied so the caller can print an honest note.
65
+ */
66
+ export function buildArchiveFromRecords(records) {
67
+ const trajectories = [];
68
+ const stats = {
69
+ total: 0, resolved: 0, byTier: { cheap: 0, frontier: 0 }, byResolvedSource: {}, skipped: 0,
70
+ };
71
+ let hasGold = false;
72
+ for (const r of records) {
73
+ if (!r || !r.instance_id || !Array.isArray(r.messages) || r.messages.length === 0) {
74
+ stats.skipped++;
75
+ continue;
76
+ }
77
+ const tier = r.tier === 'cheap' ? 'cheap' : 'frontier';
78
+ trajectories.push({
79
+ instance_id: r.instance_id,
80
+ model: r.model,
81
+ tier,
82
+ resolved: !!r.resolved,
83
+ messages: r.messages,
84
+ model_patch: r.model_patch ?? '',
85
+ sample: r.sample ?? 0,
86
+ ...(r.source ? { source: r.source } : {}),
87
+ });
88
+ stats.total++;
89
+ stats.byTier[tier]++;
90
+ if (r.resolved)
91
+ stats.resolved++;
92
+ const src = r.resolved_source ?? 'external';
93
+ stats.byResolvedSource[src] = (stats.byResolvedSource[src] ?? 0) + 1;
94
+ if (src === 'gold-oracle')
95
+ hasGold = true;
96
+ }
97
+ const proxyNote = hasGold
98
+ ? 'resolved: some records carry gold-oracle status; others are proxies (see byResolvedSource).'
99
+ : 'resolved is a PROXY — ruflo has no SWE-bench gold oracle. `output-verifier`/`api-success` ' +
100
+ 'labels are explicitly-marked proxies, NOT conformant gold eval. SFT/DPO quality is bounded by this.';
101
+ return { trajectories, stats, proxyNote };
102
+ }
103
+ /** Run the weight-eft exporter over a DarwinTrajectory[] archive. $0. */
104
+ export async function runExport(opts) {
105
+ const api = await loadWeightEft(opts.importer);
106
+ if (!api)
107
+ return { degraded: true, reason: 'weight-eft-not-available' };
108
+ try {
109
+ const res = api.exportTrainingData(opts.archive, {
110
+ evalHoldout: opts.evalHoldout ?? [],
111
+ ...(opts.maxTokens != null ? { maxTokens: opts.maxTokens } : {}),
112
+ ...(opts.truncateOverLength != null ? { truncateOverLength: opts.truncateOverLength } : {}),
113
+ // reward-hack filter defaults ON inside weight-eft; only forward an explicit override
114
+ ...(opts.dropRewardHacked != null ? { dropRewardHacked: opts.dropRewardHacked } : {}),
115
+ });
116
+ return {
117
+ degraded: false,
118
+ report: res.report,
119
+ sftJsonl: api.sftToJsonl(res.sft),
120
+ dpoJsonl: api.dpoToJsonl(res.dpo),
121
+ sftRows: res.sft.length,
122
+ dpoRows: res.dpo.length,
123
+ };
124
+ }
125
+ catch (e) {
126
+ // exportTrainingData throws on contamination-guard violation — surface it.
127
+ return { degraded: true, reason: `export-failed: ${e.message}` };
128
+ }
129
+ }
130
+ /** Emit the two-stage (SFT → on-policy DPO) GPU training plan. $0 dry-run. */
131
+ export async function runPlan(opts) {
132
+ const api = await loadWeightEft(opts.importer);
133
+ if (!api)
134
+ return { degraded: true, reason: 'weight-eft-not-available' };
135
+ const base = opts.base ?? DEFAULT_BASE_MODEL;
136
+ try {
137
+ const plan = api.twoStagePlan(base, opts.sftPath, opts.dpoPath, opts.adapterPrefix ?? 'ruflo-weft');
138
+ return { degraded: false, base, sft: plan.sft, dpo: plan.dpo };
139
+ }
140
+ catch (e) {
141
+ return { degraded: true, reason: `plan-failed: ${e.message}` };
142
+ }
143
+ }
144
+ /** Fold base + adapter CascadeOutcome[] into the cost-Pareto delta. $0. */
145
+ export async function runEval(opts) {
146
+ const api = await loadWeightEft(opts.importer);
147
+ if (!api)
148
+ return { degraded: true, reason: 'weight-eft-not-available' };
149
+ try {
150
+ return { degraded: false, delta: api.costParetoDelta(opts.baseOutcomes, opts.adapterOutcomes) };
151
+ }
152
+ catch (e) {
153
+ return { degraded: true, reason: `eval-failed: ${e.message}` };
154
+ }
155
+ }
156
+ /** Default cheap-tier tune target — a 7B coder in the tunable [1,14]B band. */
157
+ export const DEFAULT_BASE_MODEL = { id: 'Qwen/Qwen2.5-Coder-7B-Instruct', paramsB: 7 };
158
+ function sshTarget(args) {
159
+ return args.sshUser ? `${args.sshUser}@${args.host}` : args.host;
160
+ }
161
+ function sshBase(port) {
162
+ return ['-o', 'BatchMode=yes', '-o', 'ConnectTimeout=8', '-p', String(port)];
163
+ }
164
+ /** Render an argv as a copy-pasteable shell line (quoting args with spaces). */
165
+ function renderCmd(argv) {
166
+ return argv.map((a) => (/[\s"'$]/.test(a) ? `'${a.replace(/'/g, `'\\''`)}'` : a)).join(' ');
167
+ }
168
+ /**
169
+ * Construct the exact ssh/rsync/ruvllm invocations a remote GPU tune would run.
170
+ * PURE — no spawning, no filesystem, deterministic. This is the seam the
171
+ * command-construction unit test exercises. The ruvllm commands mirror the
172
+ * canonical `ruvllm microlora sft … && ruvllm microlora dpo --init-from …`
173
+ * plan weight-eft emits, wrapped for SSH execution on the remote host.
174
+ */
175
+ export function buildRemoteTrainInvocation(args) {
176
+ const base = args.base ?? DEFAULT_BASE_MODEL.id;
177
+ const port = args.sshPort ?? 22;
178
+ const runId = args.runId ?? `weft-${Date.now().toString(36)}`;
179
+ const prefix = args.adapterPrefix ?? 'ruflo-weft';
180
+ const remoteWorkdir = args.remoteWorkdir ?? `~/.ruflo-weft/${runId}`;
181
+ const adapterDir = args.adapterDir ?? '.claude-flow/neural';
182
+ const target = sshTarget(args);
183
+ const ssh = sshBase(port);
184
+ const rsyncSsh = `ssh -p ${port}`;
185
+ const sftAdapter = `${prefix}-${runId}-sft`;
186
+ const dpoAdapter = `${prefix}-${runId}-dpo`;
187
+ const preflight = [
188
+ { label: 'ssh reachability', argv: ['ssh', ...ssh, target, 'true'] },
189
+ { label: 'ruvllm version', argv: ['ssh', ...ssh, target, 'ruvllm --version || echo RUVLLM_MISSING'] },
190
+ { label: 'gpu probe', argv: ['ssh', ...ssh, target, 'nvidia-smi -L || echo NO_NVIDIA_SMI'] },
191
+ ];
192
+ const sftCmd = `cd ${remoteWorkdir} && ruvllm microlora sft --base ${base} --data sft.jsonl --output ${sftAdapter}`;
193
+ const dpoCmd = `cd ${remoteWorkdir} && ruvllm microlora dpo --base ${base} --init-from ${sftAdapter} ` +
194
+ `--data dpo.jsonl --output ${dpoAdapter}`;
195
+ const steps = [
196
+ { label: 'remote mkdir', argv: ['ssh', ...ssh, target, `mkdir -p ${remoteWorkdir}`] },
197
+ { label: 'rsync sft up', argv: ['rsync', '-az', '-e', rsyncSsh, args.sftPath, `${target}:${remoteWorkdir}/sft.jsonl`] },
198
+ { label: 'rsync dpo up', argv: ['rsync', '-az', '-e', rsyncSsh, args.dpoPath, `${target}:${remoteWorkdir}/dpo.jsonl`] },
199
+ { label: 'ruvllm sft (real GPU compute)', argv: ['ssh', ...ssh, target, sftCmd] },
200
+ { label: 'ruvllm dpo (real GPU compute)', argv: ['ssh', ...ssh, target, dpoCmd] },
201
+ { label: 'rsync adapter back', argv: ['rsync', '-az', '-e', rsyncSsh, `${target}:${remoteWorkdir}/${dpoAdapter}/`, `${adapterDir}/${dpoAdapter}/`] },
202
+ ];
203
+ return {
204
+ host: args.host, base, runId, remoteWorkdir, adapterDir, sftAdapter, dpoAdapter,
205
+ preflight, steps,
206
+ humanCommands: [...preflight, ...steps].map((s) => renderCmd(s.argv)),
207
+ };
208
+ }
209
+ /**
210
+ * Run (or, by default, DRY-RUN) a remote-GPU tune. SAFETY MODEL:
211
+ * - DEFAULT (no execute): builds the plan, runs read-only preflight probes,
212
+ * and returns the commands that WOULD run. NO rsync of data, NO training.
213
+ * - execute && !yes → 'refused' (real GPU spend needs an explicit second gate).
214
+ * - execute && yes → runs preflight; if unreachable → 'preflight-failed'
215
+ * WITHOUT training; else runs rsync + ssh ruvllm sft/dpo + fetch-back.
216
+ * - No `ssh` binary / host unreachable / any spawn error → structured
217
+ * degraded/preflight-failed. NEVER throws.
218
+ *
219
+ * `spawn` is injected for testing so CI never touches a live host.
220
+ */
221
+ export async function runRemoteTrain(args) {
222
+ let plan;
223
+ try {
224
+ plan = buildRemoteTrainInvocation(args);
225
+ }
226
+ catch (e) {
227
+ return { degraded: true, reason: `plan-construction-failed: ${e.message}` };
228
+ }
229
+ const spawn = args.spawn ?? defaultSpawn;
230
+ // Preflight — read-only reachability/capability probes. These DO contact the
231
+ // remote host (ssh ... true), so a bare dry-run must NOT run them: "no
232
+ // implicit remote execution" (adversarial RC finding). Probes run only when
233
+ // executing, or when the caller explicitly opts in with --preflight.
234
+ const runProbe = (s) => {
235
+ try {
236
+ const r = spawn(s.argv[0], s.argv.slice(1));
237
+ if (r.error)
238
+ return { label: s.label, ok: false, detail: r.error.message };
239
+ const out = `${r.stdout ?? ''}${r.stderr ?? ''}`.trim();
240
+ const ok = (r.status ?? 1) === 0 && !/RUVLLM_MISSING|NO_NVIDIA_SMI/.test(out);
241
+ return { label: s.label, ok, detail: out.slice(0, 200) || `exit ${r.status ?? 'null'}` };
242
+ }
243
+ catch (e) {
244
+ return { label: s.label, ok: false, detail: e.message };
245
+ }
246
+ };
247
+ const doProbe = args.execute === true || args.preflight === true;
248
+ const preflight = doProbe ? plan.preflight.map(runProbe) : [];
249
+ const reachable = preflight[0]?.ok === true;
250
+ if (!args.execute) {
251
+ // Bare dry-run is fully offline — plan + commands only, no host contact.
252
+ return {
253
+ degraded: false, mode: 'dry-run', plan, preflight,
254
+ reason: doProbe ? undefined : 'offline dry-run — no host contacted. Add --preflight to probe reachability/GPU, or --execute --yes to train.',
255
+ };
256
+ }
257
+ if (!args.yes) {
258
+ return {
259
+ degraded: false, mode: 'refused', plan, preflight,
260
+ reason: '--execute runs REAL GPU compute on your host; re-run with --yes to confirm the spend.',
261
+ };
262
+ }
263
+ if (!reachable) {
264
+ return { degraded: false, mode: 'preflight-failed', plan, preflight, reason: 'ssh host not reachable — aborting before any data transfer or training.' };
265
+ }
266
+ // Execute the mutating steps sequentially, stopping at the first failure.
267
+ const steps = [];
268
+ for (const s of plan.steps) {
269
+ let entry;
270
+ try {
271
+ const r = spawn(s.argv[0], s.argv.slice(1));
272
+ const out = `${r.stdout ?? ''}${r.stderr ?? ''}`.trim();
273
+ entry = { label: s.label, ok: !r.error && (r.status ?? 1) === 0, detail: r.error ? r.error.message : (out.slice(0, 200) || `exit ${r.status ?? 'null'}`) };
274
+ }
275
+ catch (e) {
276
+ entry = { label: s.label, ok: false, detail: e.message };
277
+ }
278
+ steps.push(entry);
279
+ if (!entry.ok)
280
+ break;
281
+ }
282
+ return { degraded: false, mode: 'executed', plan, preflight, steps };
283
+ }
284
+ /** Default spawn — synchronous child_process, imported lazily so this module
285
+ * stays importable in any environment. Never throws (spawnSync surfaces
286
+ * errors on the returned object). */
287
+ function defaultSpawn(cmd, argv) {
288
+ try {
289
+ const r = spawnSync(cmd, argv, { encoding: 'utf8', timeout: 30 * 60 * 1000 });
290
+ return { status: r.status, stdout: r.stdout, stderr: r.stderr, error: r.error ?? undefined };
291
+ }
292
+ catch (e) {
293
+ return { status: null, error: e };
294
+ }
295
+ }
296
+ //# sourceMappingURL=weight-eft.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.19.0",
3
+ "version": "3.21.0",
4
4
  "type": "module",
5
5
  "description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code",
6
6
  "main": "dist/src/index.js",
@@ -106,8 +106,6 @@
106
106
  "yaml": "^2.8.0"
107
107
  },
108
108
  "optionalDependencies": {
109
- "agentbbs": "~0.1.0",
110
- "agenticow": "~0.2.3",
111
109
  "@claude-flow/aidefence": "^3.0.2",
112
110
  "@claude-flow/codex": "^3.0.0-alpha.8",
113
111
  "@claude-flow/embeddings": "^3.0.0-alpha.18",
@@ -119,7 +117,7 @@
119
117
  "@metaharness/kernel": "~0.1.2",
120
118
  "@metaharness/redblue": "~0.1.4",
121
119
  "@metaharness/router": "~0.3.2",
122
- "metaharness": "~0.2.8",
120
+ "@metaharness/weight-eft": "~0.1.1",
123
121
  "@ruvector/attention": "^0.1.32",
124
122
  "@ruvector/attention-darwin-arm64": "0.1.32",
125
123
  "@ruvector/diskann": "^0.1.0",
@@ -129,8 +127,11 @@
129
127
  "@ruvector/rvagent-wasm": "^0.1.0",
130
128
  "@ruvector/sona": "^0.1.6",
131
129
  "@ruvector/tiny-dancer": "^0.1.22",
130
+ "agentbbs": "~0.1.0",
132
131
  "agentdb": "^3.0.0-alpha.17",
133
132
  "agentic-flow": "^3.0.0-alpha.1",
133
+ "agenticow": "~0.2.4",
134
+ "metaharness": "~0.2.8",
134
135
  "ruvector": "^0.2.27"
135
136
  },
136
137
  "publishConfig": {