claude-flow 3.32.35 → 3.32.36

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 (41) hide show
  1. package/.claude/helpers/hook-handler.cjs +134 -3
  2. package/.claude/helpers/intelligence.cjs +47 -4
  3. package/node_modules/@claude-flow/codex/.agents/skills/github-automation/SKILL.md +32 -0
  4. package/node_modules/@claude-flow/codex/.agents/skills/performance-analysis/SKILL.md +32 -0
  5. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.d.ts +4 -0
  6. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.d.ts.map +1 -1
  7. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.js +20 -1
  8. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.js.map +1 -1
  9. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.d.ts +4 -0
  10. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.d.ts.map +1 -1
  11. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.js +18 -2
  12. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.js.map +1 -1
  13. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts +11 -5
  14. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts.map +1 -1
  15. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js +84 -849
  16. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js.map +1 -1
  17. package/node_modules/@claude-flow/codex/dist/initializer.d.ts.map +1 -1
  18. package/node_modules/@claude-flow/codex/dist/initializer.js +9 -13
  19. package/node_modules/@claude-flow/codex/dist/initializer.js.map +1 -1
  20. package/package.json +1 -1
  21. package/v3/@claude-flow/cli/bin/cli.js +25 -1
  22. package/v3/@claude-flow/cli/catalog-manifest.json +2 -2
  23. package/v3/@claude-flow/cli/dist/src/commands/agent.js +1 -1
  24. package/v3/@claude-flow/cli/dist/src/commands/doctor.js +159 -11
  25. package/v3/@claude-flow/cli/dist/src/commands/hooks.js +39 -4
  26. package/v3/@claude-flow/cli/dist/src/commands/mcp.js +1 -1
  27. package/v3/@claude-flow/cli/dist/src/commands/memory-distill.js +1 -0
  28. package/v3/@claude-flow/cli/dist/src/commands/swarm.js +28 -0
  29. package/v3/@claude-flow/cli/dist/src/init/executor.js +16 -10
  30. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +15 -4
  31. package/v3/@claude-flow/cli/dist/src/init/statusline-generator.js +18 -5
  32. package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +25 -0
  33. package/v3/@claude-flow/cli/dist/src/mcp-server.js +57 -2
  34. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +51 -10
  35. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +34 -8
  36. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +2 -0
  37. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +5 -1
  38. package/v3/@claude-flow/cli/dist/src/services/memory-distillation.d.ts +1 -0
  39. package/v3/@claude-flow/cli/dist/src/services/memory-distillation.js +81 -5
  40. package/v3/@claude-flow/cli/dist/src/services/worker-daemon.js +1 -0
  41. package/v3/@claude-flow/cli/package.json +1 -1
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * Turns raw `memory_entries` (what ruflo has been RECORDING for thousands of
5
5
  * commits) into the structured intelligence substrate it has never populated:
6
- * `episodes` → `reasoning_patterns` (+ `pattern_embeddings`) → `causal_edges`.
6
+ * `episodes` (+ `episode_embeddings`) → `reasoning_patterns`
7
+ * (+ `pattern_embeddings`) → `causal_edges`.
7
8
  * This is the DISTILL/CONSOLIDATE half of the RETRIEVE→JUDGE→DISTILL→CONSOLIDATE
8
9
  * pipeline; RETRIEVE (embeddings) was already populated, the rest was empty
9
10
  * because the daemon's `consolidate` worker was a stub (see ADR-174 root cause).
@@ -28,7 +29,8 @@ import * as path from 'path';
28
29
  import { distillTrajectoryContent, serialiseDistilled } from '../memory/structured-distill.js';
29
30
  function emptyReport(dryRun, extra = {}) {
30
31
  return {
31
- processed: 0, episodes: 0, patterns: 0, patternEmbeddings: 0, causalEdges: 0,
32
+ processed: 0, episodes: 0, episodeEmbeddings: 0,
33
+ patterns: 0, patternEmbeddings: 0, causalEdges: 0,
32
34
  promoted: 0, byProvenance: {}, namespaces: [], dryRun, spendUsd: 0, ...extra,
33
35
  };
34
36
  }
@@ -74,6 +76,20 @@ function judgeFeedback(content) {
74
76
  catch { /* not JSON — treat as neutral */ }
75
77
  return { success: true, reward: 0.5 };
76
78
  }
79
+ /** Preserve an execution-observed lesson for Reflexion without presenting
80
+ * proxy/structural summaries as genuine self-critique. */
81
+ function feedbackCritique(content) {
82
+ try {
83
+ const value = JSON.parse(content);
84
+ for (const key of ['critique', 'error', 'message', 'summary', 'stderr']) {
85
+ if (typeof value[key] === 'string' && value[key].trim()) {
86
+ return value[key].trim().slice(0, 2000);
87
+ }
88
+ }
89
+ }
90
+ catch { /* retain the original execution feedback below */ }
91
+ return `Observed execution feedback: ${content}`.slice(0, 2000);
92
+ }
77
93
  /**
78
94
  * Distill accumulated memory into the structured intelligence tables.
79
95
  * Incremental, $0, transactional, provenance-tagged.
@@ -115,6 +131,17 @@ export async function runDistillation(options) {
115
131
  db.close();
116
132
  return { ...report, corrupt: true, skipped: 'memory DB reports corruption — run recoverMemoryDatabase first' };
117
133
  }
134
+ // #2677 — older AgentDB stores may have episodes but no embedding table.
135
+ // Create the stable AgentDB v1 table only after the corruption gate, and
136
+ // never create it during a dry-run.
137
+ if (!dryRun && !tableExists('episode_embeddings')) {
138
+ db.exec(`CREATE TABLE episode_embeddings (
139
+ episode_id INTEGER PRIMARY KEY,
140
+ embedding BLOB NOT NULL,
141
+ embedding_model TEXT DEFAULT 'all-MiniLM-L6-v2',
142
+ FOREIGN KEY(episode_id) REFERENCES episodes(id) ON DELETE CASCADE
143
+ )`);
144
+ }
118
145
  // M0: incremental cursor table (per namespace, by monotonic rowid).
119
146
  db.exec(`CREATE TABLE IF NOT EXISTS distill_state (
120
147
  namespace TEXT PRIMARY KEY,
@@ -128,10 +155,54 @@ export async function runDistillation(options) {
128
155
  const getCursor = db.prepare('SELECT last_rowid FROM distill_state WHERE namespace = ?');
129
156
  const setCursor = db.prepare('INSERT INTO distill_state (namespace, last_rowid, last_run_at) VALUES (?, ?, ?) ' +
130
157
  'ON CONFLICT(namespace) DO UPDATE SET last_rowid = excluded.last_rowid, last_run_at = excluded.last_run_at');
131
- const insEpisode = db.prepare('INSERT INTO episodes (session_id, task, input, output, reward, success, tags, metadata) VALUES (?,?,?,?,?,?,?,?)');
158
+ const insEpisode = db.prepare('INSERT INTO episodes (session_id, task, input, output, critique, reward, success, tags, metadata) VALUES (?,?,?,?,?,?,?,?,?)');
159
+ const insEpisodeEmbedding = dryRun ? null : db.prepare('INSERT OR REPLACE INTO episode_embeddings (episode_id, embedding) VALUES (?, ?)');
132
160
  const insPattern = db.prepare('INSERT INTO reasoning_patterns (task_type, approach, success_rate, uses, avg_reward, tags, metadata) VALUES (?,?,?,?,?,?,?)');
133
161
  const insPatEmb = db.prepare('INSERT OR REPLACE INTO pattern_embeddings (pattern_id, embedding) VALUES (?, ?)');
134
162
  const insEdge = db.prepare('INSERT INTO causal_edges (from_memory_id, from_memory_type, to_memory_id, to_memory_type, similarity, confidence, mechanism, metadata) VALUES (?,?,?,?,?,?,?,?)');
163
+ // Repair episodes produced by older distillation releases. Their metadata
164
+ // records sourceIds; if that provenance is absent, exact input matching is
165
+ // a conservative fallback. Never invent a vector or call a model.
166
+ if (!dryRun) {
167
+ const missingEpisodes = db.prepare(`
168
+ SELECT e.id, e.input, e.metadata
169
+ FROM episodes e
170
+ LEFT JOIN episode_embeddings ee ON ee.episode_id = e.id
171
+ WHERE ee.episode_id IS NULL AND e.session_id LIKE 'distill:%'
172
+ `).all();
173
+ const embeddingById = db.prepare('SELECT embedding FROM memory_entries WHERE id = ? AND embedding IS NOT NULL');
174
+ const embeddingByContent = db.prepare('SELECT embedding FROM memory_entries WHERE content = ? AND embedding IS NOT NULL LIMIT 1');
175
+ const missingCritiques = db.prepare(`
176
+ SELECT id, input FROM episodes
177
+ WHERE session_id LIKE 'distill:feedback%'
178
+ AND length(trim(coalesce(critique,''))) = 0
179
+ `).all();
180
+ const updateCritique = db.prepare('UPDATE episodes SET critique = ? WHERE id = ?');
181
+ const backfill = db.transaction(() => {
182
+ for (const episode of missingEpisodes) {
183
+ let sourceId;
184
+ try {
185
+ const metadata = JSON.parse(episode.metadata ?? '{}');
186
+ if (Array.isArray(metadata.sourceIds) && typeof metadata.sourceIds[0] === 'string') {
187
+ sourceId = metadata.sourceIds[0];
188
+ }
189
+ }
190
+ catch { /* use exact-content fallback */ }
191
+ let raw = sourceId ? embeddingById.get(sourceId)?.embedding : undefined;
192
+ if (!raw)
193
+ raw = embeddingByContent.get(episode.input ?? '')?.embedding;
194
+ const vector = parseEmbedding(raw);
195
+ if (!vector)
196
+ continue;
197
+ insEpisodeEmbedding.run(episode.id, Buffer.from(Float32Array.from(vector).buffer));
198
+ report.episodeEmbeddings++;
199
+ }
200
+ for (const episode of missingCritiques) {
201
+ updateCritique.run(feedbackCritique(episode.input ?? ''), episode.id);
202
+ }
203
+ });
204
+ backfill();
205
+ }
135
206
  let remaining = typeof maxEntries === 'number' ? maxEntries : Infinity;
136
207
  for (const ns of nsList) {
137
208
  if (remaining <= 0)
@@ -200,8 +271,14 @@ export async function runDistillation(options) {
200
271
  sourceIds: cl.members.map(m => m.id).slice(0, 25),
201
272
  paths: distilled.paths.slice(0, 10), namespace: ns, distilledBy: 'structural',
202
273
  };
203
- const epInfo = insEpisode.run(`distill:${ns}`, approach, cl.rep.content.slice(0, 2000), '', avgReward, promoted && cl.successCount > 0 ? 1 : 0, JSON.stringify(distilled.labels), JSON.stringify(provMeta));
274
+ const epInfo = insEpisode.run(`distill:${ns}`, approach, cl.rep.content.slice(0, 2000), '', cl.provenance === 'oracle:test-exec' ? feedbackCritique(cl.rep.content) : null, avgReward, promoted && cl.successCount > 0 ? 1 : 0, JSON.stringify(distilled.labels), JSON.stringify(provMeta));
204
275
  report.episodes++;
276
+ const epId = Number(epInfo.lastInsertRowid);
277
+ // ReflexionMemory.retrieveRelevant() INNER JOINs this table.
278
+ // Reuse the source embedding so every distilled episode is
279
+ // immediately retrievable without an embedding-model call.
280
+ insEpisodeEmbedding.run(epId, Buffer.from(Float32Array.from(embVec).buffer));
281
+ report.episodeEmbeddings++;
205
282
  const patInfo = insPattern.run(taskType, approach, successRate, uses, avgReward, JSON.stringify(distilled.labels), JSON.stringify(provMeta));
206
283
  const patternId = Number(patInfo.lastInsertRowid);
207
284
  report.patterns++;
@@ -217,7 +294,6 @@ export async function runDistillation(options) {
217
294
  // rowids). Explicitly typed co-occurrence / proxy-tier / non-
218
295
  // promoted: may rank retrieval, must NOT justify autonomous action
219
296
  // (ADR-174 edge contract).
220
- const epId = Number(epInfo.lastInsertRowid);
221
297
  if (prevEpId !== null) {
222
298
  insEdge.run(prevEpId, 'episode', epId, 'episode', 0, 0.3, 'co-occurrence', JSON.stringify({
223
299
  edge_type: 'cooccurrence',
@@ -1545,6 +1545,7 @@ export class WorkerDaemon extends EventEmitter {
1545
1545
  // instead of becoming their own distinct pattern.
1546
1546
  duplicatesRemoved: Math.max(0, report.processed - report.patterns),
1547
1547
  episodes: report.episodes,
1548
+ episodeEmbeddings: report.episodeEmbeddings,
1548
1549
  patternEmbeddings: report.patternEmbeddings,
1549
1550
  causalEdges: report.causalEdges,
1550
1551
  promoted: report.promoted,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@claude-flow/cli",
3
- "version": "3.32.35",
3
+ "version": "3.32.36",
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",