claude-flow 3.10.41 → 3.10.42

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 @@
1
+ {"sessionId":"d0b433ab-a217-4dde-9ea4-b2c996ac456a","pid":35460,"acquiredAt":1781120150954}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "3.10.41",
3
+ "version": "3.10.42",
4
4
  "description": "Ruflo - Enterprise AI agent orchestration for Claude Code. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -399,9 +399,20 @@ const postEditCommand = {
399
399
  metrics,
400
400
  timestamp: Date.now(),
401
401
  });
402
+ // #2352: the MCP handler returns `{success: false, error: "..."}` on
403
+ // validation failure (e.g. unsupported path shape) without throwing.
404
+ // Surface that explicitly instead of always printing the success line —
405
+ // Windows users were seeing `[OK]` while nothing reached the learning
406
+ // pipeline because absolute paths were rejected upstream.
407
+ const mcpFailed = result && result.success === false;
408
+ const mcpError = result?.error;
402
409
  if (ctx.flags.format === 'json') {
403
410
  output.printJson(result);
404
- return { success: true, data: result };
411
+ return { success: !mcpFailed, exitCode: mcpFailed ? 1 : 0, data: result };
412
+ }
413
+ if (mcpFailed) {
414
+ output.printError(`Post-edit hook failed: ${mcpError || 'unknown error'}`);
415
+ return { success: false, exitCode: 1 };
405
416
  }
406
417
  output.writeln();
407
418
  output.printSuccess(`Outcome recorded for ${filePath}`);
@@ -773,7 +773,13 @@ const hooksCommand = {
773
773
  skills: false,
774
774
  commands: false,
775
775
  agents: false,
776
- helpers: false,
776
+ // #2350: helpers MUST ship with the hooks subcommand. The hook entries
777
+ // in settings.json point at `.claude/helpers/hook-handler.cjs`; if
778
+ // that file doesn't exist, settings-generator (#1744 fix) drops the
779
+ // hooks block entirely — so the one subcommand whose stated purpose
780
+ // is "Initialize only hooks configuration" produced settings.json
781
+ // with no `hooks` key while reporting "N hooks enabled".
782
+ helpers: true,
777
783
  statusline: false,
778
784
  mcp: false,
779
785
  runtime: false,
@@ -2665,7 +2665,81 @@ export const hooksTrajectoryEnd = {
2665
2665
  }
2666
2666
  catch { /* intelligence module not loadable — keep sona-only behaviour */ }
2667
2667
  }
2668
+ // #2351: when an agent calls trajectory-end with no recorded steps but a
2669
+ // non-empty `feedback` string, the feedback was previously dropped on the
2670
+ // floor — `patternsExtracted` reported 0 and `pattern-search` never
2671
+ // surfaced it. Step-less trajectories are the common case for LLM agents
2672
+ // (nothing forces step logging mid-task), and feedback is often the most
2673
+ // distilled lesson available. Route it through the same store + embed
2674
+ // path that pattern-store uses so it becomes searchable. Best-effort:
2675
+ // failures here must not turn the trajectory-end call itself into a
2676
+ // failure — the trajectory record was already persisted above.
2677
+ let feedbackDistilled = { stored: false };
2678
+ const hasSteps = !!trajectory && trajectory.steps.length > 0;
2679
+ const trimmedFeedback = typeof feedback === 'string' ? feedback.trim() : '';
2680
+ if (trajectory && !hasSteps && trimmedFeedback.length > 0) {
2681
+ const distilledPatternId = `pattern-feedback-${trajectoryId}-${Date.now()}`;
2682
+ const patternMetadata = {
2683
+ sourceTrajectoryId: trajectoryId,
2684
+ task: trajectory.task,
2685
+ agent: trajectory.agent,
2686
+ outcome: success ? 'success' : 'failure',
2687
+ distilledFrom: 'trajectory-end-feedback',
2688
+ };
2689
+ // Modest default confidence — step-less feedback hasn't been validated
2690
+ // by execution evidence the way a multi-step trajectory has.
2691
+ const feedbackConfidence = success ? 0.6 : 0.4;
2692
+ try {
2693
+ const bridge = await import('../memory/memory-bridge.js');
2694
+ const rb = await bridge.bridgeStorePattern({
2695
+ pattern: trimmedFeedback,
2696
+ type: 'trajectory-feedback',
2697
+ confidence: feedbackConfidence,
2698
+ metadata: patternMetadata,
2699
+ });
2700
+ if (rb?.success) {
2701
+ feedbackDistilled = { stored: true, patternId: rb.patternId, controller: rb.controller };
2702
+ }
2703
+ }
2704
+ catch {
2705
+ // Bridge unavailable — fall through to direct store
2706
+ }
2707
+ if (!feedbackDistilled.stored) {
2708
+ try {
2709
+ const storeFn = await getRealStoreFunction();
2710
+ if (storeFn) {
2711
+ const r = await storeFn({
2712
+ key: distilledPatternId,
2713
+ value: JSON.stringify({
2714
+ pattern: trimmedFeedback,
2715
+ type: 'trajectory-feedback',
2716
+ confidence: feedbackConfidence,
2717
+ metadata: patternMetadata,
2718
+ timestamp: endedAt,
2719
+ }),
2720
+ namespace: 'pattern',
2721
+ generateEmbeddingFlag: true,
2722
+ tags: [
2723
+ 'trajectory-feedback',
2724
+ success ? 'success' : 'failure',
2725
+ `confidence-${Math.round(feedbackConfidence * 100)}`,
2726
+ ],
2727
+ });
2728
+ if (r?.success) {
2729
+ feedbackDistilled = { stored: true, patternId: r.id || distilledPatternId, controller: 'store-fallback' };
2730
+ }
2731
+ }
2732
+ }
2733
+ catch {
2734
+ // Both paths failed — leave feedbackDistilled.stored = false.
2735
+ }
2736
+ }
2737
+ }
2668
2738
  const learningTimeMs = Date.now() - startTime;
2739
+ // patternsExtracted now reflects either recorded steps (the original
2740
+ // semantics) OR a distilled feedback pattern (#2351), so step-less
2741
+ // trajectories with useful feedback no longer report 0.
2742
+ const patternsExtracted = (trajectory?.steps.length || 0) + (feedbackDistilled.stored ? 1 : 0);
2669
2743
  return {
2670
2744
  trajectoryId,
2671
2745
  success,
@@ -2678,7 +2752,11 @@ export const hooksTrajectoryEnd = {
2678
2752
  sonaConfidence: sonaResult.confidence || undefined,
2679
2753
  ewcConsolidation: ewcResult.consolidated,
2680
2754
  ewcPenalty: ewcResult.penalty || undefined,
2681
- patternsExtracted: trajectory?.steps.length || 0,
2755
+ patternsExtracted,
2756
+ feedbackDistilled: feedbackDistilled.stored ? {
2757
+ patternId: feedbackDistilled.patternId,
2758
+ controller: feedbackDistilled.controller,
2759
+ } : undefined,
2682
2760
  learningTimeMs,
2683
2761
  globalStatsTrajectoriesDelta: globalStatsDelta, // Round B: was 0, now reflects
2684
2762
  },
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Neural routing scaffold — `@ruvector/tiny-dancer` FastGRNN seam (#2334 Phase 1)
3
+ *
4
+ * Wires the optional neural path that ADR-026 originally described, behind a
5
+ * double gate that is OFF by default:
6
+ *
7
+ * CLAUDE_FLOW_ROUTER_NEURAL=1 — opt in to the neural path
8
+ * CLAUDE_FLOW_ROUTER_MODEL_PATH=<x.safetensors> — trained FastGRNN artifact
9
+ *
10
+ * Both must be set; otherwise `tryNeuralRoute` returns `null` immediately and
11
+ * the caller stays on the shipped heuristic + Thompson-bandit path. When the
12
+ * gate is open but anything fails (package not installed — it is an
13
+ * optionalDependency per ADR-124 — artifact missing/incompatible, runtime
14
+ * error), this module degrades gracefully: it returns `null`, never throws,
15
+ * and the caller reports `routedBy: 'bandit-fallback'` so the active path is
16
+ * observable rather than inferred from import success (ADR-086/074).
17
+ *
18
+ * Candidate modeling (#2334 Q3, provisional): the 3 model tiers are encoded as
19
+ * fixed candidates with deterministic placeholder embeddings (orthogonal-ish
20
+ * one-hot-block vectors). This is explicitly provisional — the trained Phase 2
21
+ * artifact defines what candidate embeddings mean, and this encoding is the
22
+ * scaffolding default until the maintainers answer #2334's candidate-modeling
23
+ * question. Until a real artifact exists the gate stays closed in practice, so
24
+ * the placeholder never influences routing.
25
+ *
26
+ * @module neural-router
27
+ */
28
+ /** The three routable tiers — 'inherit' is never a neural candidate. */
29
+ export type NeuralRoutableModel = 'haiku' | 'sonnet' | 'opus';
30
+ export interface NeuralRouteDecision {
31
+ model: NeuralRoutableModel;
32
+ confidence: number;
33
+ uncertainty: number;
34
+ inferenceTimeUs: number;
35
+ }
36
+ /** True when the user has opted in AND pointed at a model artifact. */
37
+ export declare function neuralRoutingEnabled(): boolean;
38
+ /** Reset cached state — for tests. */
39
+ export declare function resetNeuralRouter(): void;
40
+ /**
41
+ * Attempt a neural routing decision for the given task embedding.
42
+ *
43
+ * Returns `null` (never throws) when the gate is closed, the package or
44
+ * artifact is unavailable, or inference fails — callers fall back to the
45
+ * bandit and report `routedBy: 'bandit-fallback'` (when the gate was open)
46
+ * or `'heuristic'` (when it never was).
47
+ */
48
+ export declare function tryNeuralRoute(embedding: number[]): Promise<NeuralRouteDecision | null>;
49
+ //# sourceMappingURL=neural-router.d.ts.map
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Neural routing scaffold — `@ruvector/tiny-dancer` FastGRNN seam (#2334 Phase 1)
3
+ *
4
+ * Wires the optional neural path that ADR-026 originally described, behind a
5
+ * double gate that is OFF by default:
6
+ *
7
+ * CLAUDE_FLOW_ROUTER_NEURAL=1 — opt in to the neural path
8
+ * CLAUDE_FLOW_ROUTER_MODEL_PATH=<x.safetensors> — trained FastGRNN artifact
9
+ *
10
+ * Both must be set; otherwise `tryNeuralRoute` returns `null` immediately and
11
+ * the caller stays on the shipped heuristic + Thompson-bandit path. When the
12
+ * gate is open but anything fails (package not installed — it is an
13
+ * optionalDependency per ADR-124 — artifact missing/incompatible, runtime
14
+ * error), this module degrades gracefully: it returns `null`, never throws,
15
+ * and the caller reports `routedBy: 'bandit-fallback'` so the active path is
16
+ * observable rather than inferred from import success (ADR-086/074).
17
+ *
18
+ * Candidate modeling (#2334 Q3, provisional): the 3 model tiers are encoded as
19
+ * fixed candidates with deterministic placeholder embeddings (orthogonal-ish
20
+ * one-hot-block vectors). This is explicitly provisional — the trained Phase 2
21
+ * artifact defines what candidate embeddings mean, and this encoding is the
22
+ * scaffolding default until the maintainers answer #2334's candidate-modeling
23
+ * question. Until a real artifact exists the gate stays closed in practice, so
24
+ * the placeholder never influences routing.
25
+ *
26
+ * @module neural-router
27
+ */
28
+ import { existsSync } from 'fs';
29
+ // ============================================================================
30
+ // Gate & lifecycle
31
+ // ============================================================================
32
+ /** True when the user has opted in AND pointed at a model artifact. */
33
+ export function neuralRoutingEnabled() {
34
+ return process.env.CLAUDE_FLOW_ROUTER_NEURAL === '1'
35
+ && !!process.env.CLAUDE_FLOW_ROUTER_MODEL_PATH;
36
+ }
37
+ // Cached router instance + a sticky failure latch so a broken install/artifact
38
+ // costs one failed load, not one per routing call.
39
+ let routerInstance = null;
40
+ let loadFailed = false;
41
+ /** Reset cached state — for tests. */
42
+ export function resetNeuralRouter() {
43
+ routerInstance = null;
44
+ loadFailed = false;
45
+ }
46
+ async function loadRouter() {
47
+ if (routerInstance)
48
+ return routerInstance;
49
+ if (loadFailed)
50
+ return null;
51
+ const modelPath = process.env.CLAUDE_FLOW_ROUTER_MODEL_PATH;
52
+ if (!modelPath || !existsSync(modelPath)) {
53
+ loadFailed = true;
54
+ return null;
55
+ }
56
+ try {
57
+ // Dynamic import of an optionalDependency (ADR-124): absent on installs
58
+ // where the native binding failed or was skipped — degrade, don't throw.
59
+ const mod = await import('@ruvector/tiny-dancer');
60
+ const RouterCtor = mod.Router;
61
+ if (!RouterCtor) {
62
+ loadFailed = true;
63
+ return null;
64
+ }
65
+ routerInstance = new RouterCtor({ modelPath });
66
+ return routerInstance;
67
+ }
68
+ catch {
69
+ loadFailed = true;
70
+ return null;
71
+ }
72
+ }
73
+ // ============================================================================
74
+ // Candidate encoding (provisional — see header + #2334 Q3)
75
+ // ============================================================================
76
+ const TIER_ORDER = ['haiku', 'sonnet', 'opus'];
77
+ /**
78
+ * Deterministic placeholder embedding for a tier candidate: a block one-hot
79
+ * over the embedding dimensionality. Replaced by whatever the Phase 2 trained
80
+ * artifact defines as candidate space.
81
+ */
82
+ function tierCandidateEmbedding(tierIndex, dim) {
83
+ const v = new Array(dim).fill(0);
84
+ const block = Math.max(1, Math.floor(dim / TIER_ORDER.length));
85
+ const start = tierIndex * block;
86
+ for (let i = start; i < Math.min(start + block, dim); i++)
87
+ v[i] = 1 / Math.sqrt(block);
88
+ return v;
89
+ }
90
+ // ============================================================================
91
+ // Routing
92
+ // ============================================================================
93
+ /**
94
+ * Attempt a neural routing decision for the given task embedding.
95
+ *
96
+ * Returns `null` (never throws) when the gate is closed, the package or
97
+ * artifact is unavailable, or inference fails — callers fall back to the
98
+ * bandit and report `routedBy: 'bandit-fallback'` (when the gate was open)
99
+ * or `'heuristic'` (when it never was).
100
+ */
101
+ export async function tryNeuralRoute(embedding) {
102
+ if (!neuralRoutingEnabled())
103
+ return null;
104
+ if (!embedding || embedding.length === 0)
105
+ return null;
106
+ const router = await loadRouter();
107
+ if (!router)
108
+ return null;
109
+ try {
110
+ const response = await router.route({
111
+ queryEmbedding: embedding,
112
+ candidates: TIER_ORDER.map((tier, i) => ({
113
+ id: tier,
114
+ embedding: tierCandidateEmbedding(i, embedding.length),
115
+ metadata: JSON.stringify({ tier }),
116
+ })),
117
+ });
118
+ const best = response.decisions?.[0];
119
+ if (!best || !TIER_ORDER.includes(best.candidateId))
120
+ return null;
121
+ return {
122
+ model: best.candidateId,
123
+ confidence: best.confidence,
124
+ uncertainty: best.uncertainty,
125
+ inferenceTimeUs: response.inferenceTimeUs,
126
+ };
127
+ }
128
+ catch {
129
+ return null;
130
+ }
131
+ }
132
+ //# sourceMappingURL=neural-router.js.map
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Router trajectory collection (#2334 Phase 1)
3
+ *
4
+ * Opt-in per-decision dataset collection for the model router. The persisted
5
+ * bandit state (`.swarm/model-router-state.json`) keeps only aggregates —
6
+ * 9 Beta(α,β) cells and a capped/truncated history — which is not trainable
7
+ * material for the Phase 2 FastGRNN tier-classifier. This sidecar captures
8
+ * the per-example rows that training needs:
9
+ *
10
+ * decision rows: { taskHash, task, embedding?, complexity, features,
11
+ * model, confidence, uncertainty, routedBy, ts }
12
+ * outcome rows: { taskHash, model, outcome, ts }
13
+ *
14
+ * joined offline on `taskHash` (sha256-16 of the task text).
15
+ *
16
+ * OFF by default. Enable with CLAUDE_FLOW_ROUTER_TRAJECTORY=1. Rows append to
17
+ * `.swarm/model-router-trajectories.jsonl` — local-only, same trust domain as
18
+ * the existing state file, but unlike it the rows contain full task text (up
19
+ * to 500 chars) and raw embeddings, which is why this is opt-in rather than
20
+ * always-on.
21
+ *
22
+ * Writes are best-effort: any fs error is swallowed (collection must never
23
+ * break routing), matching the state-file behavior in model-router.ts.
24
+ *
25
+ * @module router-trajectory
26
+ */
27
+ export declare const TRAJECTORY_FILE = ".swarm/model-router-trajectories.jsonl";
28
+ export declare function trajectoryCollectionEnabled(): boolean;
29
+ /** Join key: first 16 hex chars of sha256(task). */
30
+ export declare function taskHash(task: string): string;
31
+ export interface TrajectoryDecisionRow {
32
+ v: number;
33
+ type: 'decision';
34
+ ts: string;
35
+ taskHash: string;
36
+ /** Task text, capped at 500 chars (cf. learningHistory's 100). */
37
+ task: string;
38
+ /** Raw embedding when one was threaded through route(); else omitted. */
39
+ embedding?: number[];
40
+ complexity: number;
41
+ features: {
42
+ lexicalComplexity: number;
43
+ semanticDepth: number;
44
+ taskScope: number;
45
+ uncertaintyLevel: number;
46
+ };
47
+ model: string;
48
+ confidence: number;
49
+ uncertainty: number;
50
+ routedBy: string;
51
+ }
52
+ export interface TrajectoryOutcomeRow {
53
+ v: number;
54
+ type: 'outcome';
55
+ ts: string;
56
+ taskHash: string;
57
+ model: string;
58
+ outcome: 'success' | 'failure' | 'escalated';
59
+ }
60
+ export declare function recordTrajectoryDecision(task: string, embedding: number[] | undefined, complexity: TrajectoryDecisionRow['features'] & {
61
+ score: number;
62
+ }, decision: {
63
+ model: string;
64
+ confidence: number;
65
+ uncertainty: number;
66
+ routedBy: string;
67
+ }): void;
68
+ export declare function recordTrajectoryOutcome(task: string, model: string, outcome: 'success' | 'failure' | 'escalated'): void;
69
+ //# sourceMappingURL=router-trajectory.d.ts.map
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Router trajectory collection (#2334 Phase 1)
3
+ *
4
+ * Opt-in per-decision dataset collection for the model router. The persisted
5
+ * bandit state (`.swarm/model-router-state.json`) keeps only aggregates —
6
+ * 9 Beta(α,β) cells and a capped/truncated history — which is not trainable
7
+ * material for the Phase 2 FastGRNN tier-classifier. This sidecar captures
8
+ * the per-example rows that training needs:
9
+ *
10
+ * decision rows: { taskHash, task, embedding?, complexity, features,
11
+ * model, confidence, uncertainty, routedBy, ts }
12
+ * outcome rows: { taskHash, model, outcome, ts }
13
+ *
14
+ * joined offline on `taskHash` (sha256-16 of the task text).
15
+ *
16
+ * OFF by default. Enable with CLAUDE_FLOW_ROUTER_TRAJECTORY=1. Rows append to
17
+ * `.swarm/model-router-trajectories.jsonl` — local-only, same trust domain as
18
+ * the existing state file, but unlike it the rows contain full task text (up
19
+ * to 500 chars) and raw embeddings, which is why this is opt-in rather than
20
+ * always-on.
21
+ *
22
+ * Writes are best-effort: any fs error is swallowed (collection must never
23
+ * break routing), matching the state-file behavior in model-router.ts.
24
+ *
25
+ * @module router-trajectory
26
+ */
27
+ import { createHash } from 'crypto';
28
+ import { appendFileSync, existsSync, mkdirSync } from 'fs';
29
+ import { dirname, join } from 'path';
30
+ export const TRAJECTORY_FILE = '.swarm/model-router-trajectories.jsonl';
31
+ /** Schema version stamped on every row so offline training can dispatch. */
32
+ const ROW_VERSION = 1;
33
+ export function trajectoryCollectionEnabled() {
34
+ return process.env.CLAUDE_FLOW_ROUTER_TRAJECTORY === '1';
35
+ }
36
+ /** Join key: first 16 hex chars of sha256(task). */
37
+ export function taskHash(task) {
38
+ return createHash('sha256').update(task).digest('hex').slice(0, 16);
39
+ }
40
+ function appendRow(row) {
41
+ try {
42
+ const fullPath = join(process.cwd(), TRAJECTORY_FILE);
43
+ const dir = dirname(fullPath);
44
+ if (!existsSync(dir))
45
+ mkdirSync(dir, { recursive: true });
46
+ appendFileSync(fullPath, JSON.stringify(row) + '\n');
47
+ }
48
+ catch {
49
+ // Best-effort: collection must never break routing.
50
+ }
51
+ }
52
+ export function recordTrajectoryDecision(task, embedding, complexity, decision) {
53
+ if (!trajectoryCollectionEnabled())
54
+ return;
55
+ appendRow({
56
+ v: ROW_VERSION,
57
+ type: 'decision',
58
+ ts: new Date().toISOString(),
59
+ taskHash: taskHash(task),
60
+ task: task.slice(0, 500),
61
+ ...(embedding && embedding.length > 0 ? { embedding } : {}),
62
+ complexity: complexity.score,
63
+ features: {
64
+ lexicalComplexity: complexity.lexicalComplexity,
65
+ semanticDepth: complexity.semanticDepth,
66
+ taskScope: complexity.taskScope,
67
+ uncertaintyLevel: complexity.uncertaintyLevel,
68
+ },
69
+ model: decision.model,
70
+ confidence: decision.confidence,
71
+ uncertainty: decision.uncertainty,
72
+ routedBy: decision.routedBy,
73
+ });
74
+ }
75
+ export function recordTrajectoryOutcome(task, model, outcome) {
76
+ if (!trajectoryCollectionEnabled())
77
+ return;
78
+ appendRow({
79
+ v: ROW_VERSION,
80
+ type: 'outcome',
81
+ ts: new Date().toISOString(),
82
+ taskHash: taskHash(task),
83
+ model,
84
+ outcome,
85
+ });
86
+ }
87
+ //# sourceMappingURL=router-trajectory.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.10.41",
3
+ "version": "3.10.42",
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",