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

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 +233 -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 +587 -15
  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, } 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,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
@@ -355,6 +417,31 @@ export async function executeUpgrade(targetDir, upgradeSettings = false) {
355
417
  result.created.push('.claude/helpers/statusline.cjs');
356
418
  }
357
419
  fs.writeFileSync(statuslinePath, statuslineContent, 'utf-8');
420
+ // 1b. Generate helpers if missing (SG-003: ensure helpers for all init paths)
421
+ const helpersDir = path.join(targetDir, '.claude', 'helpers');
422
+ const helperFiles = {
423
+ 'pre-commit': generatePreCommitHook,
424
+ 'post-commit': generatePostCommitHook,
425
+ 'session.js': generateSessionManager,
426
+ 'router.js': generateAgentRouter,
427
+ 'memory.js': generateMemoryHelper,
428
+ };
429
+ for (const [name, generator] of Object.entries(helperFiles)) {
430
+ const helperPath = path.join(helpersDir, name);
431
+ if (!fs.existsSync(helperPath)) {
432
+ try {
433
+ fs.writeFileSync(helperPath, generator(), 'utf-8');
434
+ try {
435
+ fs.chmodSync(helperPath, '755');
436
+ }
437
+ catch { }
438
+ result.created.push(`.claude/helpers/${name}`);
439
+ }
440
+ catch {
441
+ // Non-fatal: skip individual helper on error
442
+ }
443
+ }
444
+ }
358
445
  // 2. Create MISSING metrics files only (preserve existing data)
359
446
  const metricsDir = path.join(targetDir, '.claude-flow', 'metrics');
360
447
  const securityDir = path.join(targetDir, '.claude-flow', 'security');
@@ -436,9 +523,12 @@ export async function executeUpgrade(targetDir, upgradeSettings = false) {
436
523
  result.updated.push('.claude/settings.json');
437
524
  result.settingsUpdated = [
438
525
  'env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS',
439
- 'hooks.TeammateIdle',
440
- 'hooks.TaskCompleted',
526
+ 'hooks.SessionStart (auto-memory import)',
527
+ 'hooks.SessionEnd (auto-memory sync)',
528
+ 'hooks.TeammateIdle (removed — not a valid Claude Code hook)',
529
+ 'hooks.TaskCompleted (removed — not a valid Claude Code hook)',
441
530
  'claudeFlow.agentTeams',
531
+ 'claudeFlow.memory (learningBridge, memoryGraph, agentScopes)',
442
532
  ];
443
533
  }
444
534
  catch (settingsError) {
@@ -767,42 +857,51 @@ async function copyAgents(targetDir, options, result) {
767
857
  }
768
858
  }
769
859
  /**
770
- * Find source helpers directory
860
+ * Find source helpers directory.
861
+ * Validates that the directory contains hook-handler.cjs to avoid
862
+ * returning the target directory or an incomplete source.
771
863
  */
772
864
  function findSourceHelpersDir(sourceBaseDir) {
773
865
  const possiblePaths = [];
866
+ const SENTINEL_FILE = 'hook-handler.cjs'; // Must exist in valid source
774
867
  // If explicit source base directory is provided, check it first
775
868
  if (sourceBaseDir) {
776
869
  possiblePaths.push(path.join(sourceBaseDir, '.claude', 'helpers'));
777
870
  }
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)
871
+ // Strategy 1: require.resolve to find package root (most reliable for npx)
872
+ try {
873
+ const esmRequire = createRequire(import.meta.url);
874
+ const pkgJsonPath = esmRequire.resolve('@sparkleideas/cli/package.json');
875
+ const pkgRoot = path.dirname(pkgJsonPath);
876
+ possiblePaths.push(path.join(pkgRoot, '.claude', 'helpers'));
877
+ }
878
+ catch {
879
+ // Not installed as a package — skip
880
+ }
881
+ // Strategy 2: __dirname-based (dist/src/init -> package root)
782
882
  const packageRoot = path.resolve(__dirname, '..', '..', '..');
783
883
  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
884
+ possiblePaths.push(packageHelpers);
885
+ // Strategy 3: Walk up from __dirname looking for package root
788
886
  let currentDir = __dirname;
789
887
  for (let i = 0; i < 10; i++) {
790
888
  const parentDir = path.dirname(currentDir);
889
+ if (parentDir === currentDir)
890
+ break; // hit filesystem root
791
891
  const helpersPath = path.join(parentDir, '.claude', 'helpers');
792
- if (fs.existsSync(helpersPath)) {
793
- possiblePaths.push(helpersPath);
794
- }
892
+ possiblePaths.push(helpersPath);
795
893
  currentDir = parentDir;
796
894
  }
797
- // Also check relative to process.cwd() for development
895
+ // Strategy 4: Check cwd-relative paths (for local dev)
798
896
  const cwdBased = [
799
897
  path.join(process.cwd(), '.claude', 'helpers'),
800
898
  path.join(process.cwd(), '..', '.claude', 'helpers'),
801
899
  path.join(process.cwd(), '..', '..', '.claude', 'helpers'),
802
900
  ];
803
901
  possiblePaths.push(...cwdBased);
902
+ // Return first path that exists AND contains the sentinel file
804
903
  for (const p of possiblePaths) {
805
- if (fs.existsSync(p)) {
904
+ if (fs.existsSync(p) && fs.existsSync(path.join(p, SENTINEL_FILE))) {
806
905
  return p;
807
906
  }
808
907
  }
@@ -849,6 +948,9 @@ async function writeHelpers(targetDir, options, result) {
849
948
  'session.js': generateSessionManager(),
850
949
  'router.js': generateAgentRouter(),
851
950
  'memory.js': generateMemoryHelper(),
951
+ 'hook-handler.cjs': generateHookHandler(),
952
+ 'intelligence.cjs': generateIntelligenceStub(),
953
+ 'auto-memory-hook.mjs': generateAutoMemoryHook(),
852
954
  };
853
955
  for (const [name, content] of Object.entries(helpers)) {
854
956
  const filePath = path.join(helpersDir, name);
@@ -911,7 +1013,6 @@ async function writeStatusline(targetDir, options, result) {
911
1013
  { src: 'statusline.sh', dest: 'statusline.sh', dir: claudeDir },
912
1014
  { src: 'statusline.mjs', dest: 'statusline.mjs', dir: claudeDir },
913
1015
  ];
914
- let copiedAdvanced = false;
915
1016
  if (sourceClaudeDir) {
916
1017
  for (const file of advancedStatuslineFiles) {
917
1018
  const sourcePath = path.join(sourceClaudeDir, file.src);
@@ -924,7 +1025,6 @@ async function writeStatusline(targetDir, options, result) {
924
1025
  fs.chmodSync(destPath, '755');
925
1026
  }
926
1027
  result.created.files.push(`.claude/${file.dest}`);
927
- copiedAdvanced = true;
928
1028
  }
929
1029
  else {
930
1030
  result.skipped.push(`.claude/${file.dest}`);
@@ -932,24 +1032,16 @@ async function writeStatusline(targetDir, options, result) {
932
1032
  }
933
1033
  }
934
1034
  }
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
- }
1035
+ // ALWAYS generate statusline.cjs settings.json references this path
1036
+ // regardless of whether advanced statusline files were also copied.
1037
+ const statuslineScript = generateStatuslineScript(options);
1038
+ const statuslinePath = path.join(helpersDir, 'statusline.cjs');
1039
+ if (!fs.existsSync(statuslinePath) || options.force) {
1040
+ fs.writeFileSync(statuslinePath, statuslineScript, 'utf-8');
1041
+ result.created.files.push('.claude/helpers/statusline.cjs');
1042
+ }
1043
+ else {
1044
+ result.skipped.push('.claude/helpers/statusline.cjs');
953
1045
  }
954
1046
  }
955
1047
  /**
@@ -961,7 +1053,7 @@ async function writeRuntimeConfig(targetDir, options, result) {
961
1053
  result.skipped.push('.claude-flow/config.yaml');
962
1054
  return;
963
1055
  }
964
- const config = `# Claude Flow V3 Runtime Configuration
1056
+ const config = `# RuFlo V3 Runtime Configuration
965
1057
  # Generated: ${new Date().toISOString()}
966
1058
 
967
1059
  version: "3.0.0"
@@ -977,6 +1069,21 @@ memory:
977
1069
  enableHNSW: ${options.runtime.enableHNSW}
978
1070
  persistPath: .claude-flow/data
979
1071
  cacheSize: 100
1072
+ # ADR-049: Self-Learning Memory
1073
+ learningBridge:
1074
+ enabled: ${options.runtime.enableLearningBridge ?? options.runtime.enableNeural}
1075
+ sonaMode: balanced
1076
+ confidenceDecayRate: 0.005
1077
+ accessBoostAmount: 0.03
1078
+ consolidationThreshold: 10
1079
+ memoryGraph:
1080
+ enabled: ${options.runtime.enableMemoryGraph ?? true}
1081
+ pageRankDamping: 0.85
1082
+ maxNodes: 5000
1083
+ similarityThreshold: 0.8
1084
+ agentScopes:
1085
+ enabled: ${options.runtime.enableAgentScopes ?? true}
1086
+ defaultScope: project
980
1087
 
981
1088
  neural:
982
1089
  enabled: ${options.runtime.enableNeural}
@@ -1126,7 +1233,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1126
1233
  result.skipped.push('.claude-flow/CAPABILITIES.md');
1127
1234
  return;
1128
1235
  }
1129
- const capabilities = `# Claude Flow V3 - Complete Capabilities Reference
1236
+ const capabilities = `# RuFlo V3 - Complete Capabilities Reference
1130
1237
  > Generated: ${new Date().toISOString()}
1131
1238
  > Full documentation: https://github.com/ruvnet/claude-flow
1132
1239
 
@@ -1146,7 +1253,7 @@ async function writeCapabilitiesDoc(targetDir, options, result) {
1146
1253
 
1147
1254
  ## Overview
1148
1255
 
1149
- Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordination with:
1256
+ RuFlo V3 is a domain-driven design architecture for multi-agent AI coordination with:
1150
1257
 
1151
1258
  - **15-Agent Swarm Coordination** with hierarchical and mesh topologies
1152
1259
  - **HNSW Vector Search** - 150x-12,500x faster pattern retrieval
@@ -1162,6 +1269,9 @@ Claude Flow V3 is a domain-driven design architecture for multi-agent AI coordin
1162
1269
  | Memory Backend | ${options.runtime.memoryBackend} |
1163
1270
  | HNSW Indexing | ${options.runtime.enableHNSW ? 'Enabled' : 'Disabled'} |
1164
1271
  | Neural Learning | ${options.runtime.enableNeural ? 'Enabled' : 'Disabled'} |
1272
+ | LearningBridge | ${options.runtime.enableLearningBridge ? 'Enabled (SONA + ReasoningBank)' : 'Disabled'} |
1273
+ | Knowledge Graph | ${options.runtime.enableMemoryGraph ? 'Enabled (PageRank + Communities)' : 'Disabled'} |
1274
+ | Agent Scopes | ${options.runtime.enableAgentScopes ? 'Enabled (project/local/user)' : 'Disabled'} |
1165
1275
 
1166
1276
  ---
1167
1277
 
@@ -1362,6 +1472,25 @@ npx @sparkleideas/cli@latest doctor --fix
1362
1472
  3. **DISTILL** - LoRA learning extraction
1363
1473
  4. **CONSOLIDATE** - EWC++ preservation
1364
1474
 
1475
+ ### Self-Learning Memory (ADR-049)
1476
+
1477
+ | Component | Status | Description |
1478
+ |-----------|--------|-------------|
1479
+ | **LearningBridge** | ${options.runtime.enableLearningBridge ? '✅ Enabled' : '⏸ Disabled'} | Connects insights to SONA/ReasoningBank neural pipeline |
1480
+ | **MemoryGraph** | ${options.runtime.enableMemoryGraph ? '✅ Enabled' : '⏸ Disabled'} | PageRank knowledge graph + community detection |
1481
+ | **AgentMemoryScope** | ${options.runtime.enableAgentScopes ? '✅ Enabled' : '⏸ Disabled'} | 3-scope agent memory (project/local/user) |
1482
+
1483
+ **LearningBridge** - Insights trigger learning trajectories. Confidence evolves: +0.03 on access, -0.005/hour decay. Consolidation runs the JUDGE/DISTILL/CONSOLIDATE pipeline.
1484
+
1485
+ **MemoryGraph** - Builds a knowledge graph from entry references. PageRank identifies influential insights. Communities group related knowledge. Graph-aware ranking blends vector + structural scores.
1486
+
1487
+ **AgentMemoryScope** - Maps Claude Code 3-scope directories:
1488
+ - \`project\`: \`<gitRoot>/.claude/agent-memory/<agent>/\`
1489
+ - \`local\`: \`<gitRoot>/.claude/agent-memory-local/<agent>/\`
1490
+ - \`user\`: \`~/.claude/agent-memory/<agent>/\`
1491
+
1492
+ High-confidence insights (>0.8) can transfer between agents.
1493
+
1365
1494
  ### Memory Commands
1366
1495
  \`\`\`bash
1367
1496
  # Store pattern
@@ -1428,6 +1557,11 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1428
1557
  | MCP Response | <100ms | ✅ Achieved |
1429
1558
  | CLI Startup | <500ms | ✅ Achieved |
1430
1559
  | SONA Adaptation | <0.05ms | 🔄 In Progress |
1560
+ | Graph Build (1k) | <200ms | ✅ 2.78ms (71.9x headroom) |
1561
+ | PageRank (1k) | <100ms | ✅ 12.21ms (8.2x headroom) |
1562
+ | Insight Recording | <5ms/each | ✅ 0.12ms (41x headroom) |
1563
+ | Consolidation | <500ms | ✅ 0.26ms (1,955x headroom) |
1564
+ | Knowledge Transfer | <100ms | ✅ 1.25ms (80x headroom) |
1431
1565
 
1432
1566
  ---
1433
1567
 
@@ -1436,8 +1570,8 @@ npx @sparkleideas/cli@latest hive-mind consensus --propose "task"
1436
1570
  ### Integrated Packages
1437
1571
  | Package | Version | Purpose |
1438
1572
  |---------|---------|---------|
1439
- | agentic-flow | 2.0.1-alpha | Core coordination |
1440
- | agentdb | 2.0.0-alpha.3.4 | Vector database |
1573
+ | agentic-flow | 3.0.0-alpha.1 | Core coordination + ReasoningBank + Router |
1574
+ | agentdb | 3.0.0-alpha.10 | Vector database + 8 controllers |
1441
1575
  | @ruvector/attention | 0.1.3 | Flash attention |
1442
1576
  | @ruvector/sona | 0.1.5 | Neural learning |
1443
1577
 
@@ -1622,6 +1756,8 @@ function countEnabledHooks(options) {
1622
1756
  count++;
1623
1757
  if (hooks.stop)
1624
1758
  count++;
1759
+ if (hooks.preCompact)
1760
+ count++;
1625
1761
  if (hooks.notification)
1626
1762
  count++;
1627
1763
  return count;