@sparkleideas/cli 3.1.0-alpha.64 → 3.5.15-patch.2

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 +208 -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 +575 -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 +10 -3
  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 +207 -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 +13 -10
@@ -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, } 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
+ });
283
278
  }
284
- // 3. Merge claudeFlow settings (preserve existing, add agentTeams)
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
+ };
294
+ }
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,50 @@ 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
+ }
338
400
  // 1. ALWAYS update statusline helper (force overwrite)
339
401
  const statuslinePath = path.join(targetDir, '.claude', 'helpers', 'statusline.cjs');
340
402
  // Use default options with statusline config
@@ -436,9 +498,12 @@ export async function executeUpgrade(targetDir, upgradeSettings = false) {
436
498
  result.updated.push('.claude/settings.json');
437
499
  result.settingsUpdated = [
438
500
  'env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS',
439
- 'hooks.TeammateIdle',
440
- 'hooks.TaskCompleted',
501
+ 'hooks.SessionStart (auto-memory import)',
502
+ 'hooks.SessionEnd (auto-memory sync)',
503
+ 'hooks.TeammateIdle (removed — not a valid Claude Code hook)',
504
+ 'hooks.TaskCompleted (removed — not a valid Claude Code hook)',
441
505
  'claudeFlow.agentTeams',
506
+ 'claudeFlow.memory (learningBridge, memoryGraph, agentScopes)',
442
507
  ];
443
508
  }
444
509
  catch (settingsError) {
@@ -767,42 +832,51 @@ async function copyAgents(targetDir, options, result) {
767
832
  }
768
833
  }
769
834
  /**
770
- * Find source helpers directory
835
+ * Find source helpers directory.
836
+ * Validates that the directory contains hook-handler.cjs to avoid
837
+ * returning the target directory or an incomplete source.
771
838
  */
772
839
  function findSourceHelpersDir(sourceBaseDir) {
773
840
  const possiblePaths = [];
841
+ const SENTINEL_FILE = 'hook-handler.cjs'; // Must exist in valid source
774
842
  // If explicit source base directory is provided, check it first
775
843
  if (sourceBaseDir) {
776
844
  possiblePaths.push(path.join(sourceBaseDir, '.claude', 'helpers'));
777
845
  }
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)
846
+ // Strategy 1: require.resolve to find package root (most reliable for npx)
847
+ try {
848
+ const esmRequire = createRequire(import.meta.url);
849
+ const pkgJsonPath = esmRequire.resolve('@sparkleideas/cli/package.json');
850
+ const pkgRoot = path.dirname(pkgJsonPath);
851
+ possiblePaths.push(path.join(pkgRoot, '.claude', 'helpers'));
852
+ }
853
+ catch {
854
+ // Not installed as a package — skip
855
+ }
856
+ // Strategy 2: __dirname-based (dist/src/init -> package root)
782
857
  const packageRoot = path.resolve(__dirname, '..', '..', '..');
783
858
  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
859
+ possiblePaths.push(packageHelpers);
860
+ // Strategy 3: Walk up from __dirname looking for package root
788
861
  let currentDir = __dirname;
789
862
  for (let i = 0; i < 10; i++) {
790
863
  const parentDir = path.dirname(currentDir);
864
+ if (parentDir === currentDir)
865
+ break; // hit filesystem root
791
866
  const helpersPath = path.join(parentDir, '.claude', 'helpers');
792
- if (fs.existsSync(helpersPath)) {
793
- possiblePaths.push(helpersPath);
794
- }
867
+ possiblePaths.push(helpersPath);
795
868
  currentDir = parentDir;
796
869
  }
797
- // Also check relative to process.cwd() for development
870
+ // Strategy 4: Check cwd-relative paths (for local dev)
798
871
  const cwdBased = [
799
872
  path.join(process.cwd(), '.claude', 'helpers'),
800
873
  path.join(process.cwd(), '..', '.claude', 'helpers'),
801
874
  path.join(process.cwd(), '..', '..', '.claude', 'helpers'),
802
875
  ];
803
876
  possiblePaths.push(...cwdBased);
877
+ // Return first path that exists AND contains the sentinel file
804
878
  for (const p of possiblePaths) {
805
- if (fs.existsSync(p)) {
879
+ if (fs.existsSync(p) && fs.existsSync(path.join(p, SENTINEL_FILE))) {
806
880
  return p;
807
881
  }
808
882
  }
@@ -849,6 +923,9 @@ async function writeHelpers(targetDir, options, result) {
849
923
  'session.js': generateSessionManager(),
850
924
  'router.js': generateAgentRouter(),
851
925
  'memory.js': generateMemoryHelper(),
926
+ 'hook-handler.cjs': generateHookHandler(),
927
+ 'intelligence.cjs': generateIntelligenceStub(),
928
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
852
929
  };
853
930
  for (const [name, content] of Object.entries(helpers)) {
854
931
  const filePath = path.join(helpersDir, name);
@@ -911,7 +988,6 @@ async function writeStatusline(targetDir, options, result) {
911
988
  { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
912
989
  { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
913
990
  ];
914
- let copiedAdvanced = false;
915
991
  if (sourceClaudeDir) {
916
992
  for (const file of advancedStatuslineFiles) {
917
993
  const sourcePath = path.join(sourceClaudeDir, file.src);
@@ -924,7 +1000,6 @@ async function writeStatusline(targetDir, options, result) {
924
1000
  fs.chmodSync(destPath, '755');
925
1001
  }
926
1002
  result.created.files.push(`.claude/${file.dest}`);
927
- copiedAdvanced = true;
928
1003
  }
929
1004
  else {
930
1005
  result.skipped.push(`.claude/${file.dest}`);
@@ -932,24 +1007,16 @@ async function writeStatusline(targetDir, options, result) {
932
1007
  }
933
1008
  }
934
1009
  }
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
- }
1010
+ // ALWAYS generate statusline.cjs settings.json references this path
1011
+ // regardless of whether advanced statusline files were also copied.
1012
+ const statuslineScript = generateStatuslineScript(options);
1013
+ const statuslinePath = path.join(helpersDir, 'statusline.cjs');
1014
+ if (!fs.existsSync(statuslinePath) || options.force) {
1015
+ fs.writeFileSync(statuslinePath, statuslineScript, 'utf-8');
1016
+ result.created.files.push('.claude/helpers/statusline.cjs');
1017
+ }
1018
+ else {
1019
+ result.skipped.push('.claude/helpers/statusline.cjs');
953
1020
  }
954
1021
  }
955
1022
  /**
@@ -961,7 +1028,7 @@ async function writeRuntimeConfig(targetDir, options, result) {
961
1028
  result.skipped.push('.claude-flow/config.yaml');
962
1029
  return;
963
1030
  }
964
- const config = `# Claude Flow V3 Runtime Configuration
1031
+ const config = `# RuFlo V3 Runtime Configuration
965
1032
  # Generated: ${new Date().toISOString()}
966
1033
 
967
1034
  version: "3.0.0"
@@ -977,6 +1044,21 @@ memory:
977
1044
  enableHNSW: ${options.runtime.enableHNSW}
978
1045
  persistPath: .claude-flow/data
979
1046
  cacheSize: 100
1047
+ # ADR-049: Self-Learning Memory
1048
+ learningBridge:
1049
+ enabled: ${options.runtime.enableLearningBridge ?? options.runtime.enableNeural}
1050
+ sonaMode: balanced
1051
+ confidenceDecayRate: 0.005
1052
+ accessBoostAmount: 0.03
1053
+ consolidationThreshold: 10
1054
+ memoryGraph:
1055
+ enabled: ${options.runtime.enableMemoryGraph ?? true}
1056
+ pageRankDamping: 0.85
1057
+ maxNodes: 5000
1058
+ similarityThreshold: 0.8
1059
+ agentScopes:
1060
+ enabled: ${options.runtime.enableAgentScopes ?? true}
1061
+ defaultScope: project
980
1062
 
981
1063
  neural:
982
1064
  enabled: ${options.runtime.enableNeural}
@@ -1126,7 +1208,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1126
1208
  result.skipped.push('.claude-flow/CAPABILITIES.md');
1127
1209
  return;
1128
1210
  }
1129
- const capabilities = `# Claude Flow V3 - Complete Capabilities Reference
1211
+ const capabilities = `# RuFlo V3 - Complete Capabilities Reference
1130
1212
  > Generated: ${new Date().toISOString()}
1131
1213
  > Full documentation: https://github.com/ruvnet/claude-flow
1132
1214
 
@@ -1146,7 +1228,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1146
1228
 
1147
1229
  ## Overview
1148
1230
 
1149
- Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordination with:
1231
+ RuFlo V3 is a domain-driven design architecture for multi-agent AI coordination with:
1150
1232
 
1151
1233
  - **15-Agent Swarm Coordination** with hierarchical and mesh topologies
1152
1234
  - **HNSW Vector Search** - 150x-12,500x faster pattern retrieval
@@ -1162,6 +1244,9 @@ Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordin
1162
1244
  | Memory Backend | ${options.runtime.memoryBackend} |
1163
1245
  | HNSW Indexing | ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'} |
1164
1246
  | Neural Learning | ${options.runtime.enableNeural ? 'Enabled' : 'Disabled'} |
1247
+ | LearningBridge | ${options.runtime.enableLearningBridge ? 'Enabled (SONA + ReasoningBank)' : 'Disabled'} |
1248
+ | Knowledge Graph | ${options.runtime.enableMemoryGraph ? 'Enabled (PageRank + Communities)' : 'Disabled'} |
1249
+ | Agent Scopes | ${options.runtime.enableAgentScopes ? 'Enabled (project/local/user)' : 'Disabled'} |
1165
1250
 
1166
1251
  ---
1167
1252
 
@@ -1362,6 +1447,25 @@ npx @sparkleideas/cli@latest doctor --fix
1362
1447
  3. **DISTILL** - LoRA learning extraction
1363
1448
  4. **CONSOLIDATE** - EWC++ preservation
1364
1449
 
1450
+ ### Self-Learning Memory (ADR-049)
1451
+
1452
+ | Component | Status | Description |
1453
+ |-----------|--------|-------------|
1454
+ | **LearningBridge** | ${options.runtime.enableLearningBridge ? '✅ Enabled' : '⏸ Disabled'} | Connects insights to SONA/ReasoningBank neural pipeline |
1455
+ | **MemoryGraph** | ${options.runtime.enableMemoryGraph ? '✅ Enabled' : '⏸ Disabled'} | PageRank knowledge graph + community detection |
1456
+ | **AgentMemoryScope** | ${options.runtime.enableAgentScopes ? '✅ Enabled' : '⏸ Disabled'} | 3-scope agent memory (project/local/user) |
1457
+
1458
+ **LearningBridge** - Insights trigger learning trajectories. Confidence evolves: +0.03 on access, -0.005/hour decay. Consolidation runs the JUDGE/DISTILL/CONSOLIDATE pipeline.
1459
+
1460
+ **MemoryGraph** - Builds a knowledge graph from entry references. PageRank identifies influential insights. Communities group related knowledge. Graph-aware ranking blends vector + structural scores.
1461
+
1462
+ **AgentMemoryScope** - Maps Claude Code 3-scope directories:
1463
+ - \`project\`: \`<gitRoot>/.claude/agent-memory/<agent>/\`
1464
+ - \`local\`: \`<gitRoot>/.claude/agent-memory-local/<agent>/\`
1465
+ - \`user\`: \`~/.claude/agent-memory/<agent>/\`
1466
+
1467
+ High-confidence insights (>0.8) can transfer between agents.
1468
+
1365
1469
  ### Memory Commands
1366
1470
  \`\`\`bash
1367
1471
  # Store pattern
@@ -1428,6 +1532,11 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1428
1532
  | MCP Response | <100ms | ✅ Achieved |
1429
1533
  | CLI Startup | <500ms | ✅ Achieved |
1430
1534
  | SONA Adaptation | <0.05ms | 🔄 In Progress |
1535
+ | Graph Build (1k) | <200ms | ✅ 2.78ms (71.9x headroom) |
1536
+ | PageRank (1k) | <100ms | ✅ 12.21ms (8.2x headroom) |
1537
+ | Insight Recording | <5ms/each | ✅ 0.12ms (41x headroom) |
1538
+ | Consolidation | <500ms | ✅ 0.26ms (1,955x headroom) |
1539
+ | Knowledge Transfer | <100ms | ✅ 1.25ms (80x headroom) |
1431
1540
 
1432
1541
  ---
1433
1542
 
@@ -1436,8 +1545,8 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1436
1545
  ### Integrated Packages
1437
1546
  | Package | Version | Purpose |
1438
1547
  |---------|---------|---------|
1439
- | agentic-flow | 2.0.1-alpha | Core coordination |
1440
- | agentdb | 2.0.0-alpha.3.4 | Vector database |
1548
+ | agentic-flow | 3.0.0-alpha.1 | Core coordination + ReasoningBank + Router |
1549
+ | agentdb | 3.0.0-alpha.10 | Vector database + 8 controllers |
1441
1550
  | @ruvector/attention | 0.1.3 | Flash attention |
1442
1551
  | @ruvector/sona | 0.1.5 | Neural learning |
1443
1552
 
@@ -1622,6 +1731,8 @@ function countEnabledHooks(options) {
1622
1731
  count++;
1623
1732
  if (hooks.stop)
1624
1733
  count++;
1734
+ if (hooks.preCompact)
1735
+ count++;
1625
1736
  if (hooks.notification)
1626
1737
  count++;
1627
1738
  return count;