@claude-flow/cli 3.10.13 → 3.10.15

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.
@@ -52,6 +52,13 @@ export declare const hooksCodemod: MCPTool;
52
52
  export declare const hooksWorkerCancel: MCPTool;
53
53
  export declare const hooksTeammateIdle: MCPTool;
54
54
  export declare const hooksTaskCompleted: MCPTool;
55
+ /**
56
+ * Unified learning-stats aggregator MCP tool (#2245 → ADR-075).
57
+ *
58
+ * One honest call across the four historical stat sources — every sub-view
59
+ * names its store and a `consistency` block flags relationships that drift.
60
+ */
61
+ export declare const hooksIntelligenceUnifiedStats: MCPTool;
55
62
  export declare const hooksTools: MCPTool[];
56
63
  export default hooksTools;
57
64
  //# sourceMappingURL=hooks-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks-tools.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/hooks-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,YAAY,CAAC;AAiBzD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CASzD;AAwqBD,eAAO,MAAM,YAAY,EAAE,OAwC1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,OA+C3B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,OA6C7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,OAuD9B,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,OAgLxB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,OAoE1B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,OA8CvB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,OA2F1B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,OAuK3B,CAAC;AAGF,eAAO,MAAM,YAAY,EAAE,OA4E1B,CAAC;AAGF,eAAO,MAAM,aAAa,EAA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AAM,iBAAiB,EAAE,OAkI/B,CAAC;AAGF,eAAO,MAAM,sBAAsB,EAAE,OAmEpC,CAAC;AAGF,eAAO,MAAM,oBAAoB,EAAE,OAyDlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,OAmEjC,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,OAuKhC,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,OA4E/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,OAwGhC,CAAC;AAGF,eAAO,MAAM,sBAAsB,EAAE,OAgNpC,CAAC;AAGF,eAAO,MAAM,sBAAsB,EAAE,OAiGpC,CAAC;AAGF,eAAO,MAAM,0BAA0B,EAAE,OA8MxC,CAAC;AAgQF,eAAO,MAAM,eAAe,EAAE,OA8C7B,CAAC;AAGF,eAAO,MAAM,mBAAmB,EAAE,OAwIjC,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,OAuD/B,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,OAkE/B,CAAC;AAiBF,eAAO,MAAM,eAAe,EAAE,OA4C7B,CAAC;AAGF,eAAO,MAAM,iBAAiB,EAAE,OAgC/B,CAAC;AAGF,eAAO,MAAM,eAAe,EAAE,OAuB7B,CAAC;AAeF,eAAO,MAAM,YAAY,EAAE,OAmI1B,CAAC;AAqBF,eAAO,MAAM,iBAAiB,EAAE,OA0C/B,CAAC;AAOF,eAAO,MAAM,iBAAiB,EAAE,OAwB/B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,OAoFhC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,EAAE,OAc3C,CAAC;AAGF,eAAO,MAAM,UAAU,EAAE,OAAO,EA6C/B,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1531,8 +1531,13 @@ export const hooksPretrain = {
1531
1531
  };
1532
1532
  scan(repoPath, 0);
1533
1533
  const elapsed = Math.round(performance.now() - startTime);
1534
- // Store extracted patterns in AgentDB
1535
- let patternsStored = 0;
1534
+ // Persist extracted patterns. Two stores get written so the user can find
1535
+ // them where they expect:
1536
+ // 1. memory-bridge `pretrain` namespace — one summary bundle
1537
+ // 2. neural store — one row PER pattern so `neural_patterns list` reflects them
1538
+ // #2245 — without (2), the dashboards reported "0 patterns" after pretrain.
1539
+ let patternsBundled = 0;
1540
+ let patternsIndexed = 0;
1536
1541
  try {
1537
1542
  const bridge = await import('../memory/memory-bridge.js');
1538
1543
  await bridge.bridgeStoreEntry({
@@ -1541,9 +1546,23 @@ export const hooksPretrain = {
1541
1546
  namespace: 'pretrain',
1542
1547
  tags: ['pretrain', depth],
1543
1548
  });
1544
- patternsStored = patterns.length;
1549
+ patternsBundled = patterns.length;
1545
1550
  }
1546
1551
  catch { /* AgentDB not available */ }
1552
+ try {
1553
+ const neural = await import('./neural-tools.js');
1554
+ const items = patterns.map((p) => ({
1555
+ name: p.length > 200 ? p.slice(0, 200) : p,
1556
+ type: 'import-pattern',
1557
+ content: p,
1558
+ metadata: { source: 'hooks_pretrain', depth },
1559
+ }));
1560
+ const result = await neural.storeNeuralPatterns(items);
1561
+ patternsIndexed = result.stored;
1562
+ }
1563
+ catch { /* neural store unavailable */ }
1564
+ // Back-compat field
1565
+ const patternsStored = patternsBundled;
1547
1566
  // #1847: when the corpus contains files but no patterns were extracted
1548
1567
  // (typical for Markdown vaults), make the source-code-only extraction
1549
1568
  // contract explicit so users don't conclude the hook system is broken.
@@ -1565,13 +1584,20 @@ export const hooksPretrain = {
1565
1584
  filesAnalyzed,
1566
1585
  totalLines,
1567
1586
  patternsExtracted: patterns.length,
1568
- patternsStored,
1587
+ patternsBundled, // #2245: 1 summary row in memory-bridge `pretrain` namespace
1588
+ patternsIndexed, // #2245: per-pattern rows in neural store — surfaced by neural_patterns list
1589
+ patternsStored, // back-compat alias for patternsBundled
1569
1590
  fileTypes: Object.entries(extCounts).sort((a, b) => b[1] - a[1]).slice(0, 15).map(([ext, count]) => ({ ext, count })),
1570
1591
  // #1847: explicit extraction contract so callers can tell pretrain
1571
1592
  // patterns apart from live trajectories and hook statusline state.
1593
+ // #2245: also call out exactly which stores got written.
1572
1594
  sources: {
1573
1595
  extractedFrom: SUPPORTED_EXTRACTION_EXTS,
1574
1596
  scope: 'pretrain-only (live trajectories + statusline are tracked separately)',
1597
+ stores: {
1598
+ 'memory-bridge:pretrain': patternsBundled > 0 ? 1 : 0, // one bundle row
1599
+ 'neural-store (neural_patterns list)': patternsIndexed,
1600
+ },
1575
1601
  },
1576
1602
  },
1577
1603
  ...(note ? { note } : {}),
@@ -4150,7 +4176,7 @@ export const hooksTeammateIdle = {
4150
4176
  };
4151
4177
  export const hooksTaskCompleted = {
4152
4178
  name: 'hooks_task-completed',
4153
- description: 'Agent Teams hook — fired when a task is marked complete; records completion and (eventually) trains patterns + notifies the team lead. Use when native TodoWrite is wrong because the work was a persisted, agent-assigned task whose outcome should feed cross-session learning and team coordination. For an in-session checklist tick, native TodoWrite is fine. (Pattern-learning is delegated to the intelligence pipeline this records the completion today.)',
4179
+ description: 'Agent Teams hook — fired when a task is marked complete. Records the completion and, when `trainPatterns:true`, feeds the outcome to the SONA + EWC++ learning pipeline (the same path used by hooks_intelligence trajectory-*). Multiple ways to drive learning exist: (a) call this with trainPatterns:true for a one-step trajectory, (b) use hooks_intelligence trajectory-start/step/end for richer multi-step learning, (c) just record an episode via memory_store if no learning is needed. Each path is honest about what it persists; check the returned `learningPath` field.',
4154
4180
  category: 'hooks',
4155
4181
  inputSchema: {
4156
4182
  type: 'object',
@@ -4159,26 +4185,98 @@ export const hooksTaskCompleted = {
4159
4185
  teammateId: { type: 'string', description: 'Teammate that completed it' },
4160
4186
  success: { type: 'boolean', description: 'Whether the task succeeded' },
4161
4187
  quality: { type: 'number', description: 'Quality score 0-1' },
4162
- trainPatterns: { type: 'boolean', description: 'Feed the outcome to the learning pipeline' },
4188
+ trainPatterns: { type: 'boolean', description: 'When true, runs the SONA + EWC++ trajectory pipeline on this completion so globalStats.patternsLearned reflects it. When false (default), only records the completion.' },
4163
4189
  notifyLead: { type: 'boolean', description: 'Notify the team lead' },
4190
+ content: { type: 'string', description: 'Optional richer task description; used as the trajectory step content when training. Defaults to the taskId.' },
4164
4191
  },
4165
4192
  required: ['taskId'],
4166
4193
  },
4167
4194
  handler: async (input) => {
4168
4195
  const taskId = String(input.taskId ?? '');
4169
- const quality = typeof input.quality === 'number' ? input.quality : (input.success === false ? 0 : 1);
4196
+ const success = input.success !== false;
4197
+ const quality = typeof input.quality === 'number' ? input.quality : (success ? 1 : 0);
4198
+ const trainPatterns = input.trainPatterns === true;
4199
+ const teammateId = input.teammateId ? String(input.teammateId) : undefined;
4200
+ // #2241 (OWASP ASI06 Memory/Context Poisoning) — task content is user-
4201
+ // supplied and feeds the SONA learning model. Cap length, strip control
4202
+ // chars, and reject obvious prompt-injection sentinels before training.
4203
+ const rawContent = typeof input.content === 'string' && input.content.trim()
4204
+ ? String(input.content)
4205
+ : `Task ${taskId} completed (quality=${quality.toFixed(2)})`;
4206
+ const content = rawContent
4207
+ // Strip ASCII control chars except newline/tab.
4208
+ .replace(/[\x00-\x08\x0B-\x1F\x7F]/g, '')
4209
+ // Cap to 4 KB — way over a typical trajectory step, well under a memory bomb.
4210
+ .slice(0, 4096);
4211
+ let patternsLearned = 0;
4212
+ let trajectoriesRecorded = 0;
4213
+ let learningPath = 'recorded-only';
4214
+ let learningError;
4215
+ if (trainPatterns) {
4216
+ // #2245 — actually feed the learning loop. Synthesize a one-step
4217
+ // trajectory from {taskId, success, quality} and run it through the
4218
+ // same SONA + EWC + globalStats++ path as hooks_intelligence trajectory-end.
4219
+ try {
4220
+ const intel = await import('../memory/intelligence.js');
4221
+ const before = intel.getIntelligenceStats();
4222
+ await intel.recordTrajectory([{
4223
+ type: 'result',
4224
+ content,
4225
+ metadata: { taskId, success, quality, teammateId },
4226
+ timestamp: Date.now(),
4227
+ }], success ? 'success' : 'failure');
4228
+ const after = intel.getIntelligenceStats();
4229
+ patternsLearned = Math.max(0, after.patternsLearned - before.patternsLearned);
4230
+ trajectoriesRecorded = Math.max(0, after.trajectoriesRecorded - before.trajectoriesRecorded);
4231
+ learningPath = 'trajectory-pipeline';
4232
+ }
4233
+ catch (err) {
4234
+ learningError = err.message;
4235
+ // Fall back to recorded-only — be honest about it.
4236
+ }
4237
+ }
4238
+ const note = trainPatterns
4239
+ ? (learningPath === 'trajectory-pipeline'
4240
+ ? `Trained via SONA + EWC++ trajectory pipeline (verdict=${success ? 'success' : 'failure'}, patternsLearned=${patternsLearned}, trajectoriesRecorded=${trajectoriesRecorded}).`
4241
+ : `trainPatterns=true but the trajectory pipeline failed (${learningError ?? 'unknown error'}). Completion recorded only.`)
4242
+ : 'Completion recorded only. Pass trainPatterns:true (or use hooks_intelligence trajectory-* directly) to feed the learning loop.';
4170
4243
  return {
4171
4244
  success: true,
4172
4245
  taskId,
4173
- patternsLearned: 0,
4246
+ patternsLearned,
4247
+ trajectoriesRecorded,
4248
+ learningPath, // 'trajectory-pipeline' | 'recorded-only'
4174
4249
  leadNotified: input.notifyLead === true,
4175
- metrics: { duration: 0, quality, learningUpdates: 0 },
4176
- note: 'completion recorded; pattern-learning is delegated to the intelligence pipeline (#1916 follow-up)',
4250
+ metrics: { duration: 0, quality, learningUpdates: patternsLearned },
4251
+ ...(learningError ? { learningError } : {}),
4252
+ note,
4177
4253
  };
4178
4254
  },
4179
4255
  };
4256
+ /**
4257
+ * Unified learning-stats aggregator MCP tool (#2245 → ADR-075).
4258
+ *
4259
+ * One honest call across the four historical stat sources — every sub-view
4260
+ * names its store and a `consistency` block flags relationships that drift.
4261
+ */
4262
+ export const hooksIntelligenceUnifiedStats = {
4263
+ name: 'hooks_intelligence_unified-stats',
4264
+ description: 'One honest view across the four learning stat sources: globalStats (`.claude-flow/neural/stats.json`), the in-memory SONA coordinator, memory-bridge AgentDB entries, and the neural-patterns store. Each sub-view names its source path. The `consistency` block notes cross-store drift (e.g. globalStats reports N patterns but neural_patterns is empty). Use this when one dashboard call should show "did learning happen" coherently — vs the four original aggregators which each return only their narrow slice. See ADR-075.',
4265
+ category: 'hooks',
4266
+ inputSchema: {
4267
+ type: 'object',
4268
+ properties: {
4269
+ verbose: { type: 'boolean', description: 'Include extended breakdowns', default: true },
4270
+ },
4271
+ },
4272
+ handler: async (_input) => {
4273
+ const intel = await import('../memory/intelligence.js');
4274
+ return intel.getUnifiedLearningStats();
4275
+ },
4276
+ };
4180
4277
  // Export all hooks tools
4181
4278
  export const hooksTools = [
4279
+ hooksIntelligenceUnifiedStats,
4182
4280
  hooksTeammateIdle,
4183
4281
  hooksTaskCompleted,
4184
4282
  hooksPreEdit,