@sparkleideas/cli 3.1.0-alpha.66 → 3.5.15-patch.10

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 (246) hide show
  1. package/.claude/agents/core/coder.md +1 -1
  2. package/.claude/agents/core/planner.md +2 -2
  3. package/.claude/agents/core/researcher.md +1 -1
  4. package/.claude/agents/core/reviewer.md +1 -1
  5. package/.claude/agents/core/tester.md +1 -1
  6. package/.claude/agents/data/data-ml-model.md +4 -4
  7. package/.claude/agents/development/dev-backend-api.md +4 -4
  8. package/.claude/agents/documentation/docs-api-openapi.md +4 -4
  9. package/.claude/agents/github/code-review-swarm.md +2 -2
  10. package/.claude/agents/github/issue-tracker.md +2 -2
  11. package/.claude/agents/github/pr-manager.md +2 -2
  12. package/.claude/agents/github/release-manager.md +2 -2
  13. package/.claude/agents/github/workflow-automation.md +2 -2
  14. package/.claude/agents/sparc/architecture.md +3 -3
  15. package/.claude/agents/sparc/pseudocode.md +2 -2
  16. package/.claude/agents/sparc/refinement.md +3 -3
  17. package/.claude/agents/sparc/specification.md +2 -2
  18. package/.claude/agents/swarm/adaptive-coordinator.md +1 -1
  19. package/.claude/agents/swarm/hierarchical-coordinator.md +1 -1
  20. package/.claude/agents/swarm/mesh-coordinator.md +1 -1
  21. package/.claude/agents/templates/base-template-generator.md +3 -3
  22. package/.claude/agents/templates/sparc-coordinator.md +3 -3
  23. package/.claude/helpers/auto-memory-hook.mjs +365 -0
  24. package/.claude/helpers/hook-handler.cjs +271 -0
  25. package/.claude/helpers/intelligence.cjs +916 -0
  26. package/.claude/helpers/learning-service.mjs +3 -3
  27. package/.claude/helpers/session.js +8 -0
  28. package/.claude/helpers/statusline.cjs +96 -28
  29. package/.claude/settings.json +86 -141
  30. package/.claude/skills/reasoningbank-intelligence/SKILL.md +2 -2
  31. package/.claude/skills/swarm-orchestration/SKILL.md +1 -1
  32. package/README.md +952 -481
  33. package/bin/preinstall.cjs +2 -0
  34. package/dist/src/appliance/gguf-engine.d.ts +91 -0
  35. package/dist/src/appliance/gguf-engine.d.ts.map +1 -0
  36. package/dist/src/appliance/gguf-engine.js +425 -0
  37. package/dist/src/appliance/gguf-engine.js.map +1 -0
  38. package/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
  39. package/dist/src/appliance/ruvllm-bridge.d.ts.map +1 -0
  40. package/dist/src/appliance/ruvllm-bridge.js +292 -0
  41. package/dist/src/appliance/ruvllm-bridge.js.map +1 -0
  42. package/dist/src/appliance/rvfa-builder.d.ts +44 -0
  43. package/dist/src/appliance/rvfa-builder.d.ts.map +1 -0
  44. package/dist/src/appliance/rvfa-builder.js +329 -0
  45. package/dist/src/appliance/rvfa-builder.js.map +1 -0
  46. package/dist/src/appliance/rvfa-distribution.d.ts +97 -0
  47. package/dist/src/appliance/rvfa-distribution.d.ts.map +1 -0
  48. package/dist/src/appliance/rvfa-distribution.js +370 -0
  49. package/dist/src/appliance/rvfa-distribution.js.map +1 -0
  50. package/dist/src/appliance/rvfa-format.d.ts +111 -0
  51. package/dist/src/appliance/rvfa-format.d.ts.map +1 -0
  52. package/dist/src/appliance/rvfa-format.js +393 -0
  53. package/dist/src/appliance/rvfa-format.js.map +1 -0
  54. package/dist/src/appliance/rvfa-runner.d.ts +69 -0
  55. package/dist/src/appliance/rvfa-runner.d.ts.map +1 -0
  56. package/dist/src/appliance/rvfa-runner.js +237 -0
  57. package/dist/src/appliance/rvfa-runner.js.map +1 -0
  58. package/dist/src/appliance/rvfa-signing.d.ts +123 -0
  59. package/dist/src/appliance/rvfa-signing.d.ts.map +1 -0
  60. package/dist/src/appliance/rvfa-signing.js +347 -0
  61. package/dist/src/appliance/rvfa-signing.js.map +1 -0
  62. package/dist/src/commands/appliance-advanced.d.ts +9 -0
  63. package/dist/src/commands/appliance-advanced.d.ts.map +1 -0
  64. package/dist/src/commands/appliance-advanced.js +215 -0
  65. package/dist/src/commands/appliance-advanced.js.map +1 -0
  66. package/dist/src/commands/appliance.d.ts +8 -0
  67. package/dist/src/commands/appliance.d.ts.map +1 -0
  68. package/dist/src/commands/appliance.js +406 -0
  69. package/dist/src/commands/appliance.js.map +1 -0
  70. package/dist/src/commands/benchmark.js +2 -2
  71. package/dist/src/commands/benchmark.js.map +1 -1
  72. package/dist/src/commands/claims.js +1 -1
  73. package/dist/src/commands/claims.js.map +1 -1
  74. package/dist/src/commands/config.js +1 -1
  75. package/dist/src/commands/config.js.map +1 -1
  76. package/dist/src/commands/daemon.d.ts.map +1 -1
  77. package/dist/src/commands/daemon.js +28 -12
  78. package/dist/src/commands/daemon.js.map +1 -1
  79. package/dist/src/commands/deployment.js +1 -1
  80. package/dist/src/commands/deployment.js.map +1 -1
  81. package/dist/src/commands/doctor.d.ts.map +1 -1
  82. package/dist/src/commands/doctor.js +76 -45
  83. package/dist/src/commands/doctor.js.map +1 -1
  84. package/dist/src/commands/embeddings.js +1 -1
  85. package/dist/src/commands/embeddings.js.map +1 -1
  86. package/dist/src/commands/hooks.d.ts.map +1 -1
  87. package/dist/src/commands/hooks.js +84 -81
  88. package/dist/src/commands/hooks.js.map +1 -1
  89. package/dist/src/commands/index.d.ts +7 -2
  90. package/dist/src/commands/index.d.ts.map +1 -1
  91. package/dist/src/commands/index.js +11 -2
  92. package/dist/src/commands/index.js.map +1 -1
  93. package/dist/src/commands/init.d.ts.map +1 -1
  94. package/dist/src/commands/init.js +29 -34
  95. package/dist/src/commands/init.js.map +1 -1
  96. package/dist/src/commands/mcp.d.ts.map +1 -1
  97. package/dist/src/commands/mcp.js +18 -3
  98. package/dist/src/commands/mcp.js.map +1 -1
  99. package/dist/src/commands/memory.d.ts.map +1 -1
  100. package/dist/src/commands/memory.js +25 -1
  101. package/dist/src/commands/memory.js.map +1 -1
  102. package/dist/src/commands/neural.js +1 -1
  103. package/dist/src/commands/neural.js.map +1 -1
  104. package/dist/src/commands/performance.js +1 -1
  105. package/dist/src/commands/performance.js.map +1 -1
  106. package/dist/src/commands/plugins.js +1 -1
  107. package/dist/src/commands/plugins.js.map +1 -1
  108. package/dist/src/commands/providers.js +1 -1
  109. package/dist/src/commands/providers.js.map +1 -1
  110. package/dist/src/commands/security.js +1 -1
  111. package/dist/src/commands/security.js.map +1 -1
  112. package/dist/src/commands/start.js +11 -11
  113. package/dist/src/commands/start.js.map +1 -1
  114. package/dist/src/commands/status.d.ts.map +1 -1
  115. package/dist/src/commands/status.js +12 -5
  116. package/dist/src/commands/status.js.map +1 -1
  117. package/dist/src/commands/transfer-store.js +1 -1
  118. package/dist/src/commands/transfer-store.js.map +1 -1
  119. package/dist/src/index.d.ts +1 -1
  120. package/dist/src/index.js +5 -5
  121. package/dist/src/index.js.map +1 -1
  122. package/dist/src/init/claudemd-generator.js +1 -1
  123. package/dist/src/init/claudemd-generator.js.map +1 -1
  124. package/dist/src/init/executor.d.ts.map +1 -1
  125. package/dist/src/init/executor.js +230 -97
  126. package/dist/src/init/executor.js.map +1 -1
  127. package/dist/src/init/helpers-generator.d.ts +18 -0
  128. package/dist/src/init/helpers-generator.d.ts.map +1 -1
  129. package/dist/src/init/helpers-generator.js +579 -12
  130. package/dist/src/init/helpers-generator.js.map +1 -1
  131. package/dist/src/init/mcp-generator.d.ts +0 -1
  132. package/dist/src/init/mcp-generator.d.ts.map +1 -1
  133. package/dist/src/init/mcp-generator.js +33 -17
  134. package/dist/src/init/mcp-generator.js.map +1 -1
  135. package/dist/src/init/settings-generator.d.ts.map +1 -1
  136. package/dist/src/init/settings-generator.js +140 -137
  137. package/dist/src/init/settings-generator.js.map +1 -1
  138. package/dist/src/init/statusline-generator.d.ts +16 -8
  139. package/dist/src/init/statusline-generator.d.ts.map +1 -1
  140. package/dist/src/init/statusline-generator.js +506 -930
  141. package/dist/src/init/statusline-generator.js.map +1 -1
  142. package/dist/src/init/types.d.ts +8 -0
  143. package/dist/src/init/types.d.ts.map +1 -1
  144. package/dist/src/init/types.js +8 -1
  145. package/dist/src/init/types.js.map +1 -1
  146. package/dist/src/mcp-client.d.ts.map +1 -1
  147. package/dist/src/mcp-client.js +4 -0
  148. package/dist/src/mcp-client.js.map +1 -1
  149. package/dist/src/mcp-server.d.ts.map +1 -1
  150. package/dist/src/mcp-server.js +27 -1
  151. package/dist/src/mcp-server.js.map +1 -1
  152. package/dist/src/mcp-tools/agentdb-tools.d.ts +30 -0
  153. package/dist/src/mcp-tools/agentdb-tools.d.ts.map +1 -0
  154. package/dist/src/mcp-tools/agentdb-tools.js +557 -0
  155. package/dist/src/mcp-tools/agentdb-tools.js.map +1 -0
  156. package/dist/src/mcp-tools/config-tools.d.ts.map +1 -1
  157. package/dist/src/mcp-tools/config-tools.js +11 -1
  158. package/dist/src/mcp-tools/config-tools.js.map +1 -1
  159. package/dist/src/mcp-tools/coordination-tools.js +1 -1
  160. package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
  161. package/dist/src/mcp-tools/daa-tools.js +5 -5
  162. package/dist/src/mcp-tools/daa-tools.js.map +1 -1
  163. package/dist/src/mcp-tools/embeddings-tools.js +1 -1
  164. package/dist/src/mcp-tools/github-tools.js +2 -2
  165. package/dist/src/mcp-tools/github-tools.js.map +1 -1
  166. package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
  167. package/dist/src/mcp-tools/hooks-tools.js +205 -33
  168. package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
  169. package/dist/src/mcp-tools/memory-tools.d.ts.map +1 -1
  170. package/dist/src/mcp-tools/memory-tools.js +18 -1
  171. package/dist/src/mcp-tools/memory-tools.js.map +1 -1
  172. package/dist/src/mcp-tools/neural-tools.d.ts.map +1 -1
  173. package/dist/src/mcp-tools/neural-tools.js +32 -27
  174. package/dist/src/mcp-tools/neural-tools.js.map +1 -1
  175. package/dist/src/mcp-tools/performance-tools.js +1 -1
  176. package/dist/src/mcp-tools/performance-tools.js.map +1 -1
  177. package/dist/src/mcp-tools/system-tools.d.ts.map +1 -1
  178. package/dist/src/mcp-tools/system-tools.js +109 -6
  179. package/dist/src/mcp-tools/system-tools.js.map +1 -1
  180. package/dist/src/mcp-tools/task-tools.d.ts.map +1 -1
  181. package/dist/src/mcp-tools/task-tools.js +36 -0
  182. package/dist/src/mcp-tools/task-tools.js.map +1 -1
  183. package/dist/src/mcp-tools/workflow-tools.d.ts.map +1 -1
  184. package/dist/src/mcp-tools/workflow-tools.js +91 -0
  185. package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
  186. package/dist/src/memory/intelligence.d.ts.map +1 -1
  187. package/dist/src/memory/intelligence.js +34 -6
  188. package/dist/src/memory/intelligence.js.map +1 -1
  189. package/dist/src/memory/memory-bridge.d.ts +407 -0
  190. package/dist/src/memory/memory-bridge.d.ts.map +1 -0
  191. package/dist/src/memory/memory-bridge.js +1494 -0
  192. package/dist/src/memory/memory-bridge.js.map +1 -0
  193. package/dist/src/memory/memory-initializer.d.ts +10 -1
  194. package/dist/src/memory/memory-initializer.d.ts.map +1 -1
  195. package/dist/src/memory/memory-initializer.js +182 -10
  196. package/dist/src/memory/memory-initializer.js.map +1 -1
  197. package/dist/src/output.d.ts.map +1 -1
  198. package/dist/src/output.js +1 -0
  199. package/dist/src/output.js.map +1 -1
  200. package/dist/src/plugins/manager.d.ts.map +1 -1
  201. package/dist/src/plugins/manager.js +24 -7
  202. package/dist/src/plugins/manager.js.map +1 -1
  203. package/dist/src/plugins/store/discovery.js +1 -1
  204. package/dist/src/plugins/store/discovery.js.map +1 -1
  205. package/dist/src/production/error-handler.js +1 -1
  206. package/dist/src/production/error-handler.js.map +1 -1
  207. package/dist/src/runtime/headless.js +3 -3
  208. package/dist/src/runtime/headless.js.map +1 -1
  209. package/dist/src/ruvector/enhanced-model-router.d.ts.map +1 -1
  210. package/dist/src/ruvector/enhanced-model-router.js +25 -15
  211. package/dist/src/ruvector/enhanced-model-router.js.map +1 -1
  212. package/dist/src/services/agentic-flow-bridge.d.ts +50 -0
  213. package/dist/src/services/agentic-flow-bridge.d.ts.map +1 -0
  214. package/dist/src/services/agentic-flow-bridge.js +95 -0
  215. package/dist/src/services/agentic-flow-bridge.js.map +1 -0
  216. package/dist/src/services/claim-service.js +1 -1
  217. package/dist/src/services/claim-service.js.map +1 -1
  218. package/dist/src/services/container-worker-pool.d.ts.map +1 -1
  219. package/dist/src/services/container-worker-pool.js +2 -0
  220. package/dist/src/services/container-worker-pool.js.map +1 -1
  221. package/dist/src/services/ruvector-training.d.ts +2 -1
  222. package/dist/src/services/ruvector-training.d.ts.map +1 -1
  223. package/dist/src/services/ruvector-training.js +1 -2
  224. package/dist/src/services/ruvector-training.js.map +1 -1
  225. package/dist/src/services/worker-queue.d.ts.map +1 -1
  226. package/dist/src/services/worker-queue.js +2 -0
  227. package/dist/src/services/worker-queue.js.map +1 -1
  228. package/dist/src/transfer/ipfs/client.d.ts.map +1 -1
  229. package/dist/src/transfer/ipfs/client.js +8 -0
  230. package/dist/src/transfer/ipfs/client.js.map +1 -1
  231. package/dist/src/transfer/ipfs/upload.d.ts.map +1 -1
  232. package/dist/src/transfer/ipfs/upload.js +0 -2
  233. package/dist/src/transfer/ipfs/upload.js.map +1 -1
  234. package/dist/src/transfer/serialization/cfp.d.ts.map +1 -1
  235. package/dist/src/transfer/serialization/cfp.js +8 -5
  236. package/dist/src/transfer/serialization/cfp.js.map +1 -1
  237. package/dist/src/transfer/storage/gcs.d.ts.map +1 -1
  238. package/dist/src/transfer/storage/gcs.js +49 -23
  239. package/dist/src/transfer/storage/gcs.js.map +1 -1
  240. package/dist/src/types.d.ts +1 -1
  241. package/dist/src/types.js +1 -1
  242. package/dist/src/update/validator.js +1 -1
  243. package/dist/src/update/validator.js.map +1 -1
  244. package/dist/tsconfig.build.tsbuildinfo +1 -1
  245. package/dist/tsconfig.tsbuildinfo +1 -0
  246. package/package.json +16 -13
@@ -5,6 +5,7 @@
5
5
  import * as fs from 'fs';
6
6
  import * as path from 'path';
7
7
  import { fileURLToPath } from 'url';
8
+ import { createRequire } from 'module';
8
9
  import { dirname } from 'path';
9
10
  // ESM-compatible __dirname
10
11
  const __filename = fileURLToPath(import.meta.url);
@@ -12,8 +13,8 @@ const __dirname = dirname(__filename);
12
13
  import { detectPlatform, DEFAULT_INIT_OPTIONS } from './types.js';
13
14
  import { generateSettingsJson, generateSettings } from './settings-generator.js';
14
15
  import { generateMCPJson } from './mcp-generator.js';
15
- import { generateStatuslineScript, generateStatuslineHook } from './statusline-generator.js';
16
- import { generatePreCommitHook, generatePostCommitHook, generateSessionManager, generateAgentRouter, generateMemoryHelper, } from './helpers-generator.js';
16
+ import { generateStatuslineScript } from './statusline-generator.js';
17
+ import { generatePreCommitHook, generatePostCommitHook, generateSessionManager, generateAgentRouter, generateMemoryHelper, generateHookHandler, generateIntelligenceStub, generateAutoMemoryHook, generateCrossPlatformSessionManager, } from './helpers-generator.js';
17
18
  import { generateClaudeMd } from './claudemd-generator.js';
18
19
  /**
19
20
  * Skills to copy based on configuration
@@ -179,24 +180,6 @@ export async function executeInit(options) {
179
180
  if (options.components.helpers) {
180
181
  await writeHelpers(targetDir, options, result);
181
182
  }
182
- // SG-003: If settings will be generated but helpers were skipped,
183
- // generate the critical helpers that settings.json hooks reference
184
- else if (options.components.settings) {
185
- const hDir = path.join(targetDir, '.claude', 'helpers');
186
- fs.mkdirSync(hDir, { recursive: true });
187
- const criticalForSettings = {
188
- 'hook-handler.cjs': generateHookHandler(),
189
- 'auto-memory-hook.mjs': generateAutoMemoryHook(),
190
- };
191
- for (const [name, content] of Object.entries(criticalForSettings)) {
192
- const fp = path.join(hDir, name);
193
- if (!fs.existsSync(fp)) {
194
- fs.writeFileSync(fp, content, 'utf-8');
195
- try { fs.chmodSync(fp, '755'); } catch { /* T4: chmod is best-effort */ }
196
- result.created.files.push(`.claude/helpers/${name}`);
197
- }
198
- }
199
- }
200
183
  // Generate statusline
201
184
  if (options.components.statusline) {
202
185
  await writeStatusline(targetDir, options, result);
@@ -234,12 +217,9 @@ function mergeSettingsForUpgrade(existing) {
234
217
  // Platform-specific command wrappers
235
218
  // Windows: Use PowerShell-compatible commands
236
219
  // Mac/Linux: Use bash-compatible commands with 2>/dev/null
237
- const teammateIdleCmd = isWindows
238
- ? 'npx @sparkleideas/cli@latest hooks teammate-idle --auto-assign true 2>$null; exit 0'
239
- : 'npx @sparkleideas/cli@latest hooks teammate-idle --auto-assign true 2>/dev/null || true';
240
- const taskCompletedCmd = isWindows
241
- ? 'if ($env:TASK_ID) { npx @sparkleideas/cli@latest hooks task-completed --task-id $env:TASK_ID --train-patterns true 2>$null }; exit 0'
242
- : '[ -n "$TASK_ID" ] && npx @sparkleideas/cli@latest hooks task-completed --task-id "$TASK_ID" --train-patterns true 2>/dev/null || true';
220
+ // NOTE: teammateIdleCmd and taskCompletedCmd were removed.
221
+ // TeammateIdle/TaskCompleted are not valid Claude Code hook events and caused warnings.
222
+ // Agent Teams hook config lives in claudeFlow.agentTeams.hooks instead.
243
223
  // 1. Merge env vars (preserve existing, add new)
244
224
  const existingEnv = existing.env || {};
245
225
  merged.env = {
@@ -248,41 +228,73 @@ function mergeSettingsForUpgrade(existing) {
248
228
  CLAUDE_FLOW_V3_ENABLED: existingEnv.CLAUDE_FLOW_V3_ENABLED || 'true',
249
229
  CLAUDE_FLOW_HOOKS_ENABLED: existingEnv.CLAUDE_FLOW_HOOKS_ENABLED || 'true',
250
230
  };
251
- // 2. Merge hooks (preserve existing, add new Agent Teams hooks)
231
+ // 2. Merge hooks (preserve existing, add new Agent Teams + auto-memory hooks)
252
232
  const existingHooks = existing.hooks || {};
253
233
  merged.hooks = { ...existingHooks };
254
- // Add TeammateIdle hook if not present
255
- if (!existingHooks.TeammateIdle) {
256
- merged.hooks.TeammateIdle = [
257
- {
258
- hooks: [
259
- {
260
- type: 'command',
261
- command: teammateIdleCmd,
262
- timeout: 5000,
263
- continueOnError: true,
264
- },
265
- ],
266
- },
267
- ];
234
+ // Cross-platform auto-memory hook commands that resolve paths via git root.
235
+ // Uses node -e with git rev-parse so hooks work regardless of CWD (#1259, #1284).
236
+ const gitRootResolver = "var c=require('child_process'),p=require('path'),u=require('url'),r;"
237
+ + "try{r=c.execSync('git rev-parse --show-toplevel',{encoding:'utf8'}).trim()}"
238
+ + 'catch(e){r=process.cwd()}';
239
+ const autoMemoryScript = '.claude/helpers/auto-memory-hook.mjs';
240
+ const autoMemoryImportCmd = `node -e "${gitRootResolver}var f=p.join(r,'${autoMemoryScript}');import(u.pathToFileURL(f).href)" import`;
241
+ const autoMemorySyncCmd = `node -e "${gitRootResolver}var f=p.join(r,'${autoMemoryScript}');import(u.pathToFileURL(f).href)" sync`;
242
+ // Add auto-memory import to SessionStart (if not already present)
243
+ const sessionStartHooks = existingHooks.SessionStart;
244
+ const hasAutoMemoryImport = sessionStartHooks?.some(group => group.hooks?.some(h => h.command?.includes('auto-memory-hook')));
245
+ if (!hasAutoMemoryImport) {
246
+ const startHooks = merged.hooks;
247
+ if (!startHooks.SessionStart) {
248
+ startHooks.SessionStart = [{ hooks: [] }];
249
+ }
250
+ const startGroup = startHooks.SessionStart[0];
251
+ if (!startGroup.hooks)
252
+ startGroup.hooks = [];
253
+ startGroup.hooks.push({
254
+ type: 'command',
255
+ command: autoMemoryImportCmd,
256
+ timeout: 6000,
257
+ continueOnError: true,
258
+ });
268
259
  }
269
- // Add TaskCompleted hook if not present
270
- if (!existingHooks.TaskCompleted) {
271
- merged.hooks.TaskCompleted = [
272
- {
273
- hooks: [
274
- {
275
- type: 'command',
276
- command: taskCompletedCmd,
277
- timeout: 5000,
278
- continueOnError: true,
279
- },
280
- ],
281
- },
282
- ];
260
+ // Add auto-memory sync to SessionEnd (if not already present)
261
+ const sessionEndHooks = existingHooks.SessionEnd;
262
+ const hasAutoMemorySync = sessionEndHooks?.some(group => group.hooks?.some(h => h.command?.includes('auto-memory-hook')));
263
+ if (!hasAutoMemorySync) {
264
+ const endHooks = merged.hooks;
265
+ if (!endHooks.SessionEnd) {
266
+ endHooks.SessionEnd = [{ hooks: [] }];
267
+ }
268
+ const endGroup = endHooks.SessionEnd[0];
269
+ if (!endGroup.hooks)
270
+ endGroup.hooks = [];
271
+ // Insert at beginning so sync runs before other cleanup
272
+ endGroup.hooks.unshift({
273
+ type: 'command',
274
+ command: autoMemorySyncCmd,
275
+ timeout: 8000,
276
+ continueOnError: true,
277
+ });
278
+ }
279
+ // NOTE: TeammateIdle and TaskCompleted are NOT valid Claude Code hook events.
280
+ // They cause warnings when present in settings.json hooks.
281
+ // Remove them if they exist from a previous init.
282
+ delete merged.hooks.TeammateIdle;
283
+ delete merged.hooks.TaskCompleted;
284
+ // Their configuration lives in claudeFlow.agentTeams.hooks instead.
285
+ // 3. Fix statusLine config (remove invalid fields, ensure correct format)
286
+ // Claude Code only supports: type, command, padding
287
+ const existingStatusLine = existing.statusLine;
288
+ if (existingStatusLine) {
289
+ merged.statusLine = {
290
+ type: 'command',
291
+ command: existingStatusLine.command || `node -e "var c=require('child_process'),p=require('path'),r;try{r=c.execSync('git rev-parse --show-toplevel',{encoding:'utf8'}).trim()}catch(e){r=process.cwd()}var s=p.join(r,'.claude/helpers/statusline.cjs');process.argv.splice(1,0,s);require(s)"`,
292
+ // Remove invalid fields: refreshMs, enabled (not supported by Claude Code)
293
+ };
283
294
  }
284
- // 3. Merge claudeFlow settings (preserve existing, add agentTeams)
295
+ // 4. Merge claudeFlow settings (preserve existing, add agentTeams + memory)
285
296
  const existingClaudeFlow = existing.claudeFlow || {};
297
+ const existingMemory = existingClaudeFlow.memory || {};
286
298
  merged.claudeFlow = {
287
299
  ...existingClaudeFlow,
288
300
  version: existingClaudeFlow.version || '3.0.0',
@@ -303,6 +315,12 @@ function mergeSettingsForUpgrade(existing) {
303
315
  taskCompleted: { enabled: true, trainPatterns: true, notifyLead: true },
304
316
  },
305
317
  },
318
+ memory: {
319
+ ...existingMemory,
320
+ learningBridge: existingMemory.learningBridge ?? { enabled: true },
321
+ memoryGraph: existingMemory.memoryGraph ?? { enabled: true },
322
+ agentScopes: existingMemory.agentScopes ?? { enabled: true },
323
+ },
306
324
  };
307
325
  return merged;
308
326
  }
@@ -335,6 +353,72 @@ export async function executeUpgrade(targetDir, upgradeSettings = false) {
335
353
  fs.mkdirSync(fullPath, { recursive: true });
336
354
  }
337
355
  }
356
+ // 0. ALWAYS update critical helpers (force overwrite)
357
+ const sourceHelpersForUpgrade = findSourceHelpersDir();
358
+ if (sourceHelpersForUpgrade) {
359
+ const criticalHelpers = ['auto-memory-hook.mjs', 'hook-handler.cjs', 'intelligence.cjs'];
360
+ for (const helperName of criticalHelpers) {
361
+ const targetPath = path.join(targetDir, '.claude', 'helpers', helperName);
362
+ const sourcePath = path.join(sourceHelpersForUpgrade, helperName);
363
+ if (fs.existsSync(sourcePath)) {
364
+ if (fs.existsSync(targetPath)) {
365
+ result.updated.push(`.claude/helpers/${helperName}`);
366
+ }
367
+ else {
368
+ result.created.push(`.claude/helpers/${helperName}`);
369
+ }
370
+ fs.copyFileSync(sourcePath, targetPath);
371
+ try {
372
+ fs.chmodSync(targetPath, '755');
373
+ }
374
+ catch { }
375
+ }
376
+ }
377
+ }
378
+ else {
379
+ // Source not found (npx with broken paths) — use generated fallbacks
380
+ const generatedCritical = {
381
+ 'hook-handler.cjs': generateHookHandler(),
382
+ 'intelligence.cjs': generateIntelligenceStub(),
383
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
384
+ };
385
+ for (const [helperName, content] of Object.entries(generatedCritical)) {
386
+ const targetPath = path.join(targetDir, '.claude', 'helpers', helperName);
387
+ if (fs.existsSync(targetPath)) {
388
+ result.updated.push(`.claude/helpers/${helperName}`);
389
+ }
390
+ else {
391
+ result.created.push(`.claude/helpers/${helperName}`);
392
+ }
393
+ fs.writeFileSync(targetPath, content, 'utf-8');
394
+ try {
395
+ fs.chmodSync(targetPath, '755');
396
+ }
397
+ catch { }
398
+ }
399
+ }
400
+ // 0b. Generate standard helpers (session, router, memory) — SG-003
401
+ const standardHelpers = {
402
+ 'session.js': generateCrossPlatformSessionManager,
403
+ 'router.js': generateAgentRouter,
404
+ 'memory.js': generateMemoryHelper,
405
+ };
406
+ for (const [helperName, generator] of Object.entries(standardHelpers)) {
407
+ const targetPath = path.join(targetDir, '.claude', 'helpers', helperName);
408
+ if (!fs.existsSync(targetPath)) {
409
+ try {
410
+ fs.writeFileSync(targetPath, generator(), 'utf-8');
411
+ try {
412
+ fs.chmodSync(targetPath, '755');
413
+ }
414
+ catch { }
415
+ result.created.push(`.claude/helpers/${helperName}`);
416
+ }
417
+ catch {
418
+ // Non-fatal: helper generation failed
419
+ }
420
+ }
421
+ }
338
422
  // 1. ALWAYS update statusline helper (force overwrite)
339
423
  const statuslinePath = path.join(targetDir, '.claude', 'helpers', 'statusline.cjs');
340
424
  // Use default options with statusline config
@@ -436,9 +520,12 @@ export async function executeUpgrade(targetDir, upgradeSettings = false) {
436
520
  result.updated.push('.claude/settings.json');
437
521
  result.settingsUpdated = [
438
522
  'env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS',
439
- 'hooks.TeammateIdle',
440
- 'hooks.TaskCompleted',
523
+ 'hooks.SessionStart (auto-memory import)',
524
+ 'hooks.SessionEnd (auto-memory sync)',
525
+ 'hooks.TeammateIdle (removed — not a valid Claude Code hook)',
526
+ 'hooks.TaskCompleted (removed — not a valid Claude Code hook)',
441
527
  'claudeFlow.agentTeams',
528
+ 'claudeFlow.memory (learningBridge, memoryGraph, agentScopes)',
442
529
  ];
443
530
  }
444
531
  catch (settingsError) {
@@ -767,42 +854,51 @@ async function copyAgents(targetDir, options, result) {
767
854
  }
768
855
  }
769
856
  /**
770
- * Find source helpers directory
857
+ * Find source helpers directory.
858
+ * Validates that the directory contains hook-handler.cjs to avoid
859
+ * returning the target directory or an incomplete source.
771
860
  */
772
861
  function findSourceHelpersDir(sourceBaseDir) {
773
862
  const possiblePaths = [];
863
+ const SENTINEL_FILE = 'hook-handler.cjs'; // Must exist in valid source
774
864
  // If explicit source base directory is provided, check it first
775
865
  if (sourceBaseDir) {
776
866
  possiblePaths.push(path.join(sourceBaseDir, '.claude', 'helpers'));
777
867
  }
778
- // IMPORTANT: Check the package's own .claude/helpers directory
779
- // This is the primary path when running as an npm package
780
- // __dirname is typically /path/to/node_modules/@sparkleideas/cli/dist/src/init
781
- // We need to go up 3 levels to reach the package root (dist/src/init -> dist/src -> dist -> root)
868
+ // Strategy 1: require.resolve to find package root (most reliable for npx)
869
+ try {
870
+ const esmRequire = createRequire(import.meta.url);
871
+ const pkgJsonPath = esmRequire.resolve('@sparkleideas/cli/package.json');
872
+ const pkgRoot = path.dirname(pkgJsonPath);
873
+ possiblePaths.push(path.join(pkgRoot, '.claude', 'helpers'));
874
+ }
875
+ catch {
876
+ // Not installed as a package — skip
877
+ }
878
+ // Strategy 2: __dirname-based (dist/src/init -> package root)
782
879
  const packageRoot = path.resolve(__dirname, '..', '..', '..');
783
880
  const packageHelpers = path.join(packageRoot, '.claude', 'helpers');
784
- if (fs.existsSync(packageHelpers)) {
785
- possiblePaths.unshift(packageHelpers); // Add to beginning (highest priority)
786
- }
787
- // From dist/src/init -> go up to project root
881
+ possiblePaths.push(packageHelpers);
882
+ // Strategy 3: Walk up from __dirname looking for package root
788
883
  let currentDir = __dirname;
789
884
  for (let i = 0; i < 10; i++) {
790
885
  const parentDir = path.dirname(currentDir);
886
+ if (parentDir === currentDir)
887
+ break; // hit filesystem root
791
888
  const helpersPath = path.join(parentDir, '.claude', 'helpers');
792
- if (fs.existsSync(helpersPath)) {
793
- possiblePaths.push(helpersPath);
794
- }
889
+ possiblePaths.push(helpersPath);
795
890
  currentDir = parentDir;
796
891
  }
797
- // Also check relative to process.cwd() for development
892
+ // Strategy 4: Check cwd-relative paths (for local dev)
798
893
  const cwdBased = [
799
894
  path.join(process.cwd(), '.claude', 'helpers'),
800
895
  path.join(process.cwd(), '..', '.claude', 'helpers'),
801
896
  path.join(process.cwd(), '..', '..', '.claude', 'helpers'),
802
897
  ];
803
898
  possiblePaths.push(...cwdBased);
899
+ // Return first path that exists AND contains the sentinel file
804
900
  for (const p of possiblePaths) {
805
- if (fs.existsSync(p)) {
901
+ if (fs.existsSync(p) && fs.existsSync(path.join(p, SENTINEL_FILE))) {
806
902
  return p;
807
903
  }
808
904
  }
@@ -849,6 +945,9 @@ async function writeHelpers(targetDir, options, result) {
849
945
  'session.js': generateSessionManager(),
850
946
  'router.js': generateAgentRouter(),
851
947
  'memory.js': generateMemoryHelper(),
948
+ 'hook-handler.cjs': generateHookHandler(),
949
+ 'intelligence.cjs': generateIntelligenceStub(),
950
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
852
951
  };
853
952
  for (const [name, content] of Object.entries(helpers)) {
854
953
  const filePath = path.join(helpersDir, name);
@@ -911,7 +1010,6 @@ async function writeStatusline(targetDir, options, result) {
911
1010
  { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
912
1011
  { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
913
1012
  ];
914
- let copiedAdvanced = false;
915
1013
  if (sourceClaudeDir) {
916
1014
  for (const file of advancedStatuslineFiles) {
917
1015
  const sourcePath = path.join(sourceClaudeDir, file.src);
@@ -924,7 +1022,6 @@ async function writeStatusline(targetDir, options, result) {
924
1022
  fs.chmodSync(destPath, '755');
925
1023
  }
926
1024
  result.created.files.push(`.claude/${file.dest}`);
927
- copiedAdvanced = true;
928
1025
  }
929
1026
  else {
930
1027
  result.skipped.push(`.claude/${file.dest}`);
@@ -932,24 +1029,16 @@ async function writeStatusline(targetDir, options, result) {
932
1029
  }
933
1030
  }
934
1031
  }
935
- // Fall back to generating simple statusline if advanced files not available
936
- if (!copiedAdvanced) {
937
- const statuslineScript = generateStatuslineScript(options);
938
- const statuslineHook = generateStatuslineHook(options);
939
- const files = {
940
- 'statusline.cjs': statuslineScript, // .cjs for ES module project compatibility
941
- 'statusline-hook.sh': statuslineHook,
942
- };
943
- for (const [name, content] of Object.entries(files)) {
944
- const filePath = path.join(helpersDir, name);
945
- if (!fs.existsSync(filePath) || options.force) {
946
- fs.writeFileSync(filePath, content, 'utf-8');
947
- result.created.files.push(`.claude/helpers/${name}`);
948
- }
949
- else {
950
- result.skipped.push(`.claude/helpers/${name}`);
951
- }
952
- }
1032
+ // ALWAYS generate statusline.cjs settings.json references this path
1033
+ // regardless of whether advanced statusline files were also copied.
1034
+ const statuslineScript = generateStatuslineScript(options);
1035
+ const statuslinePath = path.join(helpersDir, 'statusline.cjs');
1036
+ if (!fs.existsSync(statuslinePath) || options.force) {
1037
+ fs.writeFileSync(statuslinePath, statuslineScript, 'utf-8');
1038
+ result.created.files.push('.claude/helpers/statusline.cjs');
1039
+ }
1040
+ else {
1041
+ result.skipped.push('.claude/helpers/statusline.cjs');
953
1042
  }
954
1043
  }
955
1044
  /**
@@ -961,7 +1050,7 @@ async function writeRuntimeConfig(targetDir, options, result) {
961
1050
  result.skipped.push('.claude-flow/config.yaml');
962
1051
  return;
963
1052
  }
964
- const config = `# Claude Flow V3 Runtime Configuration
1053
+ const config = `# RuFlo V3 Runtime Configuration
965
1054
  # Generated: ${new Date().toISOString()}
966
1055
 
967
1056
  version: "3.0.0"
@@ -977,6 +1066,21 @@ memory:
977
1066
  enableHNSW: ${options.runtime.enableHNSW}
978
1067
  persistPath: .claude-flow/data
979
1068
  cacheSize: 100
1069
+ # ADR-049: Self-Learning Memory
1070
+ learningBridge:
1071
+ enabled: ${options.runtime.enableLearningBridge ?? options.runtime.enableNeural}
1072
+ sonaMode: balanced
1073
+ confidenceDecayRate: 0.005
1074
+ accessBoostAmount: 0.03
1075
+ consolidationThreshold: 10
1076
+ memoryGraph:
1077
+ enabled: ${options.runtime.enableMemoryGraph ?? true}
1078
+ pageRankDamping: 0.85
1079
+ maxNodes: 5000
1080
+ similarityThreshold: 0.8
1081
+ agentScopes:
1082
+ enabled: ${options.runtime.enableAgentScopes ?? true}
1083
+ defaultScope: project
980
1084
 
981
1085
  neural:
982
1086
  enabled: ${options.runtime.enableNeural}
@@ -1126,7 +1230,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1126
1230
  result.skipped.push('.claude-flow/CAPABILITIES.md');
1127
1231
  return;
1128
1232
  }
1129
- const capabilities = `# Claude Flow V3 - Complete Capabilities Reference
1233
+ const capabilities = `# RuFlo V3 - Complete Capabilities Reference
1130
1234
  > Generated: ${new Date().toISOString()}
1131
1235
  > Full documentation: https://github.com/ruvnet/claude-flow
1132
1236
 
@@ -1146,7 +1250,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1146
1250
 
1147
1251
  ## Overview
1148
1252
 
1149
- Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordination with:
1253
+ RuFlo V3 is a domain-driven design architecture for multi-agent AI coordination with:
1150
1254
 
1151
1255
  - **15-Agent Swarm Coordination** with hierarchical and mesh topologies
1152
1256
  - **HNSW Vector Search** - 150x-12,500x faster pattern retrieval
@@ -1162,6 +1266,9 @@ Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordin
1162
1266
  | Memory Backend | ${options.runtime.memoryBackend} |
1163
1267
  | HNSW Indexing | ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'} |
1164
1268
  | Neural Learning | ${options.runtime.enableNeural ? 'Enabled' : 'Disabled'} |
1269
+ | LearningBridge | ${options.runtime.enableLearningBridge ? 'Enabled (SONA + ReasoningBank)' : 'Disabled'} |
1270
+ | Knowledge Graph | ${options.runtime.enableMemoryGraph ? 'Enabled (PageRank + Communities)' : 'Disabled'} |
1271
+ | Agent Scopes | ${options.runtime.enableAgentScopes ? 'Enabled (project/local/user)' : 'Disabled'} |
1165
1272
 
1166
1273
  ---
1167
1274
 
@@ -1362,6 +1469,25 @@ npx @sparkleideas/cli@latest doctor --fix
1362
1469
  3. **DISTILL** - LoRA learning extraction
1363
1470
  4. **CONSOLIDATE** - EWC++ preservation
1364
1471
 
1472
+ ### Self-Learning Memory (ADR-049)
1473
+
1474
+ | Component | Status | Description |
1475
+ |-----------|--------|-------------|
1476
+ | **LearningBridge** | ${options.runtime.enableLearningBridge ? '✅ Enabled' : '⏸ Disabled'} | Connects insights to SONA/ReasoningBank neural pipeline |
1477
+ | **MemoryGraph** | ${options.runtime.enableMemoryGraph ? '✅ Enabled' : '⏸ Disabled'} | PageRank knowledge graph + community detection |
1478
+ | **AgentMemoryScope** | ${options.runtime.enableAgentScopes ? '✅ Enabled' : '⏸ Disabled'} | 3-scope agent memory (project/local/user) |
1479
+
1480
+ **LearningBridge** - Insights trigger learning trajectories. Confidence evolves: +0.03 on access, -0.005/hour decay. Consolidation runs the JUDGE/DISTILL/CONSOLIDATE pipeline.
1481
+
1482
+ **MemoryGraph** - Builds a knowledge graph from entry references. PageRank identifies influential insights. Communities group related knowledge. Graph-aware ranking blends vector + structural scores.
1483
+
1484
+ **AgentMemoryScope** - Maps Claude Code 3-scope directories:
1485
+ - \`project\`: \`<gitRoot>/.claude/agent-memory/<agent>/\`
1486
+ - \`local\`: \`<gitRoot>/.claude/agent-memory-local/<agent>/\`
1487
+ - \`user\`: \`~/.claude/agent-memory/<agent>/\`
1488
+
1489
+ High-confidence insights (>0.8) can transfer between agents.
1490
+
1365
1491
  ### Memory Commands
1366
1492
  \`\`\`bash
1367
1493
  # Store pattern
@@ -1428,6 +1554,11 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1428
1554
  | MCP Response | <100ms | ✅ Achieved |
1429
1555
  | CLI Startup | <500ms | ✅ Achieved |
1430
1556
  | SONA Adaptation | <0.05ms | 🔄 In Progress |
1557
+ | Graph Build (1k) | <200ms | ✅ 2.78ms (71.9x headroom) |
1558
+ | PageRank (1k) | <100ms | ✅ 12.21ms (8.2x headroom) |
1559
+ | Insight Recording | <5ms/each | ✅ 0.12ms (41x headroom) |
1560
+ | Consolidation | <500ms | ✅ 0.26ms (1,955x headroom) |
1561
+ | Knowledge Transfer | <100ms | ✅ 1.25ms (80x headroom) |
1431
1562
 
1432
1563
  ---
1433
1564
 
@@ -1436,8 +1567,8 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1436
1567
  ### Integrated Packages
1437
1568
  | Package | Version | Purpose |
1438
1569
  |---------|---------|---------|
1439
- | agentic-flow | 2.0.1-alpha | Core coordination |
1440
- | agentdb | 2.0.0-alpha.3.4 | Vector database |
1570
+ | agentic-flow | 3.0.0-alpha.1 | Core coordination + ReasoningBank + Router |
1571
+ | agentdb | 3.0.0-alpha.10 | Vector database + 8 controllers |
1441
1572
  | @ruvector/attention | 0.1.3 | Flash attention |
1442
1573
  | @ruvector/sona | 0.1.5 | Neural learning |
1443
1574
 
@@ -1622,6 +1753,8 @@ function countEnabledHooks(options) {
1622
1753
  count++;
1623
1754
  if (hooks.stop)
1624
1755
  count++;
1756
+ if (hooks.preCompact)
1757
+ count++;
1625
1758
  if (hooks.notification)
1626
1759
  count++;
1627
1760
  return count;