claude-flow 2.0.0-alpha.61 → 2.0.0-alpha.62
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.
- package/CHANGELOG.md +59 -1
- package/bin/claude-flow +1 -1
- package/dist/adapters/cliffy-node.d.ts.map +1 -1
- package/dist/adapters/cliffy-node.js +13 -7
- package/dist/adapters/cliffy-node.js.map +1 -1
- package/dist/agents/agent-manager.d.ts.map +1 -1
- package/dist/agents/agent-manager.js +77 -65
- package/dist/agents/agent-manager.js.map +1 -1
- package/dist/agents/agent-registry.d.ts.map +1 -1
- package/dist/agents/agent-registry.js +38 -30
- package/dist/agents/agent-registry.js.map +1 -1
- package/dist/api/claude-client.d.ts.map +1 -1
- package/dist/api/claude-client.js +22 -16
- package/dist/api/claude-client.js.map +1 -1
- package/dist/cli/agents/analyst.d.ts.map +1 -1
- package/dist/cli/agents/analyst.js +94 -114
- package/dist/cli/agents/analyst.js.map +1 -1
- package/dist/cli/agents/architect.d.ts.map +1 -1
- package/dist/cli/agents/architect.js +100 -114
- package/dist/cli/agents/architect.js.map +1 -1
- package/dist/cli/agents/base-agent.d.ts.map +1 -1
- package/dist/cli/agents/base-agent.js +27 -27
- package/dist/cli/agents/base-agent.js.map +1 -1
- package/dist/cli/agents/capabilities.d.ts.map +1 -1
- package/dist/cli/agents/capabilities.js +49 -51
- package/dist/cli/agents/capabilities.js.map +1 -1
- package/dist/cli/agents/coder.d.ts.map +1 -1
- package/dist/cli/agents/coder.js +92 -98
- package/dist/cli/agents/coder.js.map +1 -1
- package/dist/cli/agents/coordinator.d.ts.map +1 -1
- package/dist/cli/agents/coordinator.js +59 -64
- package/dist/cli/agents/coordinator.js.map +1 -1
- package/dist/cli/agents/hive-agents.d.ts.map +1 -1
- package/dist/cli/agents/hive-agents.js +22 -24
- package/dist/cli/agents/hive-agents.js.map +1 -1
- package/dist/cli/agents/index.d.ts.map +1 -1
- package/dist/cli/agents/index.js +17 -17
- package/dist/cli/agents/index.js.map +1 -1
- package/dist/cli/agents/researcher.d.ts.map +1 -1
- package/dist/cli/agents/researcher.js +41 -61
- package/dist/cli/agents/researcher.js.map +1 -1
- package/dist/cli/agents/tester.d.ts.map +1 -1
- package/dist/cli/agents/tester.js +78 -90
- package/dist/cli/agents/tester.js.map +1 -1
- package/dist/cli/cli-core.d.ts +4 -1
- package/dist/cli/cli-core.d.ts.map +1 -1
- package/dist/cli/cli-core.js +40 -39
- package/dist/cli/cli-core.js.map +1 -1
- package/dist/cli/command-registry.d.ts.map +1 -1
- package/dist/cli/command-registry.js +55 -64
- package/dist/cli/command-registry.js.map +1 -1
- package/dist/cli/commands/advanced-memory-commands.d.ts.map +1 -1
- package/dist/cli/commands/advanced-memory-commands.js +49 -40
- package/dist/cli/commands/advanced-memory-commands.js.map +1 -1
- package/dist/cli/commands/agent-simple.d.ts +3 -0
- package/dist/cli/commands/agent-simple.d.ts.map +1 -1
- package/dist/cli/commands/agent-simple.js +30 -27
- package/dist/cli/commands/agent-simple.js.map +1 -1
- package/dist/cli/commands/agent.d.ts.map +1 -1
- package/dist/cli/commands/agent.js +53 -40
- package/dist/cli/commands/agent.js.map +1 -1
- package/dist/cli/commands/claude-api.js +4 -4
- package/dist/cli/commands/claude-api.js.map +1 -1
- package/dist/cli/commands/claude.d.ts.map +1 -1
- package/dist/cli/commands/claude.js +2 -2
- package/dist/cli/commands/claude.js.map +1 -1
- package/dist/cli/commands/config-integration.d.ts +7 -1
- package/dist/cli/commands/config-integration.d.ts.map +1 -1
- package/dist/cli/commands/config-integration.js +18 -9
- package/dist/cli/commands/config-integration.js.map +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/config.js +2 -3
- package/dist/cli/commands/config.js.map +1 -1
- package/dist/cli/commands/enterprise.d.ts.map +1 -1
- package/dist/cli/commands/enterprise.js +115 -95
- package/dist/cli/commands/enterprise.js.map +1 -1
- package/dist/cli/commands/help-new.js +49 -49
- package/dist/cli/commands/help-new.js.map +1 -1
- package/dist/cli/commands/help.d.ts.map +1 -1
- package/dist/cli/commands/help.js +122 -125
- package/dist/cli/commands/help.js.map +1 -1
- package/dist/cli/commands/hive-mind/index.d.ts +1 -1
- package/dist/cli/commands/hive-mind/index.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/index.js +1 -1
- package/dist/cli/commands/hive-mind/index.js.map +1 -1
- package/dist/cli/commands/hive-mind/init.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/init.js.map +1 -1
- package/dist/cli/commands/hive-mind/optimize-memory.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/optimize-memory.js +35 -26
- package/dist/cli/commands/hive-mind/optimize-memory.js.map +1 -1
- package/dist/cli/commands/hive-mind/pause.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/pause.js +8 -6
- package/dist/cli/commands/hive-mind/pause.js.map +1 -1
- package/dist/cli/commands/hive-mind/ps.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/ps.js +17 -12
- package/dist/cli/commands/hive-mind/ps.js.map +1 -1
- package/dist/cli/commands/hive-mind/resume.js +12 -10
- package/dist/cli/commands/hive-mind/resume.js.map +1 -1
- package/dist/cli/commands/hive-mind/spawn.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/spawn.js +20 -11
- package/dist/cli/commands/hive-mind/spawn.js.map +1 -1
- package/dist/cli/commands/hive-mind/status.js +17 -22
- package/dist/cli/commands/hive-mind/status.js.map +1 -1
- package/dist/cli/commands/hive-mind/stop.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/stop.js +23 -15
- package/dist/cli/commands/hive-mind/stop.js.map +1 -1
- package/dist/cli/commands/hive-mind/task.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/task.js +25 -19
- package/dist/cli/commands/hive-mind/task.js.map +1 -1
- package/dist/cli/commands/hive-mind/wizard.d.ts.map +1 -1
- package/dist/cli/commands/hive-mind/wizard.js +86 -68
- package/dist/cli/commands/hive-mind/wizard.js.map +1 -1
- package/dist/cli/commands/hive.js +73 -38
- package/dist/cli/commands/hive.js.map +1 -1
- package/dist/cli/commands/hook-validator.d.ts.map +1 -1
- package/dist/cli/commands/hook-validator.js +4 -2
- package/dist/cli/commands/hook-validator.js.map +1 -1
- package/dist/cli/commands/hook.d.ts.map +1 -1
- package/dist/cli/commands/hook.js +8 -8
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -1
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +850 -784
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +8 -16
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/memory.d.ts.map +1 -1
- package/dist/cli/commands/memory.js +8 -8
- package/dist/cli/commands/memory.js.map +1 -1
- package/dist/cli/commands/migrate.d.ts.map +1 -1
- package/dist/cli/commands/migrate.js +3 -3
- package/dist/cli/commands/migrate.js.map +1 -1
- package/dist/cli/commands/monitor.d.ts.map +1 -1
- package/dist/cli/commands/monitor.js +50 -34
- package/dist/cli/commands/monitor.js.map +1 -1
- package/dist/cli/commands/ruv-swarm.d.ts +7 -1
- package/dist/cli/commands/ruv-swarm.d.ts.map +1 -1
- package/dist/cli/commands/ruv-swarm.js +6 -6
- package/dist/cli/commands/ruv-swarm.js.map +1 -1
- package/dist/cli/commands/session.d.ts.map +1 -1
- package/dist/cli/commands/session.js +22 -17
- package/dist/cli/commands/session.js.map +1 -1
- package/dist/cli/commands/sparc.d.ts +1 -1
- package/dist/cli/commands/sparc.d.ts.map +1 -1
- package/dist/cli/commands/sparc.js +146 -126
- package/dist/cli/commands/sparc.js.map +1 -1
- package/dist/cli/commands/start/event-emitter.js +1 -1
- package/dist/cli/commands/start/event-emitter.js.map +1 -1
- package/dist/cli/commands/start/process-manager.d.ts.map +1 -1
- package/dist/cli/commands/start/process-manager.js +20 -18
- package/dist/cli/commands/start/process-manager.js.map +1 -1
- package/dist/cli/commands/start/process-ui-simple.d.ts +4 -0
- package/dist/cli/commands/start/process-ui-simple.d.ts.map +1 -1
- package/dist/cli/commands/start/process-ui-simple.js +2 -2
- package/dist/cli/commands/start/process-ui-simple.js.map +1 -1
- package/dist/cli/commands/start/start-command.d.ts.map +1 -1
- package/dist/cli/commands/start/start-command.js +27 -15
- package/dist/cli/commands/start/start-command.js.map +1 -1
- package/dist/cli/commands/start/system-monitor.d.ts +3 -0
- package/dist/cli/commands/start/system-monitor.d.ts.map +1 -1
- package/dist/cli/commands/start/system-monitor.js +16 -18
- package/dist/cli/commands/start/system-monitor.js.map +1 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +28 -33
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/swarm-spawn.d.ts.map +1 -1
- package/dist/cli/commands/swarm-spawn.js +1 -1
- package/dist/cli/commands/swarm-spawn.js.map +1 -1
- package/dist/cli/commands/swarm.d.ts +4 -1
- package/dist/cli/commands/swarm.d.ts.map +1 -1
- package/dist/cli/commands/swarm.js +23 -18
- package/dist/cli/commands/swarm.js.map +1 -1
- package/dist/cli/commands/task.d.ts.map +1 -1
- package/dist/cli/commands/task.js.map +1 -1
- package/dist/cli/commands/workflow.d.ts.map +1 -1
- package/dist/cli/commands/workflow.js +49 -45
- package/dist/cli/commands/workflow.js.map +1 -1
- package/dist/cli/completion.d.ts +3 -0
- package/dist/cli/completion.d.ts.map +1 -1
- package/dist/cli/completion.js +15 -5
- package/dist/cli/completion.js.map +1 -1
- package/dist/cli/formatter.d.ts +3 -0
- package/dist/cli/formatter.d.ts.map +1 -1
- package/dist/cli/formatter.js +3 -3
- package/dist/cli/formatter.js.map +1 -1
- package/dist/cli/help-formatter.d.ts.map +1 -1
- package/dist/cli/help-formatter.js +8 -14
- package/dist/cli/help-formatter.js.map +1 -1
- package/dist/cli/index-remote.d.ts +4 -0
- package/dist/cli/index-remote.d.ts.map +1 -1
- package/dist/cli/index-remote.js +1 -1
- package/dist/cli/index-remote.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +32 -34
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init/batch-tools.d.ts.map +1 -1
- package/dist/cli/init/batch-tools.js.map +1 -1
- package/dist/cli/init/claude-config.d.ts.map +1 -1
- package/dist/cli/init/claude-config.js +111 -106
- package/dist/cli/init/claude-config.js.map +1 -1
- package/dist/cli/init/directory-structure.d.ts.map +1 -1
- package/dist/cli/init/directory-structure.js +3 -3
- package/dist/cli/init/directory-structure.js.map +1 -1
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/index.js +1 -1
- package/dist/cli/init/index.js.map +1 -1
- package/dist/cli/init/sparc-environment.d.ts.map +1 -1
- package/dist/cli/init/sparc-environment.js +69 -69
- package/dist/cli/init/sparc-environment.js.map +1 -1
- package/dist/cli/init/swarm-commands.d.ts.map +1 -1
- package/dist/cli/init/swarm-commands.js +1 -1
- package/dist/cli/init/swarm-commands.js.map +1 -1
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +6 -6
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/node-compat.d.ts.map +1 -1
- package/dist/cli/node-compat.js +24 -18
- package/dist/cli/node-compat.js.map +1 -1
- package/dist/cli/node-repl.d.ts +4 -0
- package/dist/cli/node-repl.d.ts.map +1 -1
- package/dist/cli/node-repl.js +24 -30
- package/dist/cli/node-repl.js.map +1 -1
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +81 -70
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/runtime-detector.d.ts.map +1 -1
- package/dist/cli/runtime-detector.js +11 -7
- package/dist/cli/runtime-detector.js.map +1 -1
- package/dist/cli/simple-cli.d.ts +4 -0
- package/dist/cli/simple-cli.d.ts.map +1 -1
- package/dist/cli/simple-cli.js +109 -95
- package/dist/cli/simple-cli.js.map +1 -1
- package/dist/cli/simple-commands/analysis.d.ts.map +1 -1
- package/dist/cli/simple-commands/analysis.js +18 -11
- package/dist/cli/simple-commands/analysis.js.map +1 -1
- package/dist/cli/simple-commands/automation.js +32 -17
- package/dist/cli/simple-commands/automation.js.map +1 -1
- package/dist/cli/simple-commands/batch-manager.js +44 -39
- package/dist/cli/simple-commands/batch-manager.js.map +1 -1
- package/dist/cli/simple-commands/config.d.ts.map +1 -1
- package/dist/cli/simple-commands/config.js +22 -21
- package/dist/cli/simple-commands/config.js.map +1 -1
- package/dist/cli/simple-commands/coordination.d.ts.map +1 -1
- package/dist/cli/simple-commands/coordination.js +12 -12
- package/dist/cli/simple-commands/coordination.js.map +1 -1
- package/dist/cli/simple-commands/fix-hook-variables.d.ts.map +1 -1
- package/dist/cli/simple-commands/fix-hook-variables.js +36 -30
- package/dist/cli/simple-commands/fix-hook-variables.js.map +1 -1
- package/dist/cli/simple-commands/github.d.ts.map +1 -1
- package/dist/cli/simple-commands/github.js +15 -15
- package/dist/cli/simple-commands/github.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.js +12 -10
- package/dist/cli/simple-commands/hive-mind/auto-save-middleware.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/communication.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/communication.js +42 -45
- package/dist/cli/simple-commands/hive-mind/communication.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/core.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/core.js +97 -89
- package/dist/cli/simple-commands/hive-mind/core.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/db-optimizer.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/db-optimizer.js +114 -59
- package/dist/cli/simple-commands/hive-mind/db-optimizer.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.js +182 -103
- package/dist/cli/simple-commands/hive-mind/mcp-wrapper.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/memory.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/memory.js +105 -75
- package/dist/cli/simple-commands/hive-mind/memory.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/performance-optimizer.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/performance-optimizer.js +45 -43
- package/dist/cli/simple-commands/hive-mind/performance-optimizer.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/queen.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind/queen.js +101 -88
- package/dist/cli/simple-commands/hive-mind/queen.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind/session-manager.js +75 -53
- package/dist/cli/simple-commands/hive-mind/session-manager.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind-optimize.js +18 -18
- package/dist/cli/simple-commands/hive-mind-optimize.js.map +1 -1
- package/dist/cli/simple-commands/hive-mind.d.ts.map +1 -1
- package/dist/cli/simple-commands/hive-mind.js +195 -135
- package/dist/cli/simple-commands/hive-mind.js.map +1 -1
- package/dist/cli/simple-commands/hook-safety.d.ts.map +1 -1
- package/dist/cli/simple-commands/hook-safety.js +19 -19
- package/dist/cli/simple-commands/hook-safety.js.map +1 -1
- package/dist/cli/simple-commands/hooks.d.ts.map +1 -1
- package/dist/cli/simple-commands/hooks.js +85 -71
- package/dist/cli/simple-commands/hooks.js.map +1 -1
- package/dist/cli/simple-commands/init/batch-init.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/batch-init.js +62 -55
- package/dist/cli/simple-commands/init/batch-init.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +2 -2
- package/dist/cli/simple-commands/init/claude-commands/optimized-slash-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-sparc-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +58 -50
- package/dist/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/slash-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/slash-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.js +34 -28
- package/dist/cli/simple-commands/init/claude-commands/sparc-commands.js.map +1 -1
- package/dist/cli/simple-commands/init/executable-wrapper.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/executable-wrapper.js +7 -4
- package/dist/cli/simple-commands/init/executable-wrapper.js.map +1 -1
- package/dist/cli/simple-commands/init/gitignore-updater.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/gitignore-updater.js +10 -9
- package/dist/cli/simple-commands/init/gitignore-updater.js.map +1 -1
- package/dist/cli/simple-commands/init/help.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/help.js.map +1 -1
- package/dist/cli/simple-commands/init/index.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/index.js +159 -103
- package/dist/cli/simple-commands/init/index.js.map +1 -1
- package/dist/cli/simple-commands/init/performance-monitor.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/performance-monitor.js +17 -18
- package/dist/cli/simple-commands/init/performance-monitor.js.map +1 -1
- package/dist/cli/simple-commands/init/rollback/backup-manager.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/rollback/backup-manager.js +19 -25
- package/dist/cli/simple-commands/init/rollback/backup-manager.js.map +1 -1
- package/dist/cli/simple-commands/init/rollback/index.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/rollback/index.js +18 -15
- package/dist/cli/simple-commands/init/rollback/index.js.map +1 -1
- package/dist/cli/simple-commands/init/rollback/recovery-manager.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/rollback/recovery-manager.js +49 -68
- package/dist/cli/simple-commands/init/rollback/recovery-manager.js.map +1 -1
- package/dist/cli/simple-commands/init/rollback/rollback-executor.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/rollback/rollback-executor.js +16 -24
- package/dist/cli/simple-commands/init/rollback/rollback-executor.js.map +1 -1
- package/dist/cli/simple-commands/init/rollback/state-tracker.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/rollback/state-tracker.js +25 -25
- package/dist/cli/simple-commands/init/rollback/state-tracker.js.map +1 -1
- package/dist/cli/simple-commands/init/sparc/roomodes-config.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/sparc/roomodes-config.js +57 -57
- package/dist/cli/simple-commands/init/sparc/roomodes-config.js.map +1 -1
- package/dist/cli/simple-commands/init/sparc/workflows.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/sparc/workflows.js +21 -21
- package/dist/cli/simple-commands/init/sparc/workflows.js.map +1 -1
- package/dist/cli/simple-commands/init/sparc-structure.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/sparc-structure.js +1 -1
- package/dist/cli/simple-commands/init/sparc-structure.js.map +1 -1
- package/dist/cli/simple-commands/init/templates/enhanced-templates.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/templates/enhanced-templates.js +69 -78
- package/dist/cli/simple-commands/init/templates/enhanced-templates.js.map +1 -1
- package/dist/cli/simple-commands/init/templates/sparc-modes.js +2 -2
- package/dist/cli/simple-commands/init/validation/config-validator.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/config-validator.js +12 -16
- package/dist/cli/simple-commands/init/validation/config-validator.js.map +1 -1
- package/dist/cli/simple-commands/init/validation/health-checker.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/health-checker.js +39 -41
- package/dist/cli/simple-commands/init/validation/health-checker.js.map +1 -1
- package/dist/cli/simple-commands/init/validation/index.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/index.js +8 -8
- package/dist/cli/simple-commands/init/validation/index.js.map +1 -1
- package/dist/cli/simple-commands/init/validation/mode-validator.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/mode-validator.js +12 -12
- package/dist/cli/simple-commands/init/validation/mode-validator.js.map +1 -1
- package/dist/cli/simple-commands/init/validation/post-init-validator.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/post-init-validator.js +13 -13
- package/dist/cli/simple-commands/init/validation/post-init-validator.js.map +1 -1
- package/dist/cli/simple-commands/init/validation/pre-init-validator.d.ts.map +1 -1
- package/dist/cli/simple-commands/init/validation/pre-init-validator.js +19 -24
- package/dist/cli/simple-commands/init/validation/pre-init-validator.js.map +1 -1
- package/dist/cli/simple-commands/mcp.js +2 -2
- package/dist/cli/simple-commands/mcp.js.map +1 -1
- package/dist/cli/simple-commands/memory.js +4 -4
- package/dist/cli/simple-commands/memory.js.map +1 -1
- package/dist/cli/simple-commands/migrate-hooks.d.ts.map +1 -1
- package/dist/cli/simple-commands/migrate-hooks.js +3 -3
- package/dist/cli/simple-commands/migrate-hooks.js.map +1 -1
- package/dist/cli/simple-commands/monitor.d.ts.map +1 -1
- package/dist/cli/simple-commands/monitor.js +34 -26
- package/dist/cli/simple-commands/monitor.js.map +1 -1
- package/dist/cli/simple-commands/process-ui-enhanced.d.ts.map +1 -1
- package/dist/cli/simple-commands/process-ui-enhanced.js +53 -39
- package/dist/cli/simple-commands/process-ui-enhanced.js.map +1 -1
- package/dist/cli/simple-commands/sparc-modes/index.js +11 -11
- package/dist/cli/simple-commands/sparc-modes/index.js.map +1 -1
- package/dist/cli/simple-commands/sparc-modes/swarm.js +50 -50
- package/dist/cli/simple-commands/sparc.d.ts.map +1 -1
- package/dist/cli/simple-commands/sparc.js +21 -11
- package/dist/cli/simple-commands/sparc.js.map +1 -1
- package/dist/cli/simple-commands/start-ui.d.ts.map +1 -1
- package/dist/cli/simple-commands/start-ui.js +5 -3
- package/dist/cli/simple-commands/start-ui.js.map +1 -1
- package/dist/cli/simple-commands/start-wrapper.d.ts.map +1 -1
- package/dist/cli/simple-commands/start-wrapper.js +1 -1
- package/dist/cli/simple-commands/start-wrapper.js.map +1 -1
- package/dist/cli/simple-commands/status.js +14 -14
- package/dist/cli/simple-commands/status.js.map +1 -1
- package/dist/cli/simple-commands/swarm-executor.d.ts.map +1 -1
- package/dist/cli/simple-commands/swarm-executor.js +19 -19
- package/dist/cli/simple-commands/swarm-executor.js.map +1 -1
- package/dist/cli/simple-commands/swarm-metrics-integration.d.ts.map +1 -1
- package/dist/cli/simple-commands/swarm-metrics-integration.js +30 -21
- package/dist/cli/simple-commands/swarm-metrics-integration.js.map +1 -1
- package/dist/cli/simple-commands/swarm-webui-integration.d.ts.map +1 -1
- package/dist/cli/simple-commands/swarm-webui-integration.js +30 -18
- package/dist/cli/simple-commands/swarm-webui-integration.js.map +1 -1
- package/dist/cli/simple-commands/swarm.d.ts.map +1 -1
- package/dist/cli/simple-commands/swarm.js +78 -67
- package/dist/cli/simple-commands/swarm.js.map +1 -1
- package/dist/cli/simple-commands/training.d.ts.map +1 -1
- package/dist/cli/simple-commands/training.js +7 -7
- package/dist/cli/simple-commands/training.js.map +1 -1
- package/dist/cli/simple-commands/web-server.d.ts.map +1 -1
- package/dist/cli/simple-commands/web-server.js +68 -66
- package/dist/cli/simple-commands/web-server.js.map +1 -1
- package/dist/cli/simple-mcp.d.ts.map +1 -1
- package/dist/cli/simple-mcp.js +2 -4
- package/dist/cli/simple-mcp.js.map +1 -1
- package/dist/cli/simple-orchestrator.d.ts +3 -0
- package/dist/cli/simple-orchestrator.d.ts.map +1 -1
- package/dist/cli/simple-orchestrator.js +36 -35
- package/dist/cli/simple-orchestrator.js.map +1 -1
- package/dist/cli/ui/compatible-ui.d.ts +4 -0
- package/dist/cli/ui/compatible-ui.d.ts.map +1 -1
- package/dist/cli/ui/compatible-ui.js +9 -8
- package/dist/cli/ui/compatible-ui.js.map +1 -1
- package/dist/cli/ui/fallback-handler.d.ts.map +1 -1
- package/dist/cli/ui/fallback-handler.js +4 -4
- package/dist/cli/ui/fallback-handler.js.map +1 -1
- package/dist/cli/ui/index.d.ts +2 -2
- package/dist/cli/ui/index.d.ts.map +1 -1
- package/dist/cli/ui/index.js +3 -3
- package/dist/cli/ui/index.js.map +1 -1
- package/dist/cli/utils/environment-detector.d.ts.map +1 -1
- package/dist/cli/utils/environment-detector.js +13 -11
- package/dist/cli/utils/environment-detector.js.map +1 -1
- package/dist/cli/utils/interactive-detector.d.ts.map +1 -1
- package/dist/cli/utils/interactive-detector.js +1 -1
- package/dist/cli/utils/interactive-detector.js.map +1 -1
- package/dist/cli/utils/prompt-defaults.d.ts.map +1 -1
- package/dist/cli/utils/prompt-defaults.js +6 -7
- package/dist/cli/utils/prompt-defaults.js.map +1 -1
- package/dist/cli/utils/safe-interactive.d.ts.map +1 -1
- package/dist/cli/utils/safe-interactive.js +7 -6
- package/dist/cli/utils/safe-interactive.js.map +1 -1
- package/dist/cli/utils.d.ts.map +1 -1
- package/dist/cli/utils.js +58 -50
- package/dist/cli/utils.js.map +1 -1
- package/dist/cli/validation-helper.d.ts.map +1 -1
- package/dist/cli/validation-helper.js.map +1 -1
- package/dist/communication/message-bus.d.ts.map +1 -1
- package/dist/communication/message-bus.js +80 -74
- package/dist/communication/message-bus.js.map +1 -1
- package/dist/config/config-manager.d.ts +3 -0
- package/dist/config/config-manager.d.ts.map +1 -1
- package/dist/config/config-manager.js +23 -6
- package/dist/config/config-manager.js.map +1 -1
- package/dist/config/ruv-swarm-config.d.ts +6 -0
- package/dist/config/ruv-swarm-config.d.ts.map +1 -1
- package/dist/config/ruv-swarm-config.js +37 -22
- package/dist/config/ruv-swarm-config.js.map +1 -1
- package/dist/config/ruv-swarm-integration.d.ts.map +1 -1
- package/dist/config/ruv-swarm-integration.js +21 -21
- package/dist/config/ruv-swarm-integration.js.map +1 -1
- package/dist/constants/agent-types.d.ts +4 -4
- package/dist/constants/agent-types.d.ts.map +1 -1
- package/dist/constants/agent-types.js +4 -4
- package/dist/constants/agent-types.js.map +1 -1
- package/dist/coordination/advanced-scheduler.d.ts.map +1 -1
- package/dist/coordination/advanced-scheduler.js +6 -10
- package/dist/coordination/advanced-scheduler.js.map +1 -1
- package/dist/coordination/advanced-task-executor.d.ts.map +1 -1
- package/dist/coordination/advanced-task-executor.js +33 -33
- package/dist/coordination/advanced-task-executor.js.map +1 -1
- package/dist/coordination/background-executor.d.ts.map +1 -1
- package/dist/coordination/background-executor.js +17 -16
- package/dist/coordination/background-executor.js.map +1 -1
- package/dist/coordination/circuit-breaker.d.ts.map +1 -1
- package/dist/coordination/circuit-breaker.js +3 -0
- package/dist/coordination/circuit-breaker.js.map +1 -1
- package/dist/coordination/conflict-resolution.d.ts.map +1 -1
- package/dist/coordination/conflict-resolution.js +10 -8
- package/dist/coordination/conflict-resolution.js.map +1 -1
- package/dist/coordination/dependency-graph.d.ts.map +1 -1
- package/dist/coordination/dependency-graph.js +4 -3
- package/dist/coordination/dependency-graph.js.map +1 -1
- package/dist/coordination/hive-orchestrator.d.ts.map +1 -1
- package/dist/coordination/hive-orchestrator.js +29 -25
- package/dist/coordination/hive-orchestrator.js.map +1 -1
- package/dist/coordination/hive-protocol.d.ts.map +1 -1
- package/dist/coordination/hive-protocol.js +22 -23
- package/dist/coordination/hive-protocol.js.map +1 -1
- package/dist/coordination/index.d.ts +1 -1
- package/dist/coordination/index.d.ts.map +1 -1
- package/dist/coordination/index.js +1 -1
- package/dist/coordination/index.js.map +1 -1
- package/dist/coordination/load-balancer.d.ts.map +1 -1
- package/dist/coordination/load-balancer.js +55 -56
- package/dist/coordination/load-balancer.js.map +1 -1
- package/dist/coordination/manager.d.ts.map +1 -1
- package/dist/coordination/manager.js +2 -8
- package/dist/coordination/manager.js.map +1 -1
- package/dist/coordination/messaging.d.ts.map +1 -1
- package/dist/coordination/messaging.js +4 -4
- package/dist/coordination/messaging.js.map +1 -1
- package/dist/coordination/metrics.d.ts.map +1 -1
- package/dist/coordination/metrics.js +11 -9
- package/dist/coordination/metrics.js.map +1 -1
- package/dist/coordination/resources.d.ts.map +1 -1
- package/dist/coordination/resources.js +10 -6
- package/dist/coordination/resources.js.map +1 -1
- package/dist/coordination/scheduler.d.ts.map +1 -1
- package/dist/coordination/scheduler.js +4 -4
- package/dist/coordination/scheduler.js.map +1 -1
- package/dist/coordination/swarm-coordinator.d.ts.map +1 -1
- package/dist/coordination/swarm-coordinator.js +32 -34
- package/dist/coordination/swarm-coordinator.js.map +1 -1
- package/dist/coordination/swarm-monitor.d.ts.map +1 -1
- package/dist/coordination/swarm-monitor.js +17 -17
- package/dist/coordination/swarm-monitor.js.map +1 -1
- package/dist/coordination/work-stealing.d.ts.map +1 -1
- package/dist/coordination/work-stealing.js +3 -0
- package/dist/coordination/work-stealing.js.map +1 -1
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +28 -31
- package/dist/core/config.js.map +1 -1
- package/dist/core/event-bus.d.ts +3 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/json-persistence.d.ts +3 -0
- package/dist/core/json-persistence.d.ts.map +1 -1
- package/dist/core/json-persistence.js +19 -23
- package/dist/core/json-persistence.js.map +1 -1
- package/dist/core/logger.d.ts +3 -0
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +2 -6
- package/dist/core/logger.js.map +1 -1
- package/dist/core/orchestrator-fixed.d.ts.map +1 -1
- package/dist/core/orchestrator-fixed.js +4 -1
- package/dist/core/orchestrator-fixed.js.map +1 -1
- package/dist/core/orchestrator.d.ts.map +1 -1
- package/dist/core/orchestrator.js +66 -33
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/core/persistence.d.ts +3 -0
- package/dist/core/persistence.d.ts.map +1 -1
- package/dist/core/persistence.js +25 -19
- package/dist/core/persistence.js.map +1 -1
- package/dist/enterprise/analytics-manager.d.ts.map +1 -1
- package/dist/enterprise/analytics-manager.js +141 -134
- package/dist/enterprise/analytics-manager.js.map +1 -1
- package/dist/enterprise/audit-manager.d.ts.map +1 -1
- package/dist/enterprise/audit-manager.js +144 -122
- package/dist/enterprise/audit-manager.js.map +1 -1
- package/dist/enterprise/cloud-manager.d.ts.map +1 -1
- package/dist/enterprise/cloud-manager.js +104 -99
- package/dist/enterprise/cloud-manager.js.map +1 -1
- package/dist/enterprise/deployment-manager.d.ts.map +1 -1
- package/dist/enterprise/deployment-manager.js +104 -97
- package/dist/enterprise/deployment-manager.js.map +1 -1
- package/dist/enterprise/index.d.ts +6 -6
- package/dist/enterprise/index.d.ts.map +1 -1
- package/dist/enterprise/project-manager.d.ts.map +1 -1
- package/dist/enterprise/project-manager.js +74 -66
- package/dist/enterprise/project-manager.js.map +1 -1
- package/dist/enterprise/security-manager.d.ts.map +1 -1
- package/dist/enterprise/security-manager.js +137 -129
- package/dist/enterprise/security-manager.js.map +1 -1
- package/dist/hive-mind/core/Agent.d.ts.map +1 -1
- package/dist/hive-mind/core/Agent.js +36 -36
- package/dist/hive-mind/core/Agent.js.map +1 -1
- package/dist/hive-mind/core/Communication.d.ts.map +1 -1
- package/dist/hive-mind/core/Communication.js +17 -17
- package/dist/hive-mind/core/Communication.js.map +1 -1
- package/dist/hive-mind/core/DatabaseManager.d.ts.map +1 -1
- package/dist/hive-mind/core/DatabaseManager.js +104 -58
- package/dist/hive-mind/core/DatabaseManager.js.map +1 -1
- package/dist/hive-mind/core/HiveMind.d.ts.map +1 -1
- package/dist/hive-mind/core/HiveMind.js +35 -35
- package/dist/hive-mind/core/HiveMind.js.map +1 -1
- package/dist/hive-mind/core/Memory.d.ts.map +1 -1
- package/dist/hive-mind/core/Memory.js +78 -71
- package/dist/hive-mind/core/Memory.js.map +1 -1
- package/dist/hive-mind/core/MemoryMonitor.d.ts.map +1 -1
- package/dist/hive-mind/core/MemoryMonitor.js +38 -38
- package/dist/hive-mind/core/MemoryMonitor.js.map +1 -1
- package/dist/hive-mind/core/Queen.d.ts.map +1 -1
- package/dist/hive-mind/core/Queen.js +110 -47
- package/dist/hive-mind/core/Queen.js.map +1 -1
- package/dist/hive-mind/integration/ConsensusEngine.d.ts.map +1 -1
- package/dist/hive-mind/integration/ConsensusEngine.js +25 -23
- package/dist/hive-mind/integration/ConsensusEngine.js.map +1 -1
- package/dist/hive-mind/integration/MCPToolWrapper.d.ts.map +1 -1
- package/dist/hive-mind/integration/MCPToolWrapper.js.map +1 -1
- package/dist/hive-mind/integration/SwarmOrchestrator.d.ts.map +1 -1
- package/dist/hive-mind/integration/SwarmOrchestrator.js +60 -58
- package/dist/hive-mind/integration/SwarmOrchestrator.js.map +1 -1
- package/dist/hive-mind/types.d.ts.map +1 -1
- package/dist/integration/mock-components.d.ts.map +1 -1
- package/dist/integration/mock-components.js +21 -21
- package/dist/integration/mock-components.js.map +1 -1
- package/dist/integration/system-integration.d.ts.map +1 -1
- package/dist/integration/system-integration.js +13 -11
- package/dist/integration/system-integration.js.map +1 -1
- package/dist/mcp/auth.d.ts +1 -1
- package/dist/mcp/auth.d.ts.map +1 -1
- package/dist/mcp/auth.js +8 -1
- package/dist/mcp/auth.js.map +1 -1
- package/dist/mcp/claude-code-wrapper.d.ts.map +1 -1
- package/dist/mcp/claude-code-wrapper.js +169 -68
- package/dist/mcp/claude-code-wrapper.js.map +1 -1
- package/dist/mcp/claude-flow-tools.d.ts.map +1 -1
- package/dist/mcp/claude-flow-tools.js +42 -3
- package/dist/mcp/claude-flow-tools.js.map +1 -1
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js.map +1 -1
- package/dist/mcp/index.d.ts +6 -6
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +9 -9
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/integrate-wrapper.d.ts.map +1 -1
- package/dist/mcp/integrate-wrapper.js +5 -7
- package/dist/mcp/integrate-wrapper.js.map +1 -1
- package/dist/mcp/lifecycle-manager.d.ts.map +1 -1
- package/dist/mcp/lifecycle-manager.js +8 -7
- package/dist/mcp/lifecycle-manager.js.map +1 -1
- package/dist/mcp/load-balancer.d.ts.map +1 -1
- package/dist/mcp/load-balancer.js +5 -1
- package/dist/mcp/load-balancer.js.map +1 -1
- package/dist/mcp/orchestration-integration.d.ts.map +1 -1
- package/dist/mcp/orchestration-integration.js +22 -9
- package/dist/mcp/orchestration-integration.js.map +1 -1
- package/dist/mcp/performance-monitor.d.ts.map +1 -1
- package/dist/mcp/performance-monitor.js +22 -19
- package/dist/mcp/performance-monitor.js.map +1 -1
- package/dist/mcp/protocol-manager.d.ts.map +1 -1
- package/dist/mcp/protocol-manager.js +8 -19
- package/dist/mcp/protocol-manager.js.map +1 -1
- package/dist/mcp/recovery/connection-health-monitor.d.ts.map +1 -1
- package/dist/mcp/recovery/connection-health-monitor.js +5 -5
- package/dist/mcp/recovery/connection-health-monitor.js.map +1 -1
- package/dist/mcp/recovery/connection-state-manager.d.ts +4 -0
- package/dist/mcp/recovery/connection-state-manager.d.ts.map +1 -1
- package/dist/mcp/recovery/connection-state-manager.js +13 -13
- package/dist/mcp/recovery/connection-state-manager.js.map +1 -1
- package/dist/mcp/recovery/fallback-coordinator.d.ts.map +1 -1
- package/dist/mcp/recovery/fallback-coordinator.js +5 -5
- package/dist/mcp/recovery/fallback-coordinator.js.map +1 -1
- package/dist/mcp/recovery/index.d.ts +4 -4
- package/dist/mcp/recovery/index.d.ts.map +1 -1
- package/dist/mcp/recovery/index.js +4 -4
- package/dist/mcp/recovery/index.js.map +1 -1
- package/dist/mcp/recovery/reconnection-manager.d.ts.map +1 -1
- package/dist/mcp/recovery/reconnection-manager.js +1 -1
- package/dist/mcp/recovery/reconnection-manager.js.map +1 -1
- package/dist/mcp/recovery/recovery-manager.d.ts.map +1 -1
- package/dist/mcp/recovery/recovery-manager.js +2 -4
- package/dist/mcp/recovery/recovery-manager.js.map +1 -1
- package/dist/mcp/router.d.ts.map +1 -1
- package/dist/mcp/router.js +3 -0
- package/dist/mcp/router.js.map +1 -1
- package/dist/mcp/ruv-swarm-tools.d.ts.map +1 -1
- package/dist/mcp/ruv-swarm-tools.js +132 -102
- package/dist/mcp/ruv-swarm-tools.js.map +1 -1
- package/dist/mcp/server-with-wrapper.d.ts +3 -0
- package/dist/mcp/server-with-wrapper.d.ts.map +1 -1
- package/dist/mcp/server-with-wrapper.js +2 -3
- package/dist/mcp/server-with-wrapper.js.map +1 -1
- package/dist/mcp/server-wrapper-mode.d.ts +5 -0
- package/dist/mcp/server-wrapper-mode.d.ts.map +1 -1
- package/dist/mcp/server-wrapper-mode.js +2 -3
- package/dist/mcp/server-wrapper-mode.js.map +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +12 -7
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/session-manager.d.ts.map +1 -1
- package/dist/mcp/session-manager.js +4 -3
- package/dist/mcp/session-manager.js.map +1 -1
- package/dist/mcp/sparc-modes.d.ts.map +1 -1
- package/dist/mcp/sparc-modes.js +15 -15
- package/dist/mcp/sparc-modes.js.map +1 -1
- package/dist/mcp/swarm-tools.d.ts.map +1 -1
- package/dist/mcp/swarm-tools.js +100 -80
- package/dist/mcp/swarm-tools.js.map +1 -1
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +28 -12
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/transports/base.d.ts.map +1 -1
- package/dist/mcp/transports/base.js +3 -0
- package/dist/mcp/transports/base.js.map +1 -1
- package/dist/mcp/transports/http.d.ts +3 -0
- package/dist/mcp/transports/http.d.ts.map +1 -1
- package/dist/mcp/transports/http.js +3 -3
- package/dist/mcp/transports/http.js.map +1 -1
- package/dist/mcp/transports/stdio.d.ts +3 -0
- package/dist/mcp/transports/stdio.d.ts.map +1 -1
- package/dist/mcp/transports/stdio.js +3 -0
- package/dist/mcp/transports/stdio.js.map +1 -1
- package/dist/memory/advanced-memory-manager.d.ts.map +1 -1
- package/dist/memory/advanced-memory-manager.js +109 -100
- package/dist/memory/advanced-memory-manager.js.map +1 -1
- package/dist/memory/backends/base.d.ts.map +1 -1
- package/dist/memory/backends/base.js +3 -0
- package/dist/memory/backends/base.js.map +1 -1
- package/dist/memory/backends/markdown.d.ts +3 -0
- package/dist/memory/backends/markdown.d.ts.map +1 -1
- package/dist/memory/backends/markdown.js +8 -8
- package/dist/memory/backends/markdown.js.map +1 -1
- package/dist/memory/backends/sqlite.d.ts +3 -0
- package/dist/memory/backends/sqlite.d.ts.map +1 -1
- package/dist/memory/backends/sqlite.js +6 -2
- package/dist/memory/backends/sqlite.js.map +1 -1
- package/dist/memory/cache.d.ts.map +1 -1
- package/dist/memory/cache.js +5 -3
- package/dist/memory/cache.js.map +1 -1
- package/dist/memory/distributed-memory.d.ts.map +1 -1
- package/dist/memory/distributed-memory.js +27 -28
- package/dist/memory/distributed-memory.js.map +1 -1
- package/dist/memory/fallback-store.d.ts.map +1 -1
- package/dist/memory/fallback-store.js.map +1 -1
- package/dist/memory/in-memory-store.d.ts.map +1 -1
- package/dist/memory/in-memory-store.js +8 -8
- package/dist/memory/in-memory-store.js.map +1 -1
- package/dist/memory/indexer.d.ts.map +1 -1
- package/dist/memory/indexer.js +4 -1
- package/dist/memory/indexer.js.map +1 -1
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/manager.js +17 -20
- package/dist/memory/manager.js.map +1 -1
- package/dist/memory/sqlite-store.js +12 -8
- package/dist/memory/sqlite-store.js.map +1 -1
- package/dist/memory/swarm-memory.d.ts.map +1 -1
- package/dist/memory/swarm-memory.js +37 -44
- package/dist/memory/swarm-memory.js.map +1 -1
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.d.ts.map +1 -1
- package/dist/migration/index.js +8 -8
- package/dist/migration/index.js.map +1 -1
- package/dist/migration/logger.d.ts.map +1 -1
- package/dist/migration/logger.js +5 -5
- package/dist/migration/logger.js.map +1 -1
- package/dist/migration/migration-analyzer.d.ts +3 -0
- package/dist/migration/migration-analyzer.d.ts.map +1 -1
- package/dist/migration/migration-analyzer.js +25 -20
- package/dist/migration/migration-analyzer.js.map +1 -1
- package/dist/migration/migration-runner.d.ts.map +1 -1
- package/dist/migration/migration-runner.js +35 -29
- package/dist/migration/migration-runner.js.map +1 -1
- package/dist/migration/migration-validator.d.ts +3 -0
- package/dist/migration/migration-validator.d.ts.map +1 -1
- package/dist/migration/migration-validator.js +22 -26
- package/dist/migration/migration-validator.js.map +1 -1
- package/dist/migration/progress-reporter.d.ts +3 -0
- package/dist/migration/progress-reporter.d.ts.map +1 -1
- package/dist/migration/progress-reporter.js +8 -8
- package/dist/migration/progress-reporter.js.map +1 -1
- package/dist/migration/rollback-manager.d.ts +3 -0
- package/dist/migration/rollback-manager.d.ts.map +1 -1
- package/dist/migration/rollback-manager.js +29 -26
- package/dist/migration/rollback-manager.js.map +1 -1
- package/dist/monitoring/diagnostics.d.ts.map +1 -1
- package/dist/monitoring/diagnostics.js +49 -37
- package/dist/monitoring/diagnostics.js.map +1 -1
- package/dist/monitoring/health-check.d.ts.map +1 -1
- package/dist/monitoring/health-check.js +24 -25
- package/dist/monitoring/health-check.js.map +1 -1
- package/dist/monitoring/real-time-monitor.d.ts.map +1 -1
- package/dist/monitoring/real-time-monitor.js +71 -58
- package/dist/monitoring/real-time-monitor.js.map +1 -1
- package/dist/resources/resource-manager.d.ts.map +1 -1
- package/dist/resources/resource-manager.js +96 -83
- package/dist/resources/resource-manager.js.map +1 -1
- package/dist/swarm/claude-flow-executor.d.ts.map +1 -1
- package/dist/swarm/claude-flow-executor.js +37 -31
- package/dist/swarm/claude-flow-executor.js.map +1 -1
- package/dist/swarm/coordinator.d.ts.map +1 -1
- package/dist/swarm/coordinator.js +330 -280
- package/dist/swarm/coordinator.js.map +1 -1
- package/dist/swarm/direct-executor.d.ts.map +1 -1
- package/dist/swarm/direct-executor.js +44 -37
- package/dist/swarm/direct-executor.js.map +1 -1
- package/dist/swarm/executor-v2.d.ts.map +1 -1
- package/dist/swarm/executor-v2.js +28 -27
- package/dist/swarm/executor-v2.js.map +1 -1
- package/dist/swarm/executor.d.ts +3 -0
- package/dist/swarm/executor.d.ts.map +1 -1
- package/dist/swarm/executor.js +58 -52
- package/dist/swarm/executor.js.map +1 -1
- package/dist/swarm/index.d.ts.map +1 -1
- package/dist/swarm/index.js +2 -2
- package/dist/swarm/index.js.map +1 -1
- package/dist/swarm/json-output-aggregator.d.ts.map +1 -1
- package/dist/swarm/json-output-aggregator.js +20 -19
- package/dist/swarm/json-output-aggregator.js.map +1 -1
- package/dist/swarm/memory.d.ts.map +1 -1
- package/dist/swarm/memory.js +67 -67
- package/dist/swarm/memory.js.map +1 -1
- package/dist/swarm/optimizations/async-file-manager.d.ts +4 -0
- package/dist/swarm/optimizations/async-file-manager.d.ts.map +1 -1
- package/dist/swarm/optimizations/async-file-manager.js +19 -23
- package/dist/swarm/optimizations/async-file-manager.js.map +1 -1
- package/dist/swarm/optimizations/circular-buffer.d.ts.map +1 -1
- package/dist/swarm/optimizations/circular-buffer.js +2 -4
- package/dist/swarm/optimizations/circular-buffer.js.map +1 -1
- package/dist/swarm/optimizations/connection-pool.d.ts.map +1 -1
- package/dist/swarm/optimizations/connection-pool.js +12 -13
- package/dist/swarm/optimizations/connection-pool.js.map +1 -1
- package/dist/swarm/optimizations/index.js +2 -2
- package/dist/swarm/optimizations/optimized-executor.d.ts.map +1 -1
- package/dist/swarm/optimizations/optimized-executor.js +23 -29
- package/dist/swarm/optimizations/optimized-executor.js.map +1 -1
- package/dist/swarm/optimizations/ttl-map.d.ts.map +1 -1
- package/dist/swarm/optimizations/ttl-map.js +4 -4
- package/dist/swarm/optimizations/ttl-map.js.map +1 -1
- package/dist/swarm/prompt-cli.d.ts.map +1 -1
- package/dist/swarm/prompt-cli.js +18 -13
- package/dist/swarm/prompt-cli.js.map +1 -1
- package/dist/swarm/prompt-copier-enhanced.d.ts.map +1 -1
- package/dist/swarm/prompt-copier-enhanced.js +12 -12
- package/dist/swarm/prompt-copier-enhanced.js.map +1 -1
- package/dist/swarm/prompt-copier.d.ts.map +1 -1
- package/dist/swarm/prompt-copier.js +15 -18
- package/dist/swarm/prompt-copier.js.map +1 -1
- package/dist/swarm/prompt-manager.d.ts.map +1 -1
- package/dist/swarm/prompt-manager.js +27 -21
- package/dist/swarm/prompt-manager.js.map +1 -1
- package/dist/swarm/prompt-utils.d.ts.map +1 -1
- package/dist/swarm/prompt-utils.js +34 -32
- package/dist/swarm/prompt-utils.js.map +1 -1
- package/dist/swarm/sparc-executor.d.ts.map +1 -1
- package/dist/swarm/sparc-executor.js +189 -123
- package/dist/swarm/sparc-executor.js.map +1 -1
- package/dist/swarm/strategies/auto.d.ts.map +1 -1
- package/dist/swarm/strategies/auto.js +105 -86
- package/dist/swarm/strategies/auto.js.map +1 -1
- package/dist/swarm/strategies/base.d.ts.map +1 -1
- package/dist/swarm/strategies/base.js +14 -11
- package/dist/swarm/strategies/base.js.map +1 -1
- package/dist/swarm/strategies/research.d.ts.map +1 -1
- package/dist/swarm/strategies/research.js +76 -71
- package/dist/swarm/strategies/research.js.map +1 -1
- package/dist/swarm/types.d.ts.map +1 -1
- package/dist/swarm/types.js +3 -0
- package/dist/swarm/types.js.map +1 -1
- package/dist/swarm/workers/copy-worker.js +4 -4
- package/dist/swarm/workers/copy-worker.js.map +1 -1
- package/dist/task/commands.d.ts.map +1 -1
- package/dist/task/commands.js +11 -7
- package/dist/task/commands.js.map +1 -1
- package/dist/task/coordination.d.ts.map +1 -1
- package/dist/task/coordination.js +75 -70
- package/dist/task/coordination.js.map +1 -1
- package/dist/task/engine.d.ts.map +1 -1
- package/dist/task/engine.js +34 -32
- package/dist/task/engine.js.map +1 -1
- package/dist/task/index.d.ts +3 -3
- package/dist/task/index.d.ts.map +1 -1
- package/dist/task/index.js +11 -11
- package/dist/task/index.js.map +1 -1
- package/dist/terminal/adapters/native.d.ts.map +1 -1
- package/dist/terminal/adapters/native.js +6 -6
- package/dist/terminal/adapters/native.js.map +1 -1
- package/dist/terminal/adapters/vscode.d.ts +3 -0
- package/dist/terminal/adapters/vscode.d.ts.map +1 -1
- package/dist/terminal/adapters/vscode.js +6 -4
- package/dist/terminal/adapters/vscode.js.map +1 -1
- package/dist/terminal/manager.d.ts.map +1 -1
- package/dist/terminal/manager.js +6 -8
- package/dist/terminal/manager.js.map +1 -1
- package/dist/terminal/pool.d.ts.map +1 -1
- package/dist/terminal/pool.js +3 -0
- package/dist/terminal/pool.js.map +1 -1
- package/dist/terminal/session.d.ts.map +1 -1
- package/dist/terminal/session.js +6 -2
- package/dist/terminal/session.js.map +1 -1
- package/dist/ui/hive-dashboard.d.ts.map +1 -1
- package/dist/ui/hive-dashboard.js +52 -33
- package/dist/ui/hive-dashboard.js.map +1 -1
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +1 -1
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/helpers.d.ts +3 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/utils/helpers.js +5 -8
- package/dist/utils/helpers.js.map +1 -1
- package/dist/utils/npx-isolated-cache.js +3 -3
- package/dist/utils/npx-isolated-cache.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +8 -4
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/type-guards.d.ts +1 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js +11 -10
- package/dist/utils/type-guards.js.map +1 -1
- package/package.json +7 -6
- package/src/adapters/cliffy-node.ts +27 -22
- package/src/agents/agent-manager.ts +145 -121
- package/src/agents/agent-registry.ts +77 -70
- package/src/api/claude-client.ts +59 -38
- package/src/api/routes/analysis.js +750 -735
- package/src/cli/__tests__/command-registry.test.js +42 -32
- package/src/cli/__tests__/simple-cli.test.js +42 -37
- package/src/cli/__tests__/utils.test.js +9 -9
- package/src/cli/agents/README.md +30 -4
- package/src/cli/agents/analyst.ts +161 -163
- package/src/cli/agents/architect.ts +126 -131
- package/src/cli/agents/base-agent.ts +48 -47
- package/src/cli/agents/capabilities.ts +87 -85
- package/src/cli/agents/coder.ts +127 -120
- package/src/cli/agents/coordinator.ts +72 -72
- package/src/cli/agents/hive-agents.ts +96 -70
- package/src/cli/agents/index.ts +70 -55
- package/src/cli/agents/researcher.ts +63 -74
- package/src/cli/agents/tester.ts +91 -98
- package/src/cli/cli-core.ts +56 -47
- package/src/cli/command-registry.js +82 -83
- package/src/cli/commands/advanced-memory-commands.ts +210 -142
- package/src/cli/commands/agent-simple.ts +146 -114
- package/src/cli/commands/agent.ts +119 -95
- package/src/cli/commands/claude-api.ts +19 -15
- package/src/cli/commands/claude.ts +96 -88
- package/src/cli/commands/config-integration.ts +120 -101
- package/src/cli/commands/config.ts +10 -8
- package/src/cli/commands/enterprise.ts +323 -187
- package/src/cli/commands/help-new.ts +57 -55
- package/src/cli/commands/help.ts +162 -159
- package/src/cli/commands/hive-mind/index.ts +3 -3
- package/src/cli/commands/hive-mind/init.ts +19 -12
- package/src/cli/commands/hive-mind/optimize-memory.ts +83 -53
- package/src/cli/commands/hive-mind/pause.ts +27 -25
- package/src/cli/commands/hive-mind/ps.ts +43 -37
- package/src/cli/commands/hive-mind/resume.ts +26 -26
- package/src/cli/commands/hive-mind/spawn.ts +37 -29
- package/src/cli/commands/hive-mind/status.ts +51 -51
- package/src/cli/commands/hive-mind/stop.ts +56 -51
- package/src/cli/commands/hive-mind/task.ts +65 -54
- package/src/cli/commands/hive-mind/wizard.ts +181 -167
- package/src/cli/commands/hive.ts +136 -96
- package/src/cli/commands/hook-types.ts +2 -2
- package/src/cli/commands/hook-validator.ts +8 -4
- package/src/cli/commands/hook.ts +44 -42
- package/src/cli/commands/index.ts +1162 -1031
- package/src/cli/commands/mcp.ts +105 -94
- package/src/cli/commands/memory.ts +24 -21
- package/src/cli/commands/migrate.ts +24 -24
- package/src/cli/commands/monitor.ts +123 -93
- package/src/cli/commands/ruv-swarm.ts +131 -122
- package/src/cli/commands/session.ts +60 -45
- package/src/cli/commands/sparc.ts +170 -139
- package/src/cli/commands/start/event-emitter.ts +2 -2
- package/src/cli/commands/start/index.ts +1 -1
- package/src/cli/commands/start/process-manager.ts +30 -47
- package/src/cli/commands/start/process-ui-simple.ts +60 -49
- package/src/cli/commands/start/process-ui.ts +1 -1
- package/src/cli/commands/start/start-command.ts +104 -75
- package/src/cli/commands/start/system-monitor.ts +35 -41
- package/src/cli/commands/start/types.ts +3 -3
- package/src/cli/commands/start.ts +1 -1
- package/src/cli/commands/status.ts +67 -67
- package/src/cli/commands/swarm-spawn.ts +21 -12
- package/src/cli/commands/swarm.ts +221 -150
- package/src/cli/commands/task.ts +55 -55
- package/src/cli/commands/workflow.ts +174 -157
- package/src/cli/completion.ts +34 -19
- package/src/cli/create-enhanced-task.js +49 -17
- package/src/cli/formatter.ts +38 -37
- package/src/cli/help-formatter.js +23 -33
- package/src/cli/help-formatter.ts +24 -34
- package/src/cli/help-text.js +69 -60
- package/src/cli/index-remote.ts +12 -9
- package/src/cli/index.ts +77 -67
- package/src/cli/init/batch-tools.ts +4 -5
- package/src/cli/init/claude-config.ts +125 -118
- package/src/cli/init/directory-structure.ts +10 -11
- package/src/cli/init/index.ts +13 -13
- package/src/cli/init/sparc-environment.ts +90 -74
- package/src/cli/init/swarm-commands.ts +5 -6
- package/src/cli/init/utils.ts +1 -1
- package/src/cli/main.ts +9 -10
- package/src/cli/node-compat.js +26 -19
- package/src/cli/node-repl.ts +104 -87
- package/src/cli/repl.ts +190 -158
- package/src/cli/runtime-detector.js +24 -19
- package/src/cli/simple-cli.js +460 -385
- package/src/cli/simple-cli.ts +426 -366
- package/src/cli/simple-commands/__tests__/agent.test.js +49 -55
- package/src/cli/simple-commands/__tests__/memory.test.js +4 -401
- package/src/cli/simple-commands/__tests__/swarm.test.js +49 -55
- package/src/cli/simple-commands/__tests__/task.test.js +4 -478
- package/src/cli/simple-commands/agent.js +27 -27
- package/src/cli/simple-commands/analysis.js +179 -161
- package/src/cli/simple-commands/automation.js +226 -205
- package/src/cli/simple-commands/batch-manager.js +98 -88
- package/src/cli/simple-commands/config.js +65 -60
- package/src/cli/simple-commands/coordination.js +197 -185
- package/src/cli/simple-commands/enhanced-ui-views.js +142 -115
- package/src/cli/simple-commands/enhanced-webui-complete.js +267 -167
- package/src/cli/simple-commands/fix-hook-variables.js +73 -67
- package/src/cli/simple-commands/github/gh-coordinator.js +63 -53
- package/src/cli/simple-commands/github/github-api.js +45 -47
- package/src/cli/simple-commands/github.js +33 -34
- package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +44 -40
- package/src/cli/simple-commands/hive-mind/communication.js +198 -185
- package/src/cli/simple-commands/hive-mind/core.js +289 -304
- package/src/cli/simple-commands/hive-mind/db-optimizer.js +278 -168
- package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +352 -258
- package/src/cli/simple-commands/hive-mind/memory.js +356 -287
- package/src/cli/simple-commands/hive-mind/performance-optimizer.js +88 -79
- package/src/cli/simple-commands/hive-mind/performance-test.js +61 -49
- package/src/cli/simple-commands/hive-mind/queen.js +223 -213
- package/src/cli/simple-commands/hive-mind/session-manager.js +217 -157
- package/src/cli/simple-commands/hive-mind-optimize.js +69 -65
- package/src/cli/simple-commands/hive-mind-wizard.js +213 -211
- package/src/cli/simple-commands/hive-mind.js +598 -432
- package/src/cli/simple-commands/hive.js +12 -12
- package/src/cli/simple-commands/hook-safety.js +114 -111
- package/src/cli/simple-commands/hooks.js +1077 -1017
- package/src/cli/simple-commands/init/README.md +8 -1
- package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +27 -1
- package/src/cli/simple-commands/init/batch-init.js +105 -100
- package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +6 -6
- package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +6 -6
- package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +20 -18
- package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +85 -71
- package/src/cli/simple-commands/init/claude-commands/slash-commands.js +6 -7
- package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +42 -33
- package/src/cli/simple-commands/init/executable-wrapper.js +13 -10
- package/src/cli/simple-commands/init/gitignore-updater.js +22 -22
- package/src/cli/simple-commands/init/help.js +4 -2
- package/src/cli/simple-commands/init/index.js +405 -303
- package/src/cli/simple-commands/init/performance-monitor.js +71 -64
- package/src/cli/simple-commands/init/rollback/backup-manager.js +44 -64
- package/src/cli/simple-commands/init/rollback/index.js +31 -39
- package/src/cli/simple-commands/init/rollback/recovery-manager.js +71 -101
- package/src/cli/simple-commands/init/rollback/rollback-executor.js +34 -53
- package/src/cli/simple-commands/init/rollback/state-tracker.js +38 -49
- package/src/cli/simple-commands/init/sparc/roo-readme.js +1 -1
- package/src/cli/simple-commands/init/sparc/roomodes-config.js +99 -77
- package/src/cli/simple-commands/init/sparc/workflows.js +37 -33
- package/src/cli/simple-commands/init/sparc-structure.js +9 -10
- package/src/cli/simple-commands/init/templates/CLAUDE.md +94 -26
- package/src/cli/simple-commands/init/templates/claude-flow-universal +9 -7
- package/src/cli/simple-commands/init/templates/claude-md.js +1 -1
- package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +15 -3
- package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +12 -2
- package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +10 -1
- package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +18 -5
- package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +13 -6
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +12 -1
- package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +13 -5
- package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +12 -1
- package/src/cli/simple-commands/init/templates/coordination-md.js +1 -1
- package/src/cli/simple-commands/init/templates/enhanced-templates.js +116 -113
- package/src/cli/simple-commands/init/templates/memory-bank-md.js +1 -1
- package/src/cli/simple-commands/init/templates/readme-files.js +1 -1
- package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +176 -127
- package/src/cli/simple-commands/init/templates/settings.json +2 -5
- package/src/cli/simple-commands/init/templates/sparc-modes.js +3 -3
- package/src/cli/simple-commands/init/validation/config-validator.js +17 -28
- package/src/cli/simple-commands/init/validation/health-checker.js +54 -62
- package/src/cli/simple-commands/init/validation/index.js +18 -23
- package/src/cli/simple-commands/init/validation/mode-validator.js +22 -32
- package/src/cli/simple-commands/init/validation/post-init-validator.js +25 -26
- package/src/cli/simple-commands/init/validation/pre-init-validator.js +32 -36
- package/src/cli/simple-commands/init/validation/test-runner.js +55 -63
- package/src/cli/simple-commands/init.js +1 -1
- package/src/cli/simple-commands/mcp-integration-layer.js +179 -110
- package/src/cli/simple-commands/mcp.js +55 -48
- package/src/cli/simple-commands/memory.js +62 -56
- package/src/cli/simple-commands/migrate-hooks.js +9 -10
- package/src/cli/simple-commands/monitor.js +87 -67
- package/src/cli/simple-commands/process-ui-enhanced.js +207 -155
- package/src/cli/simple-commands/process-ui.js +65 -56
- package/src/cli/simple-commands/realtime-update-system.js +136 -129
- package/src/cli/simple-commands/sparc/architecture.js +352 -251
- package/src/cli/simple-commands/sparc/commands.js +122 -94
- package/src/cli/simple-commands/sparc/completion.js +274 -199
- package/src/cli/simple-commands/sparc/coordinator.js +217 -169
- package/src/cli/simple-commands/sparc/index.js +40 -36
- package/src/cli/simple-commands/sparc/phase-base.js +72 -58
- package/src/cli/simple-commands/sparc/pseudocode.js +275 -159
- package/src/cli/simple-commands/sparc/refinement.js +306 -212
- package/src/cli/simple-commands/sparc/specification.js +164 -94
- package/src/cli/simple-commands/sparc-modes/architect.js +1 -1
- package/src/cli/simple-commands/sparc-modes/ask.js +1 -1
- package/src/cli/simple-commands/sparc-modes/code.js +1 -1
- package/src/cli/simple-commands/sparc-modes/debug.js +1 -1
- package/src/cli/simple-commands/sparc-modes/devops.js +1 -1
- package/src/cli/simple-commands/sparc-modes/docs-writer.js +1 -1
- package/src/cli/simple-commands/sparc-modes/generic.js +1 -1
- package/src/cli/simple-commands/sparc-modes/index.js +15 -15
- package/src/cli/simple-commands/sparc-modes/integration.js +1 -1
- package/src/cli/simple-commands/sparc-modes/mcp.js +1 -1
- package/src/cli/simple-commands/sparc-modes/monitoring.js +1 -1
- package/src/cli/simple-commands/sparc-modes/optimization.js +1 -1
- package/src/cli/simple-commands/sparc-modes/security-review.js +1 -1
- package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +1 -1
- package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +1 -1
- package/src/cli/simple-commands/sparc-modes/supabase-admin.js +1 -1
- package/src/cli/simple-commands/sparc-modes/swarm.js +52 -52
- package/src/cli/simple-commands/sparc-modes/tdd.js +1 -1
- package/src/cli/simple-commands/sparc-modes/tutorial.js +1 -1
- package/src/cli/simple-commands/sparc.js +87 -69
- package/src/cli/simple-commands/start-ui.js +21 -20
- package/src/cli/simple-commands/start-wrapper.js +29 -31
- package/src/cli/simple-commands/start.js +1 -1
- package/src/cli/simple-commands/status.js +53 -47
- package/src/cli/simple-commands/swarm-executor.js +47 -57
- package/src/cli/simple-commands/swarm-metrics-integration.js +119 -79
- package/src/cli/simple-commands/swarm-ui.js +120 -118
- package/src/cli/simple-commands/swarm-webui-integration.js +48 -27
- package/src/cli/simple-commands/swarm.js +216 -181
- package/src/cli/simple-commands/task.js +29 -29
- package/src/cli/simple-commands/timestamp-fix.js +28 -25
- package/src/cli/simple-commands/tool-execution-framework.js +115 -118
- package/src/cli/simple-commands/training.js +219 -194
- package/src/cli/simple-commands/web-server.js +118 -117
- package/src/cli/simple-commands/webui-validator.js +4 -3
- package/src/cli/simple-mcp.ts +14 -17
- package/src/cli/simple-orchestrator.ts +113 -101
- package/src/cli/swarm-standalone.js +20 -21
- package/src/cli/ui/compatible-ui.ts +55 -44
- package/src/cli/ui/fallback-handler.ts +19 -16
- package/src/cli/ui/index.ts +14 -15
- package/src/cli/utils/environment-detector.ts +75 -67
- package/src/cli/utils/interactive-detector.js +17 -11
- package/src/cli/utils/prompt-defaults.ts +32 -28
- package/src/cli/utils/safe-interactive.js +21 -20
- package/src/cli/utils.js +127 -110
- package/src/cli/validation-helper.js +16 -21
- package/src/cli/validation-helper.ts +21 -34
- package/src/communication/message-bus.ts +137 -124
- package/src/config/config-manager.ts +62 -30
- package/src/config/ruv-swarm-config.ts +105 -86
- package/src/config/ruv-swarm-integration.ts +38 -38
- package/src/constants/agent-types.ts +9 -8
- package/src/coordination/README.md +54 -31
- package/src/coordination/advanced-scheduler.ts +23 -26
- package/src/coordination/advanced-task-executor.ts +74 -68
- package/src/coordination/background-executor.ts +33 -30
- package/src/coordination/circuit-breaker.ts +26 -27
- package/src/coordination/conflict-resolution.ts +18 -27
- package/src/coordination/dependency-graph.ts +15 -18
- package/src/coordination/hive-orchestrator.ts +111 -81
- package/src/coordination/hive-protocol.ts +68 -77
- package/src/coordination/index.ts +3 -7
- package/src/coordination/load-balancer.ts +115 -105
- package/src/coordination/manager.ts +38 -51
- package/src/coordination/messaging.ts +19 -29
- package/src/coordination/metrics.ts +57 -60
- package/src/coordination/resources.ts +32 -37
- package/src/coordination/scheduler.ts +29 -30
- package/src/coordination/swarm-coordinator.ts +81 -70
- package/src/coordination/swarm-monitor.ts +90 -69
- package/src/coordination/work-stealing.ts +6 -13
- package/src/core/config.ts +148 -143
- package/src/core/event-bus.ts +5 -6
- package/src/core/json-persistence.ts +27 -34
- package/src/core/logger.ts +13 -16
- package/src/core/orchestrator-fixed.ts +33 -32
- package/src/core/orchestrator.ts +166 -159
- package/src/core/persistence.ts +47 -36
- package/src/enterprise/analytics-manager.ts +242 -233
- package/src/enterprise/audit-manager.ts +238 -184
- package/src/enterprise/cloud-manager.ts +167 -151
- package/src/enterprise/deployment-manager.ts +223 -180
- package/src/enterprise/index.ts +7 -7
- package/src/enterprise/project-manager.ts +151 -133
- package/src/enterprise/security-manager.ts +278 -223
- package/src/hive-mind/core/Agent.ts +112 -109
- package/src/hive-mind/core/Communication.ts +67 -69
- package/src/hive-mind/core/DatabaseManager.ts +299 -166
- package/src/hive-mind/core/HiveMind.ts +100 -96
- package/src/hive-mind/core/Memory.ts +304 -295
- package/src/hive-mind/core/MemoryMonitor.ts +46 -47
- package/src/hive-mind/core/Queen.ts +187 -114
- package/src/hive-mind/index.ts +2 -2
- package/src/hive-mind/integration/ConsensusEngine.ts +88 -92
- package/src/hive-mind/integration/MCPToolWrapper.ts +20 -72
- package/src/hive-mind/integration/SwarmOrchestrator.ts +173 -165
- package/src/hive-mind/types.ts +24 -12
- package/src/integration/mock-components.ts +42 -30
- package/src/integration/system-integration.ts +79 -78
- package/src/integration/types.ts +7 -7
- package/src/mcp/README.md +23 -4
- package/src/mcp/auth.ts +25 -18
- package/src/mcp/claude-code-wrapper.ts +257 -150
- package/src/mcp/claude-flow-tools.ts +52 -13
- package/src/mcp/client.ts +15 -13
- package/src/mcp/index.ts +22 -27
- package/src/mcp/integrate-wrapper.ts +18 -18
- package/src/mcp/lifecycle-manager.ts +30 -27
- package/src/mcp/load-balancer.ts +10 -11
- package/src/mcp/mcp-server.js +662 -351
- package/src/mcp/orchestration-integration.ts +32 -17
- package/src/mcp/performance-monitor.ts +65 -51
- package/src/mcp/protocol-manager.ts +36 -52
- package/src/mcp/recovery/connection-health-monitor.ts +40 -35
- package/src/mcp/recovery/connection-state-manager.ts +52 -50
- package/src/mcp/recovery/fallback-coordinator.ts +24 -24
- package/src/mcp/recovery/index.ts +23 -4
- package/src/mcp/recovery/reconnection-manager.ts +14 -15
- package/src/mcp/recovery/recovery-manager.ts +52 -68
- package/src/mcp/router.ts +1 -2
- package/src/mcp/ruv-swarm-tools.ts +167 -138
- package/src/mcp/ruv-swarm-wrapper.js +31 -23
- package/src/mcp/server-with-wrapper.ts +4 -5
- package/src/mcp/server-wrapper-mode.ts +5 -6
- package/src/mcp/server.ts +45 -40
- package/src/mcp/session-manager.ts +8 -11
- package/src/mcp/sparc-modes.ts +29 -28
- package/src/mcp/swarm-tools.ts +131 -114
- package/src/mcp/tests/mcp-integration.test.ts +49 -55
- package/src/mcp/tools.ts +53 -38
- package/src/mcp/transports/base.ts +4 -5
- package/src/mcp/transports/http.ts +45 -42
- package/src/mcp/transports/stdio.ts +9 -12
- package/src/memory/README.md +37 -27
- package/src/memory/advanced-memory-manager.ts +336 -279
- package/src/memory/backends/base.ts +4 -5
- package/src/memory/backends/markdown.ts +16 -22
- package/src/memory/backends/sqlite.ts +19 -15
- package/src/memory/cache.ts +18 -18
- package/src/memory/distributed-memory.ts +84 -92
- package/src/memory/enhanced-examples.js +68 -59
- package/src/memory/enhanced-memory.js +99 -80
- package/src/memory/fallback-store.js +16 -7
- package/src/memory/in-memory-store.js +31 -27
- package/src/memory/index.js +4 -4
- package/src/memory/indexer.ts +6 -10
- package/src/memory/manager.ts +45 -59
- package/src/memory/migration.js +107 -90
- package/src/memory/shared-memory.js +155 -157
- package/src/memory/sqlite-store.js +76 -59
- package/src/memory/swarm-memory.js +138 -131
- package/src/memory/swarm-memory.ts +74 -75
- package/src/memory/test-example.js +28 -30
- package/src/migration/README.md +25 -9
- package/src/migration/index.ts +13 -14
- package/src/migration/logger.ts +9 -7
- package/src/migration/migration-analyzer.ts +66 -52
- package/src/migration/migration-manifest.json +2 -6
- package/src/migration/migration-runner.ts +86 -63
- package/src/migration/migration-validator.ts +93 -68
- package/src/migration/package.json +1 -1
- package/src/migration/progress-reporter.ts +25 -21
- package/src/migration/rollback-manager.ts +79 -63
- package/src/migration/tests/migration-system.test.ts +4 -491
- package/src/migration/tsconfig.json +3 -10
- package/src/migration/types.ts +1 -1
- package/src/monitoring/diagnostics.ts +123 -97
- package/src/monitoring/health-check.ts +45 -51
- package/src/monitoring/real-time-monitor.ts +105 -92
- package/src/resources/resource-manager.ts +205 -159
- package/src/swarm/__tests__/integration.test.ts +59 -65
- package/src/swarm/__tests__/prompt-copier.test.ts +27 -27
- package/src/swarm/claude-flow-executor.ts +50 -49
- package/src/swarm/coordinator.ts +727 -635
- package/src/swarm/direct-executor.ts +80 -86
- package/src/swarm/executor-v2.ts +81 -66
- package/src/swarm/executor.ts +124 -124
- package/src/swarm/index.ts +7 -8
- package/src/swarm/json-output-aggregator.ts +56 -40
- package/src/swarm/memory.ts +152 -147
- package/src/swarm/optimizations/README.md +20 -12
- package/src/swarm/optimizations/__tests__/optimization.test.ts +84 -87
- package/src/swarm/optimizations/async-file-manager.ts +70 -80
- package/src/swarm/optimizations/circular-buffer.ts +37 -37
- package/src/swarm/optimizations/connection-pool.ts +64 -64
- package/src/swarm/optimizations/index.ts +4 -4
- package/src/swarm/optimizations/migration-guide.md +27 -16
- package/src/swarm/optimizations/optimized-executor.ts +104 -114
- package/src/swarm/optimizations/ttl-map.ts +66 -63
- package/src/swarm/prompt-cli.ts +48 -42
- package/src/swarm/prompt-copier-enhanced.ts +54 -55
- package/src/swarm/prompt-copier.ts +59 -65
- package/src/swarm/prompt-copying-README.md +49 -33
- package/src/swarm/prompt-manager.ts +69 -63
- package/src/swarm/prompt-utils.ts +71 -66
- package/src/swarm/sparc-executor.ts +298 -225
- package/src/swarm/strategies/auto.ts +367 -252
- package/src/swarm/strategies/base.ts +24 -20
- package/src/swarm/strategies/research.ts +144 -124
- package/src/swarm/types.ts +340 -309
- package/src/swarm/workers/copy-worker.ts +12 -13
- package/src/task/README.md +99 -70
- package/src/task/commands.ts +16 -8
- package/src/task/coordination.ts +209 -162
- package/src/task/engine.ts +81 -65
- package/src/task/index.ts +28 -31
- package/src/templates/claude-optimized/.claude/BATCHTOOLS_BEST_PRACTICES.md +479 -481
- package/src/templates/claude-optimized/.claude/BATCHTOOLS_GUIDE.md +210 -188
- package/src/templates/claude-optimized/.claude/MIGRATION_GUIDE.md +151 -105
- package/src/templates/claude-optimized/.claude/PERFORMANCE_BENCHMARKS.md +102 -87
- package/src/templates/claude-optimized/.claude/commands/claude-flow-help.md +18 -1
- package/src/templates/claude-optimized/.claude/commands/claude-flow-memory.md +17 -1
- package/src/templates/claude-optimized/.claude/commands/claude-flow-swarm.md +21 -1
- package/src/templates/claude-optimized/.claude/commands/sparc/architect.md +11 -4
- package/src/templates/claude-optimized/.claude/commands/sparc/ask.md +16 -10
- package/src/templates/claude-optimized/.claude/commands/sparc/code.md +26 -7
- package/src/templates/claude-optimized/.claude/commands/sparc/debug.md +14 -4
- package/src/templates/claude-optimized/.claude/commands/sparc/devops.md +23 -10
- package/src/templates/claude-optimized/.claude/commands/sparc/docs-writer.md +8 -4
- package/src/templates/claude-optimized/.claude/commands/sparc/integration.md +43 -27
- package/src/templates/claude-optimized/.claude/commands/sparc/mcp.md +15 -1
- package/src/templates/claude-optimized/.claude/commands/sparc/post-deployment-monitoring-mode.md +45 -30
- package/src/templates/claude-optimized/.claude/commands/sparc/refinement-optimization-mode.md +23 -13
- package/src/templates/claude-optimized/.claude/commands/sparc/security-review.md +31 -17
- package/src/templates/claude-optimized/.claude/commands/sparc/sparc.md +54 -47
- package/src/templates/claude-optimized/.claude/commands/sparc/spec-pseudocode.md +27 -17
- package/src/templates/claude-optimized/.claude/commands/sparc/supabase-admin.md +18 -4
- package/src/templates/claude-optimized/.claude/commands/sparc/tdd.md +23 -9
- package/src/templates/claude-optimized/.claude/commands/sparc/tutorial.md +22 -16
- package/src/templates/claude-optimized/.claude/commands/sparc.md +20 -1
- package/src/templates/claude-optimized/README.md +10 -1
- package/src/templates/claude-optimized/SUMMARY.md +23 -1
- package/src/templates/claude-optimized/deploy-to-project.js +22 -10
- package/src/templates/claude-optimized/install-template.js +14 -10
- package/src/templates/claude-optimized/manifest.json +1 -1
- package/src/templates/claude-optimized/package.json +1 -1
- package/src/templates/claude-optimized/template-manager.js +8 -8
- package/src/templates/claude-optimized/validate-template.js +33 -23
- package/src/terminal/adapters/base.ts +1 -1
- package/src/terminal/adapters/native.ts +47 -47
- package/src/terminal/adapters/vscode.ts +21 -28
- package/src/terminal/manager.ts +27 -22
- package/src/terminal/pool.ts +24 -27
- package/src/terminal/session.ts +18 -18
- package/src/terminal/vscode-bridge.ts +21 -21
- package/src/tests/validation-consistency.test.ts +4 -4
- package/src/types/cliffy.d.ts +11 -14
- package/src/types/global.d.ts +1 -2
- package/src/types/index.ts +2 -2
- package/src/types/mcp.d.ts +11 -17
- package/src/types/vscode.d.ts +18 -5
- package/src/ui/console/README-analysis-tools.md +52 -2
- package/src/ui/console/README.md +33 -1
- package/src/ui/console/WORKFLOW_DESIGNER_README.md +81 -22
- package/src/ui/console/analysis-tools.html +282 -261
- package/src/ui/console/analytics.html +329 -326
- package/src/ui/console/index.html +221 -209
- package/src/ui/console/js/analysis-tools.js +815 -754
- package/src/ui/console/js/command-handler.js +226 -196
- package/src/ui/console/js/console.js +117 -119
- package/src/ui/console/js/daa-tools.js +797 -787
- package/src/ui/console/js/memory-interface.js +676 -638
- package/src/ui/console/js/memory-test.js +49 -46
- package/src/ui/console/js/memory-tools.js +181 -159
- package/src/ui/console/js/settings.js +124 -103
- package/src/ui/console/js/terminal-emulator.js +147 -130
- package/src/ui/console/js/websocket-client.js +71 -71
- package/src/ui/console/js/workflow-designer.js +1126 -1110
- package/src/ui/console/neural-networks-demo.md +45 -16
- package/src/ui/console/styles/analysis-tools.css +571 -561
- package/src/ui/console/styles/console.css +16 -12
- package/src/ui/console/styles/daa-tools.css +322 -319
- package/src/ui/console/styles/responsive.css +71 -70
- package/src/ui/console/styles/settings.css +12 -12
- package/src/ui/console/styles/workflow-designer.css +628 -584
- package/src/ui/console/test-neural-networks.js +59 -54
- package/src/ui/console/test-neural.html +194 -196
- package/src/ui/console/workflow-designer-demo.html +433 -424
- package/src/ui/hive-dashboard.ts +74 -52
- package/src/ui/web-ui/EnhancedProcessUI.js +570 -424
- package/src/ui/web-ui/EnhancedWebUI.js +65 -65
- package/src/ui/web-ui/README.md +16 -16
- package/src/ui/web-ui/components/ComponentLibrary.js +173 -124
- package/src/ui/web-ui/core/EventBus.js +27 -25
- package/src/ui/web-ui/core/MCPIntegrationLayer.js +294 -108
- package/src/ui/web-ui/core/StateManager.js +43 -46
- package/src/ui/web-ui/core/UIManager.js +120 -70
- package/src/ui/web-ui/core/ViewManager.js +16 -19
- package/src/ui/web-ui/index.js +101 -48
- package/src/ui/web-ui/neural-panel-test.js +109 -108
- package/src/ui/web-ui/test-github-view.js +11 -12
- package/src/ui/web-ui/test-neural-panel.html +219 -205
- package/src/ui/web-ui/views/DAAView.js +88 -85
- package/src/ui/web-ui/views/GitHubIntegrationTest.js +42 -42
- package/src/ui/web-ui/views/GitHubIntegrationView.js +59 -53
- package/src/ui/web-ui/views/NeuralNetworkView.js +20 -21
- package/src/ui/web-ui/views/WorkflowAutomationView.js +31 -32
- package/src/utils/error-handler.js +1 -1
- package/src/utils/error-handler.ts +9 -5
- package/src/utils/errors.ts +20 -18
- package/src/utils/formatters.ts +6 -6
- package/src/utils/helpers.ts +53 -55
- package/src/utils/npx-isolated-cache.js +16 -16
- package/src/utils/paths.ts +9 -6
- package/src/utils/timezone-utils.js +16 -16
- package/src/utils/type-guards.ts +37 -26
- package/src/utils/types.ts +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Batchtools Best Practices Guide
|
|
2
2
|
|
|
3
3
|
## Table of Contents
|
|
4
|
+
|
|
4
5
|
1. [Core Principles](#core-principles)
|
|
5
6
|
2. [Design Patterns](#design-patterns)
|
|
6
7
|
3. [Performance Best Practices](#performance-best-practices)
|
|
@@ -17,18 +18,21 @@
|
|
|
17
18
|
### When to Use Batch Operations vs Sequential
|
|
18
19
|
|
|
19
20
|
**Use Batch Operations When:**
|
|
21
|
+
|
|
20
22
|
- Processing multiple independent files or data items
|
|
21
23
|
- Operations have similar resource requirements
|
|
22
24
|
- Total processing time is a concern
|
|
23
25
|
- Operations can fail independently without affecting others
|
|
24
26
|
|
|
25
27
|
**Use Sequential Operations When:**
|
|
28
|
+
|
|
26
29
|
- Operations have dependencies between steps
|
|
27
30
|
- Resource constraints are tight
|
|
28
31
|
- Order of execution matters
|
|
29
32
|
- Debugging and monitoring individual steps is critical
|
|
30
33
|
|
|
31
34
|
**Decision Tree:**
|
|
35
|
+
|
|
32
36
|
```
|
|
33
37
|
Is the operation independent?
|
|
34
38
|
├── Yes → Are there multiple items to process?
|
|
@@ -44,20 +48,21 @@ Is the operation independent?
|
|
|
44
48
|
```javascript
|
|
45
49
|
// Good: Resource-aware batch processing
|
|
46
50
|
const OPTIMAL_BATCH_SIZE = Math.min(
|
|
47
|
-
os.cpus().length * 2,
|
|
48
|
-
Math.floor(os.freemem() / (100 * 1024 * 1024)),
|
|
49
|
-
10
|
|
51
|
+
os.cpus().length * 2, // CPU cores
|
|
52
|
+
Math.floor(os.freemem() / (100 * 1024 * 1024)), // Available memory
|
|
53
|
+
10, // Hard limit
|
|
50
54
|
);
|
|
51
55
|
|
|
52
56
|
// Bad: Unbounded parallelism
|
|
53
57
|
const results = await Promise.all(
|
|
54
|
-
files.map(file => processFile(file))
|
|
58
|
+
files.map((file) => processFile(file)), // Could overwhelm system
|
|
55
59
|
);
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
### Maintaining Code Readability
|
|
59
63
|
|
|
60
64
|
**Best Practices:**
|
|
65
|
+
|
|
61
66
|
1. Use descriptive variable names for batch operations
|
|
62
67
|
2. Group related batch operations together
|
|
63
68
|
3. Add comments explaining parallelism decisions
|
|
@@ -65,18 +70,16 @@ const results = await Promise.all(
|
|
|
65
70
|
|
|
66
71
|
```javascript
|
|
67
72
|
// Good: Clear and readable
|
|
68
|
-
const batchedFileReads = await readFilesInBatches(
|
|
69
|
-
filePaths,
|
|
70
|
-
{ batchSize: 5, retryCount: 3 }
|
|
71
|
-
);
|
|
73
|
+
const batchedFileReads = await readFilesInBatches(filePaths, { batchSize: 5, retryCount: 3 });
|
|
72
74
|
|
|
73
75
|
// Bad: Unclear intent
|
|
74
|
-
const r = await Promise.all(fps.map(f => rf(f)));
|
|
76
|
+
const r = await Promise.all(fps.map((f) => rf(f)));
|
|
75
77
|
```
|
|
76
78
|
|
|
77
79
|
### Error Handling Philosophy
|
|
78
80
|
|
|
79
81
|
**Principles:**
|
|
82
|
+
|
|
80
83
|
1. **Fail gracefully**: Don't let one failure crash everything
|
|
81
84
|
2. **Collect all errors**: Gather comprehensive error information
|
|
82
85
|
3. **Provide context**: Include which operation failed and why
|
|
@@ -89,54 +92,55 @@ const r = await Promise.all(fps.map(f => rf(f)));
|
|
|
89
92
|
### Common Batchtools Patterns
|
|
90
93
|
|
|
91
94
|
#### 1. **Batch with Accumulator Pattern**
|
|
95
|
+
|
|
92
96
|
```javascript
|
|
93
97
|
async function batchProcess(items, processor, options = {}) {
|
|
94
98
|
const { batchSize = 5 } = options;
|
|
95
99
|
const results = [];
|
|
96
100
|
const errors = [];
|
|
97
|
-
|
|
101
|
+
|
|
98
102
|
for (let i = 0; i < items.length; i += batchSize) {
|
|
99
103
|
const batch = items.slice(i, i + batchSize);
|
|
100
|
-
const batchResults = await Promise.allSettled(
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
+
const batchResults = await Promise.allSettled(batch.map((item) => processor(item)));
|
|
105
|
+
|
|
104
106
|
batchResults.forEach((result, index) => {
|
|
105
107
|
if (result.status === 'fulfilled') {
|
|
106
108
|
results.push(result.value);
|
|
107
109
|
} else {
|
|
108
110
|
errors.push({
|
|
109
111
|
item: batch[index],
|
|
110
|
-
error: result.reason
|
|
112
|
+
error: result.reason,
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
});
|
|
114
116
|
}
|
|
115
|
-
|
|
117
|
+
|
|
116
118
|
return { results, errors };
|
|
117
119
|
}
|
|
118
120
|
```
|
|
119
121
|
|
|
120
122
|
#### 2. **Pipeline Pattern**
|
|
123
|
+
|
|
121
124
|
```javascript
|
|
122
125
|
async function pipeline(items, stages, options = {}) {
|
|
123
126
|
let current = items;
|
|
124
|
-
|
|
127
|
+
|
|
125
128
|
for (const stage of stages) {
|
|
126
129
|
const { results, errors } = await batchProcess(current, stage, options);
|
|
127
|
-
|
|
130
|
+
|
|
128
131
|
if (errors.length > 0) {
|
|
129
132
|
console.warn(`Stage ${stage.name} had ${errors.length} errors`);
|
|
130
133
|
}
|
|
131
|
-
|
|
134
|
+
|
|
132
135
|
current = results;
|
|
133
136
|
}
|
|
134
|
-
|
|
137
|
+
|
|
135
138
|
return current;
|
|
136
139
|
}
|
|
137
140
|
```
|
|
138
141
|
|
|
139
142
|
#### 3. **Circuit Breaker Pattern**
|
|
143
|
+
|
|
140
144
|
```javascript
|
|
141
145
|
class BatchCircuitBreaker {
|
|
142
146
|
constructor(threshold = 0.5, resetTime = 60000) {
|
|
@@ -147,29 +151,27 @@ class BatchCircuitBreaker {
|
|
|
147
151
|
this.state = 'closed';
|
|
148
152
|
this.nextAttempt = Date.now();
|
|
149
153
|
}
|
|
150
|
-
|
|
154
|
+
|
|
151
155
|
async execute(batch, processor) {
|
|
152
156
|
if (this.state === 'open' && Date.now() < this.nextAttempt) {
|
|
153
157
|
throw new Error('Circuit breaker is open');
|
|
154
158
|
}
|
|
155
|
-
|
|
156
|
-
const results = await Promise.allSettled(
|
|
157
|
-
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const successes = results.filter(r => r.status === 'fulfilled').length;
|
|
162
|
-
|
|
159
|
+
|
|
160
|
+
const results = await Promise.allSettled(batch.map((item) => processor(item)));
|
|
161
|
+
|
|
162
|
+
const failures = results.filter((r) => r.status === 'rejected').length;
|
|
163
|
+
const successes = results.filter((r) => r.status === 'fulfilled').length;
|
|
164
|
+
|
|
163
165
|
this.failures += failures;
|
|
164
166
|
this.successes += successes;
|
|
165
|
-
|
|
167
|
+
|
|
166
168
|
const failureRate = this.failures / (this.failures + this.successes);
|
|
167
|
-
|
|
169
|
+
|
|
168
170
|
if (failureRate > this.threshold) {
|
|
169
171
|
this.state = 'open';
|
|
170
172
|
this.nextAttempt = Date.now() + this.resetTime;
|
|
171
173
|
}
|
|
172
|
-
|
|
174
|
+
|
|
173
175
|
return results;
|
|
174
176
|
}
|
|
175
177
|
}
|
|
@@ -178,19 +180,19 @@ class BatchCircuitBreaker {
|
|
|
178
180
|
### Anti-patterns to Avoid
|
|
179
181
|
|
|
180
182
|
#### 1. **Unbounded Parallelism**
|
|
183
|
+
|
|
181
184
|
```javascript
|
|
182
185
|
// Bad: Can overwhelm system
|
|
183
|
-
const results = await Promise.all(
|
|
184
|
-
thousandsOfFiles.map(file => processLargeFile(file))
|
|
185
|
-
);
|
|
186
|
+
const results = await Promise.all(thousandsOfFiles.map((file) => processLargeFile(file)));
|
|
186
187
|
|
|
187
188
|
// Good: Controlled parallelism
|
|
188
189
|
const results = await batchProcess(thousandsOfFiles, processLargeFile, {
|
|
189
|
-
batchSize: 10
|
|
190
|
+
batchSize: 10,
|
|
190
191
|
});
|
|
191
192
|
```
|
|
192
193
|
|
|
193
194
|
#### 2. **Ignoring Partial Failures**
|
|
195
|
+
|
|
194
196
|
```javascript
|
|
195
197
|
// Bad: Loses error information
|
|
196
198
|
try {
|
|
@@ -201,17 +203,16 @@ try {
|
|
|
201
203
|
|
|
202
204
|
// Good: Handles partial failures
|
|
203
205
|
const results = await Promise.allSettled(operations);
|
|
204
|
-
const succeeded = results.filter(r => r.status === 'fulfilled');
|
|
205
|
-
const failed = results.filter(r => r.status === 'rejected');
|
|
206
|
+
const succeeded = results.filter((r) => r.status === 'fulfilled');
|
|
207
|
+
const failed = results.filter((r) => r.status === 'rejected');
|
|
206
208
|
```
|
|
207
209
|
|
|
208
210
|
#### 3. **Resource Leaks in Batch Operations**
|
|
211
|
+
|
|
209
212
|
```javascript
|
|
210
213
|
// Bad: Doesn't clean up resources
|
|
211
214
|
async function processBatch(files) {
|
|
212
|
-
const handles = await Promise.all(
|
|
213
|
-
files.map(file => fs.open(file, 'r'))
|
|
214
|
-
);
|
|
215
|
+
const handles = await Promise.all(files.map((file) => fs.open(file, 'r')));
|
|
215
216
|
// Process files...
|
|
216
217
|
// Oops, forgot to close handles!
|
|
217
218
|
}
|
|
@@ -225,9 +226,7 @@ async function processBatch(files) {
|
|
|
225
226
|
}
|
|
226
227
|
// Process files...
|
|
227
228
|
} finally {
|
|
228
|
-
await Promise.all(
|
|
229
|
-
handles.map(handle => handle.close())
|
|
230
|
-
);
|
|
229
|
+
await Promise.all(handles.map((handle) => handle.close()));
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
232
|
```
|
|
@@ -235,45 +234,44 @@ async function processBatch(files) {
|
|
|
235
234
|
### Dependency Management in Parallel Workflows
|
|
236
235
|
|
|
237
236
|
#### Dependency Graph Execution
|
|
237
|
+
|
|
238
238
|
```javascript
|
|
239
239
|
class DependencyGraph {
|
|
240
240
|
constructor() {
|
|
241
241
|
this.nodes = new Map();
|
|
242
242
|
this.edges = new Map();
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
|
|
245
245
|
addTask(id, task, dependencies = []) {
|
|
246
246
|
this.nodes.set(id, task);
|
|
247
247
|
this.edges.set(id, dependencies);
|
|
248
248
|
}
|
|
249
|
-
|
|
249
|
+
|
|
250
250
|
async execute() {
|
|
251
251
|
const completed = new Set();
|
|
252
252
|
const results = new Map();
|
|
253
|
-
|
|
253
|
+
|
|
254
254
|
while (completed.size < this.nodes.size) {
|
|
255
255
|
const ready = [];
|
|
256
|
-
|
|
256
|
+
|
|
257
257
|
for (const [id, deps] of this.edges) {
|
|
258
|
-
if (!completed.has(id) && deps.every(d => completed.has(d))) {
|
|
258
|
+
if (!completed.has(id) && deps.every((d) => completed.has(d))) {
|
|
259
259
|
ready.push(id);
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
|
|
262
|
+
|
|
263
263
|
if (ready.length === 0) {
|
|
264
264
|
throw new Error('Circular dependency detected');
|
|
265
265
|
}
|
|
266
|
-
|
|
267
|
-
const batchResults = await Promise.allSettled(
|
|
268
|
-
|
|
269
|
-
);
|
|
270
|
-
|
|
266
|
+
|
|
267
|
+
const batchResults = await Promise.allSettled(ready.map((id) => this.nodes.get(id)()));
|
|
268
|
+
|
|
271
269
|
ready.forEach((id, index) => {
|
|
272
270
|
completed.add(id);
|
|
273
271
|
results.set(id, batchResults[index]);
|
|
274
272
|
});
|
|
275
273
|
}
|
|
276
|
-
|
|
274
|
+
|
|
277
275
|
return results;
|
|
278
276
|
}
|
|
279
277
|
}
|
|
@@ -282,22 +280,23 @@ class DependencyGraph {
|
|
|
282
280
|
### State Management in Concurrent Operations
|
|
283
281
|
|
|
284
282
|
#### Shared State Manager
|
|
283
|
+
|
|
285
284
|
```javascript
|
|
286
285
|
class ConcurrentStateManager {
|
|
287
286
|
constructor() {
|
|
288
287
|
this.state = new Map();
|
|
289
288
|
this.locks = new Map();
|
|
290
289
|
}
|
|
291
|
-
|
|
290
|
+
|
|
292
291
|
async withLock(key, operation) {
|
|
293
292
|
// Wait for existing lock
|
|
294
293
|
while (this.locks.has(key)) {
|
|
295
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
294
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
296
295
|
}
|
|
297
|
-
|
|
296
|
+
|
|
298
297
|
// Acquire lock
|
|
299
298
|
this.locks.set(key, true);
|
|
300
|
-
|
|
299
|
+
|
|
301
300
|
try {
|
|
302
301
|
return await operation(this.state);
|
|
303
302
|
} finally {
|
|
@@ -305,16 +304,14 @@ class ConcurrentStateManager {
|
|
|
305
304
|
this.locks.delete(key);
|
|
306
305
|
}
|
|
307
306
|
}
|
|
308
|
-
|
|
307
|
+
|
|
309
308
|
async batchUpdate(updates) {
|
|
310
309
|
const results = [];
|
|
311
|
-
|
|
310
|
+
|
|
312
311
|
for (const { key, operation } of updates) {
|
|
313
|
-
results.push(
|
|
314
|
-
this.withLock(key, state => operation(state))
|
|
315
|
-
);
|
|
312
|
+
results.push(this.withLock(key, (state) => operation(state)));
|
|
316
313
|
}
|
|
317
|
-
|
|
314
|
+
|
|
318
315
|
return Promise.all(results);
|
|
319
316
|
}
|
|
320
317
|
}
|
|
@@ -326,45 +323,44 @@ class ConcurrentStateManager {
|
|
|
326
323
|
|
|
327
324
|
### Optimal Batch Sizes for Different Operations
|
|
328
325
|
|
|
329
|
-
| Operation Type
|
|
330
|
-
|
|
331
|
-
| File Reads
|
|
332
|
-
| File Writes
|
|
333
|
-
| API Calls
|
|
334
|
-
| CPU-intensive
|
|
335
|
-
| Memory-intensive | Available RAM / Task RAM | Prevents OOM errors
|
|
326
|
+
| Operation Type | Recommended Batch Size | Rationale |
|
|
327
|
+
| ---------------- | ------------------------ | ---------------------------------------------- |
|
|
328
|
+
| File Reads | 5-10 | I/O bound, prevents file descriptor exhaustion |
|
|
329
|
+
| File Writes | 3-5 | Ensures data integrity, prevents corruption |
|
|
330
|
+
| API Calls | 10-20 | Network bound, respects rate limits |
|
|
331
|
+
| CPU-intensive | CPU cores × 2 | Maximizes CPU utilization |
|
|
332
|
+
| Memory-intensive | Available RAM / Task RAM | Prevents OOM errors |
|
|
336
333
|
|
|
337
334
|
### Dynamic Batch Sizing
|
|
335
|
+
|
|
338
336
|
```javascript
|
|
339
337
|
class AdaptiveBatcher {
|
|
340
338
|
constructor(initialSize = 5) {
|
|
341
339
|
this.batchSize = initialSize;
|
|
342
340
|
this.performanceHistory = [];
|
|
343
341
|
}
|
|
344
|
-
|
|
342
|
+
|
|
345
343
|
async processBatch(items, processor) {
|
|
346
344
|
const startTime = Date.now();
|
|
347
345
|
const batch = items.slice(0, this.batchSize);
|
|
348
|
-
|
|
349
|
-
const results = await Promise.allSettled(
|
|
350
|
-
|
|
351
|
-
);
|
|
352
|
-
|
|
346
|
+
|
|
347
|
+
const results = await Promise.allSettled(batch.map((item) => processor(item)));
|
|
348
|
+
|
|
353
349
|
const duration = Date.now() - startTime;
|
|
354
350
|
const throughput = batch.length / (duration / 1000);
|
|
355
|
-
|
|
351
|
+
|
|
356
352
|
this.performanceHistory.push({ size: this.batchSize, throughput });
|
|
357
353
|
this.adjustBatchSize();
|
|
358
|
-
|
|
354
|
+
|
|
359
355
|
return results;
|
|
360
356
|
}
|
|
361
|
-
|
|
357
|
+
|
|
362
358
|
adjustBatchSize() {
|
|
363
359
|
if (this.performanceHistory.length < 3) return;
|
|
364
|
-
|
|
360
|
+
|
|
365
361
|
const recent = this.performanceHistory.slice(-3);
|
|
366
362
|
const avgThroughput = recent.reduce((sum, r) => sum + r.throughput, 0) / 3;
|
|
367
|
-
|
|
363
|
+
|
|
368
364
|
// Increase if performance is good
|
|
369
365
|
if (avgThroughput > this.batchSize * 0.8) {
|
|
370
366
|
this.batchSize = Math.min(this.batchSize + 2, 20);
|
|
@@ -380,6 +376,7 @@ class AdaptiveBatcher {
|
|
|
380
376
|
### Resource Pooling and Management
|
|
381
377
|
|
|
382
378
|
#### Connection Pool Example
|
|
379
|
+
|
|
383
380
|
```javascript
|
|
384
381
|
class ResourcePool {
|
|
385
382
|
constructor(factory, maxSize = 10) {
|
|
@@ -389,7 +386,7 @@ class ResourcePool {
|
|
|
389
386
|
this.inUse = new Set();
|
|
390
387
|
this.waiting = [];
|
|
391
388
|
}
|
|
392
|
-
|
|
389
|
+
|
|
393
390
|
async acquire() {
|
|
394
391
|
// Return available resource
|
|
395
392
|
if (this.available.length > 0) {
|
|
@@ -397,23 +394,23 @@ class ResourcePool {
|
|
|
397
394
|
this.inUse.add(resource);
|
|
398
395
|
return resource;
|
|
399
396
|
}
|
|
400
|
-
|
|
397
|
+
|
|
401
398
|
// Create new resource if under limit
|
|
402
399
|
if (this.inUse.size < this.maxSize) {
|
|
403
400
|
const resource = await this.factory();
|
|
404
401
|
this.inUse.add(resource);
|
|
405
402
|
return resource;
|
|
406
403
|
}
|
|
407
|
-
|
|
404
|
+
|
|
408
405
|
// Wait for available resource
|
|
409
|
-
return new Promise(resolve => {
|
|
406
|
+
return new Promise((resolve) => {
|
|
410
407
|
this.waiting.push(resolve);
|
|
411
408
|
});
|
|
412
409
|
}
|
|
413
|
-
|
|
410
|
+
|
|
414
411
|
release(resource) {
|
|
415
412
|
this.inUse.delete(resource);
|
|
416
|
-
|
|
413
|
+
|
|
417
414
|
if (this.waiting.length > 0) {
|
|
418
415
|
const resolve = this.waiting.shift();
|
|
419
416
|
this.inUse.add(resource);
|
|
@@ -422,7 +419,7 @@ class ResourcePool {
|
|
|
422
419
|
this.available.push(resource);
|
|
423
420
|
}
|
|
424
421
|
}
|
|
425
|
-
|
|
422
|
+
|
|
426
423
|
async withResource(operation) {
|
|
427
424
|
const resource = await this.acquire();
|
|
428
425
|
try {
|
|
@@ -437,23 +434,22 @@ class ResourcePool {
|
|
|
437
434
|
### Caching Strategies for Batch Operations
|
|
438
435
|
|
|
439
436
|
#### LRU Cache for Batch Results
|
|
437
|
+
|
|
440
438
|
```javascript
|
|
441
439
|
class BatchCache {
|
|
442
440
|
constructor(maxSize = 100) {
|
|
443
441
|
this.cache = new Map();
|
|
444
442
|
this.maxSize = maxSize;
|
|
445
443
|
}
|
|
446
|
-
|
|
444
|
+
|
|
447
445
|
getCacheKey(items) {
|
|
448
|
-
return items.map(item =>
|
|
449
|
-
typeof item === 'object' ? JSON.stringify(item) : item
|
|
450
|
-
).join('|');
|
|
446
|
+
return items.map((item) => (typeof item === 'object' ? JSON.stringify(item) : item)).join('|');
|
|
451
447
|
}
|
|
452
|
-
|
|
448
|
+
|
|
453
449
|
async batchProcess(items, processor, options = {}) {
|
|
454
450
|
const { useCache = true, ttl = 300000 } = options;
|
|
455
451
|
const cacheKey = this.getCacheKey(items);
|
|
456
|
-
|
|
452
|
+
|
|
457
453
|
// Check cache
|
|
458
454
|
if (useCache && this.cache.has(cacheKey)) {
|
|
459
455
|
const cached = this.cache.get(cacheKey);
|
|
@@ -461,26 +457,24 @@ class BatchCache {
|
|
|
461
457
|
return cached.results;
|
|
462
458
|
}
|
|
463
459
|
}
|
|
464
|
-
|
|
460
|
+
|
|
465
461
|
// Process batch
|
|
466
|
-
const results = await Promise.allSettled(
|
|
467
|
-
|
|
468
|
-
);
|
|
469
|
-
|
|
462
|
+
const results = await Promise.allSettled(items.map((item) => processor(item)));
|
|
463
|
+
|
|
470
464
|
// Update cache
|
|
471
465
|
if (useCache) {
|
|
472
466
|
this.cache.set(cacheKey, {
|
|
473
467
|
results,
|
|
474
|
-
timestamp: Date.now()
|
|
468
|
+
timestamp: Date.now(),
|
|
475
469
|
});
|
|
476
|
-
|
|
470
|
+
|
|
477
471
|
// Evict oldest if over limit
|
|
478
472
|
if (this.cache.size > this.maxSize) {
|
|
479
473
|
const firstKey = this.cache.keys().next().value;
|
|
480
474
|
this.cache.delete(firstKey);
|
|
481
475
|
}
|
|
482
476
|
}
|
|
483
|
-
|
|
477
|
+
|
|
484
478
|
return results;
|
|
485
479
|
}
|
|
486
480
|
}
|
|
@@ -489,6 +483,7 @@ class BatchCache {
|
|
|
489
483
|
### Monitoring and Profiling Guidelines
|
|
490
484
|
|
|
491
485
|
#### Performance Monitor
|
|
486
|
+
|
|
492
487
|
```javascript
|
|
493
488
|
class BatchPerformanceMonitor {
|
|
494
489
|
constructor() {
|
|
@@ -497,51 +492,50 @@ class BatchPerformanceMonitor {
|
|
|
497
492
|
successfulOperations: 0,
|
|
498
493
|
failedOperations: 0,
|
|
499
494
|
totalDuration: 0,
|
|
500
|
-
batchSizes: []
|
|
495
|
+
batchSizes: [],
|
|
501
496
|
};
|
|
502
497
|
}
|
|
503
|
-
|
|
498
|
+
|
|
504
499
|
async monitorBatch(batch, processor) {
|
|
505
500
|
const startTime = Date.now();
|
|
506
501
|
const startMemory = process.memoryUsage().heapUsed;
|
|
507
|
-
|
|
508
|
-
const results = await Promise.allSettled(
|
|
509
|
-
|
|
510
|
-
);
|
|
511
|
-
|
|
502
|
+
|
|
503
|
+
const results = await Promise.allSettled(batch.map((item) => processor(item)));
|
|
504
|
+
|
|
512
505
|
const duration = Date.now() - startTime;
|
|
513
506
|
const memoryDelta = process.memoryUsage().heapUsed - startMemory;
|
|
514
|
-
|
|
507
|
+
|
|
515
508
|
// Update metrics
|
|
516
509
|
this.metrics.totalOperations += batch.length;
|
|
517
|
-
this.metrics.successfulOperations += results.filter(r => r.status === 'fulfilled').length;
|
|
518
|
-
this.metrics.failedOperations += results.filter(r => r.status === 'rejected').length;
|
|
510
|
+
this.metrics.successfulOperations += results.filter((r) => r.status === 'fulfilled').length;
|
|
511
|
+
this.metrics.failedOperations += results.filter((r) => r.status === 'rejected').length;
|
|
519
512
|
this.metrics.totalDuration += duration;
|
|
520
513
|
this.metrics.batchSizes.push(batch.length);
|
|
521
|
-
|
|
514
|
+
|
|
522
515
|
// Log if performance degrades
|
|
523
516
|
const avgDuration = duration / batch.length;
|
|
524
517
|
if (avgDuration > 1000) {
|
|
525
518
|
console.warn(`Slow batch operation: ${avgDuration}ms per item`);
|
|
526
519
|
}
|
|
527
|
-
|
|
520
|
+
|
|
528
521
|
if (memoryDelta > 50 * 1024 * 1024) {
|
|
529
522
|
console.warn(`High memory usage in batch: ${(memoryDelta / 1024 / 1024).toFixed(2)}MB`);
|
|
530
523
|
}
|
|
531
|
-
|
|
524
|
+
|
|
532
525
|
return results;
|
|
533
526
|
}
|
|
534
|
-
|
|
527
|
+
|
|
535
528
|
getReport() {
|
|
536
|
-
const avgBatchSize =
|
|
529
|
+
const avgBatchSize =
|
|
530
|
+
this.metrics.batchSizes.reduce((a, b) => a + b, 0) / this.metrics.batchSizes.length;
|
|
537
531
|
const successRate = this.metrics.successfulOperations / this.metrics.totalOperations;
|
|
538
532
|
const avgDuration = this.metrics.totalDuration / this.metrics.totalOperations;
|
|
539
|
-
|
|
533
|
+
|
|
540
534
|
return {
|
|
541
535
|
totalOperations: this.metrics.totalOperations,
|
|
542
536
|
successRate: `${(successRate * 100).toFixed(2)}%`,
|
|
543
537
|
avgDuration: `${avgDuration.toFixed(2)}ms`,
|
|
544
|
-
avgBatchSize: avgBatchSize.toFixed(2)
|
|
538
|
+
avgBatchSize: avgBatchSize.toFixed(2),
|
|
545
539
|
};
|
|
546
540
|
}
|
|
547
541
|
}
|
|
@@ -554,35 +548,36 @@ class BatchPerformanceMonitor {
|
|
|
554
548
|
### Safe Parallel File Operations
|
|
555
549
|
|
|
556
550
|
#### File Locking for Concurrent Access
|
|
551
|
+
|
|
557
552
|
```javascript
|
|
558
553
|
class FileLockManager {
|
|
559
554
|
constructor() {
|
|
560
555
|
this.locks = new Map();
|
|
561
556
|
}
|
|
562
|
-
|
|
557
|
+
|
|
563
558
|
async withFileLock(filePath, operation, options = {}) {
|
|
564
559
|
const { timeout = 30000, retryInterval = 100 } = options;
|
|
565
560
|
const lockFile = `${filePath}.lock`;
|
|
566
561
|
const startTime = Date.now();
|
|
567
|
-
|
|
562
|
+
|
|
568
563
|
// Try to acquire lock
|
|
569
564
|
while (this.locks.has(filePath)) {
|
|
570
565
|
if (Date.now() - startTime > timeout) {
|
|
571
566
|
throw new Error(`Timeout acquiring lock for ${filePath}`);
|
|
572
567
|
}
|
|
573
|
-
await new Promise(resolve => setTimeout(resolve, retryInterval));
|
|
568
|
+
await new Promise((resolve) => setTimeout(resolve, retryInterval));
|
|
574
569
|
}
|
|
575
|
-
|
|
570
|
+
|
|
576
571
|
// Set lock
|
|
577
572
|
this.locks.set(filePath, {
|
|
578
573
|
pid: process.pid,
|
|
579
|
-
timestamp: Date.now()
|
|
574
|
+
timestamp: Date.now(),
|
|
580
575
|
});
|
|
581
|
-
|
|
576
|
+
|
|
582
577
|
try {
|
|
583
578
|
// Write lock file
|
|
584
579
|
await fs.writeFile(lockFile, JSON.stringify(this.locks.get(filePath)));
|
|
585
|
-
|
|
580
|
+
|
|
586
581
|
// Execute operation
|
|
587
582
|
return await operation();
|
|
588
583
|
} finally {
|
|
@@ -595,13 +590,9 @@ class FileLockManager {
|
|
|
595
590
|
}
|
|
596
591
|
}
|
|
597
592
|
}
|
|
598
|
-
|
|
593
|
+
|
|
599
594
|
async batchFileOperation(files, operation) {
|
|
600
|
-
return Promise.all(
|
|
601
|
-
files.map(file =>
|
|
602
|
-
this.withFileLock(file, () => operation(file))
|
|
603
|
-
)
|
|
604
|
-
);
|
|
595
|
+
return Promise.all(files.map((file) => this.withFileLock(file, () => operation(file))));
|
|
605
596
|
}
|
|
606
597
|
}
|
|
607
598
|
```
|
|
@@ -609,15 +600,16 @@ class FileLockManager {
|
|
|
609
600
|
### Preventing Race Conditions
|
|
610
601
|
|
|
611
602
|
#### Atomic Operations Pattern
|
|
603
|
+
|
|
612
604
|
```javascript
|
|
613
605
|
class AtomicBatchOperations {
|
|
614
606
|
async atomicWrite(filePath, content) {
|
|
615
607
|
const tempPath = `${filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
616
|
-
|
|
608
|
+
|
|
617
609
|
try {
|
|
618
610
|
// Write to temporary file
|
|
619
611
|
await fs.writeFile(tempPath, content, { flag: 'wx' });
|
|
620
|
-
|
|
612
|
+
|
|
621
613
|
// Atomic rename
|
|
622
614
|
await fs.rename(tempPath, filePath);
|
|
623
615
|
} catch (error) {
|
|
@@ -628,10 +620,10 @@ class AtomicBatchOperations {
|
|
|
628
620
|
throw error;
|
|
629
621
|
}
|
|
630
622
|
}
|
|
631
|
-
|
|
623
|
+
|
|
632
624
|
async atomicBatchWrite(fileContents) {
|
|
633
625
|
const tempFiles = [];
|
|
634
|
-
|
|
626
|
+
|
|
635
627
|
try {
|
|
636
628
|
// Write all temp files first
|
|
637
629
|
for (const { path, content } of fileContents) {
|
|
@@ -639,16 +631,12 @@ class AtomicBatchOperations {
|
|
|
639
631
|
tempFiles.push({ temp: tempPath, final: path });
|
|
640
632
|
await fs.writeFile(tempPath, content, { flag: 'wx' });
|
|
641
633
|
}
|
|
642
|
-
|
|
634
|
+
|
|
643
635
|
// Atomic rename all
|
|
644
|
-
await Promise.all(
|
|
645
|
-
tempFiles.map(({ temp, final }) => fs.rename(temp, final))
|
|
646
|
-
);
|
|
636
|
+
await Promise.all(tempFiles.map(({ temp, final }) => fs.rename(temp, final)));
|
|
647
637
|
} catch (error) {
|
|
648
638
|
// Cleanup all temp files on failure
|
|
649
|
-
await Promise.allSettled(
|
|
650
|
-
tempFiles.map(({ temp }) => fs.unlink(temp))
|
|
651
|
-
);
|
|
639
|
+
await Promise.allSettled(tempFiles.map(({ temp }) => fs.unlink(temp)));
|
|
652
640
|
throw error;
|
|
653
641
|
}
|
|
654
642
|
}
|
|
@@ -658,68 +646,69 @@ class AtomicBatchOperations {
|
|
|
658
646
|
### Secure Credential Handling in Batch Operations
|
|
659
647
|
|
|
660
648
|
#### Credential Manager
|
|
649
|
+
|
|
661
650
|
```javascript
|
|
662
651
|
class SecureCredentialManager {
|
|
663
652
|
constructor() {
|
|
664
653
|
this.credentials = new Map();
|
|
665
654
|
this.accessLog = [];
|
|
666
655
|
}
|
|
667
|
-
|
|
656
|
+
|
|
668
657
|
setCredential(key, value, options = {}) {
|
|
669
658
|
const { expiresIn = 3600000 } = options; // 1 hour default
|
|
670
|
-
|
|
659
|
+
|
|
671
660
|
this.credentials.set(key, {
|
|
672
661
|
value,
|
|
673
662
|
expiresAt: Date.now() + expiresIn,
|
|
674
|
-
accessed: 0
|
|
663
|
+
accessed: 0,
|
|
675
664
|
});
|
|
676
|
-
|
|
665
|
+
|
|
677
666
|
// Schedule cleanup
|
|
678
667
|
setTimeout(() => this.credentials.delete(key), expiresIn);
|
|
679
668
|
}
|
|
680
|
-
|
|
669
|
+
|
|
681
670
|
getCredential(key, requester) {
|
|
682
671
|
const cred = this.credentials.get(key);
|
|
683
|
-
|
|
672
|
+
|
|
684
673
|
if (!cred) {
|
|
685
674
|
this.logAccess(key, requester, false);
|
|
686
675
|
return null;
|
|
687
676
|
}
|
|
688
|
-
|
|
677
|
+
|
|
689
678
|
if (Date.now() > cred.expiresAt) {
|
|
690
679
|
this.credentials.delete(key);
|
|
691
680
|
this.logAccess(key, requester, false);
|
|
692
681
|
return null;
|
|
693
682
|
}
|
|
694
|
-
|
|
683
|
+
|
|
695
684
|
cred.accessed++;
|
|
696
685
|
this.logAccess(key, requester, true);
|
|
697
686
|
return cred.value;
|
|
698
687
|
}
|
|
699
|
-
|
|
688
|
+
|
|
700
689
|
logAccess(key, requester, success) {
|
|
701
690
|
this.accessLog.push({
|
|
702
691
|
timestamp: new Date().toISOString(),
|
|
703
692
|
key: key.substring(0, 4) + '****', // Partial key for security
|
|
704
693
|
requester,
|
|
705
|
-
success
|
|
694
|
+
success,
|
|
706
695
|
});
|
|
707
|
-
|
|
696
|
+
|
|
708
697
|
// Rotate log if too large
|
|
709
698
|
if (this.accessLog.length > 1000) {
|
|
710
699
|
this.accessLog = this.accessLog.slice(-500);
|
|
711
700
|
}
|
|
712
701
|
}
|
|
713
|
-
|
|
702
|
+
|
|
714
703
|
async batchOperationWithCredentials(operations, credentialKeys) {
|
|
715
704
|
const requester = `batch-${Date.now()}`;
|
|
716
|
-
|
|
705
|
+
|
|
717
706
|
// Validate all credentials exist
|
|
718
|
-
const missingCreds = credentialKeys.filter(key => !this.getCredential(key, requester));
|
|
707
|
+
const missingCreds = credentialKeys.filter((key) => !this.getCredential(key, requester));
|
|
719
708
|
if (missingCreds.length > 0) {
|
|
720
709
|
throw new Error(`Missing credentials: ${missingCreds.join(', ')}`);
|
|
721
710
|
}
|
|
722
|
-
|
|
711
|
+
|
|
723
712
|
// Execute operations
|
|
724
713
|
const results = await Promise.allSettled(
|
|
725
714
|
operations.map((op, index) => {
|
|
@@ -727,11 +716,11 @@ class SecureCredentialManager {
|
|
|
727
716
|
acc[key] = this.getCredential(key, requester);
|
|
728
717
|
return acc;
|
|
729
718
|
}, {});
|
|
730
|
-
|
|
719
|
+
|
|
731
720
|
return op(creds);
|
|
732
|
-
})
|
|
721
|
+
}),
|
|
733
722
|
);
|
|
734
|
-
|
|
723
|
+
|
|
735
724
|
return results;
|
|
736
725
|
}
|
|
737
726
|
}
|
|
@@ -740,6 +729,7 @@ class SecureCredentialManager {
|
|
|
740
729
|
### Audit Logging for Parallel Processes
|
|
741
730
|
|
|
742
731
|
#### Comprehensive Audit Logger
|
|
732
|
+
|
|
743
733
|
```javascript
|
|
744
734
|
class BatchAuditLogger {
|
|
745
735
|
constructor(logPath) {
|
|
@@ -747,7 +737,7 @@ class BatchAuditLogger {
|
|
|
747
737
|
this.buffer = [];
|
|
748
738
|
this.flushInterval = setInterval(() => this.flush(), 5000);
|
|
749
739
|
}
|
|
750
|
-
|
|
740
|
+
|
|
751
741
|
async logBatchOperation(operation, items, results) {
|
|
752
742
|
const entry = {
|
|
753
743
|
timestamp: new Date().toISOString(),
|
|
@@ -759,36 +749,34 @@ class BatchAuditLogger {
|
|
|
759
749
|
user: process.env.USER || 'unknown',
|
|
760
750
|
pid: process.pid,
|
|
761
751
|
memory: process.memoryUsage(),
|
|
762
|
-
errors: results.failed.map(f => ({
|
|
752
|
+
errors: results.failed.map((f) => ({
|
|
763
753
|
item: f.item,
|
|
764
|
-
error: f.error.message
|
|
765
|
-
}))
|
|
754
|
+
error: f.error.message,
|
|
755
|
+
})),
|
|
766
756
|
};
|
|
767
|
-
|
|
757
|
+
|
|
768
758
|
this.buffer.push(entry);
|
|
769
|
-
|
|
759
|
+
|
|
770
760
|
if (this.buffer.length >= 100) {
|
|
771
761
|
await this.flush();
|
|
772
762
|
}
|
|
773
763
|
}
|
|
774
|
-
|
|
764
|
+
|
|
775
765
|
async flush() {
|
|
776
766
|
if (this.buffer.length === 0) return;
|
|
777
|
-
|
|
767
|
+
|
|
778
768
|
const entries = this.buffer.splice(0, this.buffer.length);
|
|
779
|
-
const logContent = entries.map(e => JSON.stringify(e)).join('\n') + '\n';
|
|
780
|
-
|
|
769
|
+
const logContent = entries.map((e) => JSON.stringify(e)).join('\n') + '\n';
|
|
770
|
+
|
|
781
771
|
await fs.appendFile(this.logPath, logContent);
|
|
782
772
|
}
|
|
783
|
-
|
|
773
|
+
|
|
784
774
|
async auditedBatchProcess(items, processor, metadata = {}) {
|
|
785
775
|
const startTime = Date.now();
|
|
786
776
|
const results = { success: [], failed: [] };
|
|
787
|
-
|
|
788
|
-
const batchResults = await Promise.allSettled(
|
|
789
|
-
|
|
790
|
-
);
|
|
791
|
-
|
|
777
|
+
|
|
778
|
+
const batchResults = await Promise.allSettled(items.map((item) => processor(item)));
|
|
779
|
+
|
|
792
780
|
batchResults.forEach((result, index) => {
|
|
793
781
|
if (result.status === 'fulfilled') {
|
|
794
782
|
results.success.push({ item: items[index], result: result.value });
|
|
@@ -796,14 +784,14 @@ class BatchAuditLogger {
|
|
|
796
784
|
results.failed.push({ item: items[index], error: result.reason });
|
|
797
785
|
}
|
|
798
786
|
});
|
|
799
|
-
|
|
787
|
+
|
|
800
788
|
results.duration = Date.now() - startTime;
|
|
801
|
-
|
|
789
|
+
|
|
802
790
|
await this.logBatchOperation(processor, items, results);
|
|
803
|
-
|
|
791
|
+
|
|
804
792
|
return results;
|
|
805
793
|
}
|
|
806
|
-
|
|
794
|
+
|
|
807
795
|
destroy() {
|
|
808
796
|
clearInterval(this.flushInterval);
|
|
809
797
|
this.flush();
|
|
@@ -818,15 +806,16 @@ class BatchAuditLogger {
|
|
|
818
806
|
### Graceful Degradation Patterns
|
|
819
807
|
|
|
820
808
|
#### Progressive Degradation
|
|
809
|
+
|
|
821
810
|
```javascript
|
|
822
811
|
class ProgressiveDegradation {
|
|
823
812
|
constructor(strategies) {
|
|
824
813
|
this.strategies = strategies; // Ordered from best to worst
|
|
825
814
|
}
|
|
826
|
-
|
|
815
|
+
|
|
827
816
|
async execute(item) {
|
|
828
817
|
let lastError;
|
|
829
|
-
|
|
818
|
+
|
|
830
819
|
for (const strategy of this.strategies) {
|
|
831
820
|
try {
|
|
832
821
|
return await strategy.execute(item);
|
|
@@ -835,14 +824,12 @@ class ProgressiveDegradation {
|
|
|
835
824
|
console.warn(`Strategy ${strategy.name} failed, trying next...`);
|
|
836
825
|
}
|
|
837
826
|
}
|
|
838
|
-
|
|
827
|
+
|
|
839
828
|
throw new Error(`All strategies failed. Last error: ${lastError.message}`);
|
|
840
829
|
}
|
|
841
|
-
|
|
830
|
+
|
|
842
831
|
async batchExecute(items) {
|
|
843
|
-
return Promise.allSettled(
|
|
844
|
-
items.map(item => this.execute(item))
|
|
845
|
-
);
|
|
832
|
+
return Promise.allSettled(items.map((item) => this.execute(item)));
|
|
846
833
|
}
|
|
847
834
|
}
|
|
848
835
|
|
|
@@ -854,28 +841,29 @@ const fileProcessor = new ProgressiveDegradation([
|
|
|
854
841
|
// Try fast in-memory processing
|
|
855
842
|
const content = await fs.readFile(file);
|
|
856
843
|
return processInMemory(content);
|
|
857
|
-
}
|
|
844
|
+
},
|
|
858
845
|
},
|
|
859
846
|
{
|
|
860
847
|
name: 'StreamProcessor',
|
|
861
848
|
execute: async (file) => {
|
|
862
849
|
// Fall back to streaming for large files
|
|
863
850
|
return processStream(fs.createReadStream(file));
|
|
864
|
-
}
|
|
851
|
+
},
|
|
865
852
|
},
|
|
866
853
|
{
|
|
867
854
|
name: 'ChunkedProcessor',
|
|
868
855
|
execute: async (file) => {
|
|
869
856
|
// Last resort: process in small chunks
|
|
870
857
|
return processInChunks(file, { chunkSize: 1024 });
|
|
871
|
-
}
|
|
872
|
-
}
|
|
858
|
+
},
|
|
859
|
+
},
|
|
873
860
|
]);
|
|
874
861
|
```
|
|
875
862
|
|
|
876
863
|
### Retry Mechanisms for Batch Operations
|
|
877
864
|
|
|
878
865
|
#### Exponential Backoff with Jitter
|
|
866
|
+
|
|
879
867
|
```javascript
|
|
880
868
|
class BatchRetryManager {
|
|
881
869
|
constructor(options = {}) {
|
|
@@ -884,49 +872,44 @@ class BatchRetryManager {
|
|
|
884
872
|
this.maxDelay = options.maxDelay || 30000;
|
|
885
873
|
this.jitter = options.jitter || 0.1;
|
|
886
874
|
}
|
|
887
|
-
|
|
875
|
+
|
|
888
876
|
calculateDelay(attempt) {
|
|
889
|
-
const exponentialDelay = Math.min(
|
|
890
|
-
|
|
891
|
-
this.maxDelay
|
|
892
|
-
);
|
|
893
|
-
|
|
877
|
+
const exponentialDelay = Math.min(this.baseDelay * Math.pow(2, attempt), this.maxDelay);
|
|
878
|
+
|
|
894
879
|
const jitterRange = exponentialDelay * this.jitter;
|
|
895
880
|
const jitter = (Math.random() - 0.5) * 2 * jitterRange;
|
|
896
|
-
|
|
881
|
+
|
|
897
882
|
return exponentialDelay + jitter;
|
|
898
883
|
}
|
|
899
|
-
|
|
884
|
+
|
|
900
885
|
async retryOperation(operation, context = {}) {
|
|
901
886
|
let lastError;
|
|
902
|
-
|
|
887
|
+
|
|
903
888
|
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
904
889
|
try {
|
|
905
890
|
return await operation();
|
|
906
891
|
} catch (error) {
|
|
907
892
|
lastError = error;
|
|
908
|
-
|
|
893
|
+
|
|
909
894
|
if (attempt < this.maxRetries) {
|
|
910
895
|
const delay = this.calculateDelay(attempt);
|
|
911
896
|
console.log(`Retry ${attempt + 1}/${this.maxRetries} after ${delay}ms`);
|
|
912
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
897
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
913
898
|
}
|
|
914
899
|
}
|
|
915
900
|
}
|
|
916
|
-
|
|
901
|
+
|
|
917
902
|
throw new Error(`Failed after ${this.maxRetries} retries: ${lastError.message}`);
|
|
918
903
|
}
|
|
919
|
-
|
|
904
|
+
|
|
920
905
|
async batchRetry(items, processor) {
|
|
921
906
|
const results = await Promise.allSettled(
|
|
922
|
-
items.map(item =>
|
|
923
|
-
this.retryOperation(() => processor(item), { item })
|
|
924
|
-
)
|
|
907
|
+
items.map((item) => this.retryOperation(() => processor(item), { item })),
|
|
925
908
|
);
|
|
926
|
-
|
|
909
|
+
|
|
927
910
|
return {
|
|
928
|
-
successful: results.filter(r => r.status === 'fulfilled').map(r => r.value),
|
|
929
|
-
failed: results.filter(r => r.status === 'rejected').map(r => r.reason)
|
|
911
|
+
successful: results.filter((r) => r.status === 'fulfilled').map((r) => r.value),
|
|
912
|
+
failed: results.filter((r) => r.status === 'rejected').map((r) => r.reason),
|
|
930
913
|
};
|
|
931
914
|
}
|
|
932
915
|
}
|
|
@@ -935,13 +918,14 @@ class BatchRetryManager {
|
|
|
935
918
|
### Partial Failure Recovery
|
|
936
919
|
|
|
937
920
|
#### Checkpoint and Resume Pattern
|
|
921
|
+
|
|
938
922
|
```javascript
|
|
939
923
|
class CheckpointBatchProcessor {
|
|
940
924
|
constructor(checkpointPath) {
|
|
941
925
|
this.checkpointPath = checkpointPath;
|
|
942
926
|
this.processed = new Set();
|
|
943
927
|
}
|
|
944
|
-
|
|
928
|
+
|
|
945
929
|
async loadCheckpoint() {
|
|
946
930
|
try {
|
|
947
931
|
const data = await fs.readFile(this.checkpointPath, 'utf8');
|
|
@@ -951,33 +935,28 @@ class CheckpointBatchProcessor {
|
|
|
951
935
|
this.processed = new Set();
|
|
952
936
|
}
|
|
953
937
|
}
|
|
954
|
-
|
|
938
|
+
|
|
955
939
|
async saveCheckpoint() {
|
|
956
|
-
await fs.writeFile(
|
|
957
|
-
this.checkpointPath,
|
|
958
|
-
JSON.stringify([...this.processed])
|
|
959
|
-
);
|
|
940
|
+
await fs.writeFile(this.checkpointPath, JSON.stringify([...this.processed]));
|
|
960
941
|
}
|
|
961
|
-
|
|
942
|
+
|
|
962
943
|
async processBatchWithCheckpoints(items, processor, options = {}) {
|
|
963
944
|
const { batchSize = 10, saveInterval = 100 } = options;
|
|
964
|
-
|
|
945
|
+
|
|
965
946
|
await this.loadCheckpoint();
|
|
966
|
-
|
|
967
|
-
const remaining = items.filter(item => !this.processed.has(item.id));
|
|
947
|
+
|
|
948
|
+
const remaining = items.filter((item) => !this.processed.has(item.id));
|
|
968
949
|
const results = { successful: [], failed: [] };
|
|
969
950
|
let processedCount = 0;
|
|
970
|
-
|
|
951
|
+
|
|
971
952
|
for (let i = 0; i < remaining.length; i += batchSize) {
|
|
972
953
|
const batch = remaining.slice(i, i + batchSize);
|
|
973
|
-
|
|
974
|
-
const batchResults = await Promise.allSettled(
|
|
975
|
-
|
|
976
|
-
);
|
|
977
|
-
|
|
954
|
+
|
|
955
|
+
const batchResults = await Promise.allSettled(batch.map((item) => processor(item)));
|
|
956
|
+
|
|
978
957
|
batchResults.forEach((result, index) => {
|
|
979
958
|
const item = batch[index];
|
|
980
|
-
|
|
959
|
+
|
|
981
960
|
if (result.status === 'fulfilled') {
|
|
982
961
|
results.successful.push({ item, result: result.value });
|
|
983
962
|
this.processed.add(item.id);
|
|
@@ -986,26 +965,26 @@ class CheckpointBatchProcessor {
|
|
|
986
965
|
results.failed.push({ item, error: result.reason });
|
|
987
966
|
}
|
|
988
967
|
});
|
|
989
|
-
|
|
968
|
+
|
|
990
969
|
// Save checkpoint periodically
|
|
991
970
|
if (processedCount >= saveInterval) {
|
|
992
971
|
await this.saveCheckpoint();
|
|
993
972
|
processedCount = 0;
|
|
994
973
|
}
|
|
995
974
|
}
|
|
996
|
-
|
|
975
|
+
|
|
997
976
|
// Final checkpoint save
|
|
998
977
|
await this.saveCheckpoint();
|
|
999
|
-
|
|
978
|
+
|
|
1000
979
|
return results;
|
|
1001
980
|
}
|
|
1002
|
-
|
|
981
|
+
|
|
1003
982
|
async retry() {
|
|
1004
983
|
// Load checkpoint and find failed items
|
|
1005
984
|
await this.loadCheckpoint();
|
|
1006
985
|
const allItems = await this.getAllItems();
|
|
1007
|
-
const failed = allItems.filter(item => !this.processed.has(item.id));
|
|
1008
|
-
|
|
986
|
+
const failed = allItems.filter((item) => !this.processed.has(item.id));
|
|
987
|
+
|
|
1009
988
|
return this.processBatchWithCheckpoints(failed, this.processor);
|
|
1010
989
|
}
|
|
1011
990
|
}
|
|
@@ -1014,27 +993,28 @@ class CheckpointBatchProcessor {
|
|
|
1014
993
|
### Transaction-like Behavior in Batch Operations
|
|
1015
994
|
|
|
1016
995
|
#### Two-Phase Commit Pattern
|
|
996
|
+
|
|
1017
997
|
```javascript
|
|
1018
998
|
class BatchTransaction {
|
|
1019
999
|
constructor() {
|
|
1020
1000
|
this.operations = [];
|
|
1021
1001
|
this.preparedOps = [];
|
|
1022
1002
|
}
|
|
1023
|
-
|
|
1003
|
+
|
|
1024
1004
|
add(operation, rollback) {
|
|
1025
1005
|
this.operations.push({ operation, rollback });
|
|
1026
1006
|
}
|
|
1027
|
-
|
|
1007
|
+
|
|
1028
1008
|
async prepare() {
|
|
1029
1009
|
this.preparedOps = [];
|
|
1030
|
-
|
|
1010
|
+
|
|
1031
1011
|
for (const { operation, rollback } of this.operations) {
|
|
1032
1012
|
try {
|
|
1033
1013
|
const prepared = await operation.prepare();
|
|
1034
|
-
this.preparedOps.push({
|
|
1035
|
-
operation,
|
|
1036
|
-
rollback,
|
|
1037
|
-
prepared
|
|
1014
|
+
this.preparedOps.push({
|
|
1015
|
+
operation,
|
|
1016
|
+
rollback,
|
|
1017
|
+
prepared,
|
|
1038
1018
|
});
|
|
1039
1019
|
} catch (error) {
|
|
1040
1020
|
// Rollback any prepared operations
|
|
@@ -1042,21 +1022,21 @@ class BatchTransaction {
|
|
|
1042
1022
|
throw new Error(`Prepare failed: ${error.message}`);
|
|
1043
1023
|
}
|
|
1044
1024
|
}
|
|
1045
|
-
|
|
1025
|
+
|
|
1046
1026
|
return true;
|
|
1047
1027
|
}
|
|
1048
|
-
|
|
1028
|
+
|
|
1049
1029
|
async commit() {
|
|
1050
1030
|
const results = [];
|
|
1051
1031
|
let commitIndex = 0;
|
|
1052
|
-
|
|
1032
|
+
|
|
1053
1033
|
try {
|
|
1054
1034
|
for (const { operation, prepared } of this.preparedOps) {
|
|
1055
1035
|
const result = await operation.commit(prepared);
|
|
1056
1036
|
results.push(result);
|
|
1057
1037
|
commitIndex++;
|
|
1058
1038
|
}
|
|
1059
|
-
|
|
1039
|
+
|
|
1060
1040
|
return results;
|
|
1061
1041
|
} catch (error) {
|
|
1062
1042
|
// Partial commit occurred, rollback committed operations
|
|
@@ -1064,29 +1044,23 @@ class BatchTransaction {
|
|
|
1064
1044
|
throw new Error(`Commit failed at operation ${commitIndex}: ${error.message}`);
|
|
1065
1045
|
}
|
|
1066
1046
|
}
|
|
1067
|
-
|
|
1047
|
+
|
|
1068
1048
|
async rollback() {
|
|
1069
1049
|
const rollbackResults = await Promise.allSettled(
|
|
1070
|
-
this.preparedOps.map(({ rollback, prepared }) =>
|
|
1071
|
-
rollback(prepared)
|
|
1072
|
-
)
|
|
1050
|
+
this.preparedOps.map(({ rollback, prepared }) => rollback(prepared)),
|
|
1073
1051
|
);
|
|
1074
|
-
|
|
1075
|
-
const failed = rollbackResults.filter(r => r.status === 'rejected');
|
|
1052
|
+
|
|
1053
|
+
const failed = rollbackResults.filter((r) => r.status === 'rejected');
|
|
1076
1054
|
if (failed.length > 0) {
|
|
1077
1055
|
console.error(`${failed.length} rollback operations failed`);
|
|
1078
1056
|
}
|
|
1079
1057
|
}
|
|
1080
|
-
|
|
1058
|
+
|
|
1081
1059
|
async partialRollback(fromIndex) {
|
|
1082
1060
|
const toRollback = this.preparedOps.slice(0, fromIndex);
|
|
1083
|
-
await Promise.allSettled(
|
|
1084
|
-
toRollback.map(({ rollback, prepared }) =>
|
|
1085
|
-
rollback(prepared)
|
|
1086
|
-
)
|
|
1087
|
-
);
|
|
1061
|
+
await Promise.allSettled(toRollback.map(({ rollback, prepared }) => rollback(prepared)));
|
|
1088
1062
|
}
|
|
1089
|
-
|
|
1063
|
+
|
|
1090
1064
|
async execute() {
|
|
1091
1065
|
try {
|
|
1092
1066
|
await this.prepare();
|
|
@@ -1102,7 +1076,7 @@ class BatchTransaction {
|
|
|
1102
1076
|
const transaction = new BatchTransaction();
|
|
1103
1077
|
|
|
1104
1078
|
// Add file operations
|
|
1105
|
-
files.forEach(file => {
|
|
1079
|
+
files.forEach((file) => {
|
|
1106
1080
|
transaction.add(
|
|
1107
1081
|
{
|
|
1108
1082
|
prepare: async () => {
|
|
@@ -1111,11 +1085,11 @@ files.forEach(file => {
|
|
|
1111
1085
|
},
|
|
1112
1086
|
commit: async ({ file }) => {
|
|
1113
1087
|
await fs.writeFile(file, newContent);
|
|
1114
|
-
}
|
|
1088
|
+
},
|
|
1115
1089
|
},
|
|
1116
1090
|
async ({ file, backup }) => {
|
|
1117
1091
|
await fs.writeFile(file, backup);
|
|
1118
|
-
}
|
|
1092
|
+
},
|
|
1119
1093
|
);
|
|
1120
1094
|
});
|
|
1121
1095
|
|
|
@@ -1129,54 +1103,58 @@ await transaction.execute();
|
|
|
1129
1103
|
### Unit Testing Parallel Code
|
|
1130
1104
|
|
|
1131
1105
|
#### Testing Batch Operations
|
|
1106
|
+
|
|
1132
1107
|
```javascript
|
|
1133
1108
|
describe('BatchProcessor', () => {
|
|
1134
1109
|
let processor;
|
|
1135
|
-
|
|
1110
|
+
|
|
1136
1111
|
beforeEach(() => {
|
|
1137
1112
|
processor = new BatchProcessor();
|
|
1138
1113
|
});
|
|
1139
|
-
|
|
1114
|
+
|
|
1140
1115
|
it('should process all items successfully', async () => {
|
|
1141
1116
|
const items = [1, 2, 3, 4, 5];
|
|
1142
1117
|
const mockProcessor = jest.fn().mockResolvedValue('processed');
|
|
1143
|
-
|
|
1118
|
+
|
|
1144
1119
|
const results = await processor.processBatch(items, mockProcessor);
|
|
1145
|
-
|
|
1120
|
+
|
|
1146
1121
|
expect(mockProcessor).toHaveBeenCalledTimes(5);
|
|
1147
1122
|
expect(results.successful).toHaveLength(5);
|
|
1148
1123
|
expect(results.failed).toHaveLength(0);
|
|
1149
1124
|
});
|
|
1150
|
-
|
|
1125
|
+
|
|
1151
1126
|
it('should handle partial failures', async () => {
|
|
1152
1127
|
const items = [1, 2, 3, 4, 5];
|
|
1153
|
-
const mockProcessor = jest
|
|
1128
|
+
const mockProcessor = jest
|
|
1129
|
+
.fn()
|
|
1154
1130
|
.mockResolvedValueOnce('success')
|
|
1155
1131
|
.mockRejectedValueOnce(new Error('fail'))
|
|
1156
1132
|
.mockResolvedValueOnce('success')
|
|
1157
1133
|
.mockRejectedValueOnce(new Error('fail'))
|
|
1158
1134
|
.mockResolvedValueOnce('success');
|
|
1159
|
-
|
|
1135
|
+
|
|
1160
1136
|
const results = await processor.processBatch(items, mockProcessor);
|
|
1161
|
-
|
|
1137
|
+
|
|
1162
1138
|
expect(results.successful).toHaveLength(3);
|
|
1163
1139
|
expect(results.failed).toHaveLength(2);
|
|
1164
1140
|
});
|
|
1165
|
-
|
|
1141
|
+
|
|
1166
1142
|
it('should respect batch size limits', async () => {
|
|
1167
|
-
const items = Array(100)
|
|
1143
|
+
const items = Array(100)
|
|
1144
|
+
.fill(0)
|
|
1145
|
+
.map((_, i) => i);
|
|
1168
1146
|
const mockProcessor = jest.fn().mockResolvedValue('processed');
|
|
1169
1147
|
const concurrentCalls = [];
|
|
1170
|
-
|
|
1148
|
+
|
|
1171
1149
|
mockProcessor.mockImplementation(async (item) => {
|
|
1172
1150
|
const currentCalls = mockProcessor.mock.calls.length;
|
|
1173
1151
|
concurrentCalls.push(currentCalls);
|
|
1174
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
1152
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1175
1153
|
return 'processed';
|
|
1176
1154
|
});
|
|
1177
|
-
|
|
1155
|
+
|
|
1178
1156
|
await processor.processBatch(items, mockProcessor, { batchSize: 5 });
|
|
1179
|
-
|
|
1157
|
+
|
|
1180
1158
|
// Check that no more than 5 operations run concurrently
|
|
1181
1159
|
const maxConcurrent = Math.max(...concurrentCalls);
|
|
1182
1160
|
expect(maxConcurrent).toBeLessThanOrEqual(5);
|
|
@@ -1185,43 +1163,46 @@ describe('BatchProcessor', () => {
|
|
|
1185
1163
|
```
|
|
1186
1164
|
|
|
1187
1165
|
#### Testing Race Conditions
|
|
1166
|
+
|
|
1188
1167
|
```javascript
|
|
1189
1168
|
describe('Concurrent Operations', () => {
|
|
1190
1169
|
it('should handle concurrent writes safely', async () => {
|
|
1191
1170
|
const fileManager = new ConcurrentFileManager();
|
|
1192
1171
|
const filePath = '/tmp/test-file.txt';
|
|
1193
|
-
|
|
1172
|
+
|
|
1194
1173
|
// Simulate concurrent writes
|
|
1195
|
-
const writes = Array(10)
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1174
|
+
const writes = Array(10)
|
|
1175
|
+
.fill(0)
|
|
1176
|
+
.map((_, i) => fileManager.atomicWrite(filePath, `content-${i}`));
|
|
1177
|
+
|
|
1199
1178
|
await Promise.all(writes);
|
|
1200
|
-
|
|
1179
|
+
|
|
1201
1180
|
// Verify file exists and has valid content
|
|
1202
1181
|
const content = await fs.readFile(filePath, 'utf8');
|
|
1203
1182
|
expect(content).toMatch(/content-\d/);
|
|
1204
|
-
|
|
1183
|
+
|
|
1205
1184
|
// Verify no temp files left behind
|
|
1206
1185
|
const tempFiles = await glob(`${filePath}.tmp.*`);
|
|
1207
1186
|
expect(tempFiles).toHaveLength(0);
|
|
1208
1187
|
});
|
|
1209
|
-
|
|
1188
|
+
|
|
1210
1189
|
it('should prevent data corruption with locks', async () => {
|
|
1211
1190
|
const lockManager = new FileLockManager();
|
|
1212
1191
|
const counter = { value: 0 };
|
|
1213
|
-
|
|
1192
|
+
|
|
1214
1193
|
// Concurrent increments
|
|
1215
|
-
const operations = Array(100)
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1194
|
+
const operations = Array(100)
|
|
1195
|
+
.fill(0)
|
|
1196
|
+
.map(() =>
|
|
1197
|
+
lockManager.withLock('counter', async () => {
|
|
1198
|
+
const current = counter.value;
|
|
1199
|
+
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
1200
|
+
counter.value = current + 1;
|
|
1201
|
+
}),
|
|
1202
|
+
);
|
|
1203
|
+
|
|
1223
1204
|
await Promise.all(operations);
|
|
1224
|
-
|
|
1205
|
+
|
|
1225
1206
|
expect(counter.value).toBe(100);
|
|
1226
1207
|
});
|
|
1227
1208
|
});
|
|
@@ -1230,81 +1211,83 @@ describe('Concurrent Operations', () => {
|
|
|
1230
1211
|
### Integration Testing Strategies
|
|
1231
1212
|
|
|
1232
1213
|
#### End-to-End Batch Testing
|
|
1214
|
+
|
|
1233
1215
|
```javascript
|
|
1234
1216
|
describe('Batch Processing Integration', () => {
|
|
1235
1217
|
let testDir;
|
|
1236
1218
|
let processor;
|
|
1237
|
-
|
|
1219
|
+
|
|
1238
1220
|
beforeEach(async () => {
|
|
1239
1221
|
testDir = await fs.mkdtemp('/tmp/batch-test-');
|
|
1240
1222
|
processor = new IntegratedBatchProcessor();
|
|
1241
1223
|
});
|
|
1242
|
-
|
|
1224
|
+
|
|
1243
1225
|
afterEach(async () => {
|
|
1244
1226
|
await fs.rm(testDir, { recursive: true });
|
|
1245
1227
|
});
|
|
1246
|
-
|
|
1228
|
+
|
|
1247
1229
|
it('should process file batch end-to-end', async () => {
|
|
1248
1230
|
// Setup test files
|
|
1249
1231
|
const files = await Promise.all(
|
|
1250
|
-
Array(20)
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1232
|
+
Array(20)
|
|
1233
|
+
.fill(0)
|
|
1234
|
+
.map(async (_, i) => {
|
|
1235
|
+
const path = `${testDir}/file-${i}.txt`;
|
|
1236
|
+
await fs.writeFile(path, `content ${i}`);
|
|
1237
|
+
return path;
|
|
1238
|
+
}),
|
|
1255
1239
|
);
|
|
1256
|
-
|
|
1240
|
+
|
|
1257
1241
|
// Process batch
|
|
1258
1242
|
const results = await processor.processFiles(files, {
|
|
1259
1243
|
batchSize: 5,
|
|
1260
|
-
transform: content => content.toUpperCase()
|
|
1244
|
+
transform: (content) => content.toUpperCase(),
|
|
1261
1245
|
});
|
|
1262
|
-
|
|
1246
|
+
|
|
1263
1247
|
// Verify results
|
|
1264
1248
|
expect(results.successful).toHaveLength(20);
|
|
1265
|
-
|
|
1249
|
+
|
|
1266
1250
|
// Verify files were transformed
|
|
1267
1251
|
for (let i = 0; i < 20; i++) {
|
|
1268
1252
|
const content = await fs.readFile(`${testDir}/file-${i}.txt`, 'utf8');
|
|
1269
1253
|
expect(content).toBe(`CONTENT ${i}`);
|
|
1270
1254
|
}
|
|
1271
1255
|
});
|
|
1272
|
-
|
|
1256
|
+
|
|
1273
1257
|
it('should recover from partial failures', async () => {
|
|
1274
1258
|
const checkpointPath = `${testDir}/checkpoint.json`;
|
|
1275
1259
|
const processor = new CheckpointBatchProcessor(checkpointPath);
|
|
1276
|
-
|
|
1260
|
+
|
|
1277
1261
|
// Create files, some will fail
|
|
1278
1262
|
const files = await Promise.all(
|
|
1279
|
-
Array(10)
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1263
|
+
Array(10)
|
|
1264
|
+
.fill(0)
|
|
1265
|
+
.map(async (_, i) => {
|
|
1266
|
+
const path = `${testDir}/file-${i}.txt`;
|
|
1267
|
+
// Make some files unreadable
|
|
1268
|
+
if (i % 3 === 0) {
|
|
1269
|
+
await fs.writeFile(path, 'content');
|
|
1270
|
+
await fs.chmod(path, 0o000);
|
|
1271
|
+
} else {
|
|
1272
|
+
await fs.writeFile(path, `content ${i}`);
|
|
1273
|
+
}
|
|
1274
|
+
return { id: `file-${i}`, path };
|
|
1275
|
+
}),
|
|
1290
1276
|
);
|
|
1291
|
-
|
|
1277
|
+
|
|
1292
1278
|
// First run - will have failures
|
|
1293
|
-
const firstRun = await processor.processBatchWithCheckpoints(
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
}
|
|
1299
|
-
);
|
|
1300
|
-
|
|
1279
|
+
const firstRun = await processor.processBatchWithCheckpoints(files, async (file) => {
|
|
1280
|
+
const content = await fs.readFile(file.path, 'utf8');
|
|
1281
|
+
return content.toUpperCase();
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1301
1284
|
expect(firstRun.failed.length).toBeGreaterThan(0);
|
|
1302
|
-
|
|
1285
|
+
|
|
1303
1286
|
// Fix permissions
|
|
1304
1287
|
for (let i = 0; i < 10; i += 3) {
|
|
1305
1288
|
await fs.chmod(`${testDir}/file-${i}.txt`, 0o644);
|
|
1306
1289
|
}
|
|
1307
|
-
|
|
1290
|
+
|
|
1308
1291
|
// Retry - should only process failed items
|
|
1309
1292
|
const retry = await processor.retry();
|
|
1310
1293
|
expect(retry.successful.length).toBe(firstRun.failed.length);
|
|
@@ -1315,80 +1298,77 @@ describe('Batch Processing Integration', () => {
|
|
|
1315
1298
|
### Performance Testing Guidelines
|
|
1316
1299
|
|
|
1317
1300
|
#### Load Testing Batch Operations
|
|
1301
|
+
|
|
1318
1302
|
```javascript
|
|
1319
1303
|
class BatchLoadTester {
|
|
1320
1304
|
constructor() {
|
|
1321
1305
|
this.metrics = [];
|
|
1322
1306
|
}
|
|
1323
|
-
|
|
1307
|
+
|
|
1324
1308
|
async runLoadTest(config) {
|
|
1325
|
-
const {
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
id: i,
|
|
1335
|
-
data: `test-data-${i}`
|
|
1336
|
-
}));
|
|
1337
|
-
|
|
1309
|
+
const { itemCount, batchSizes, processor, warmupRuns = 3, testRuns = 10 } = config;
|
|
1310
|
+
|
|
1311
|
+
const items = Array(itemCount)
|
|
1312
|
+
.fill(0)
|
|
1313
|
+
.map((_, i) => ({
|
|
1314
|
+
id: i,
|
|
1315
|
+
data: `test-data-${i}`,
|
|
1316
|
+
}));
|
|
1317
|
+
|
|
1338
1318
|
const results = {};
|
|
1339
|
-
|
|
1319
|
+
|
|
1340
1320
|
for (const batchSize of batchSizes) {
|
|
1341
1321
|
console.log(`Testing batch size: ${batchSize}`);
|
|
1342
|
-
|
|
1322
|
+
|
|
1343
1323
|
// Warmup runs
|
|
1344
1324
|
for (let i = 0; i < warmupRuns; i++) {
|
|
1345
1325
|
await this.runBatch(items, processor, batchSize);
|
|
1346
1326
|
}
|
|
1347
|
-
|
|
1327
|
+
|
|
1348
1328
|
// Test runs
|
|
1349
1329
|
const runMetrics = [];
|
|
1350
1330
|
for (let i = 0; i < testRuns; i++) {
|
|
1351
1331
|
const metrics = await this.runBatch(items, processor, batchSize);
|
|
1352
1332
|
runMetrics.push(metrics);
|
|
1353
1333
|
}
|
|
1354
|
-
|
|
1334
|
+
|
|
1355
1335
|
results[batchSize] = this.analyzeMetrics(runMetrics);
|
|
1356
1336
|
}
|
|
1357
|
-
|
|
1337
|
+
|
|
1358
1338
|
return results;
|
|
1359
1339
|
}
|
|
1360
|
-
|
|
1340
|
+
|
|
1361
1341
|
async runBatch(items, processor, batchSize) {
|
|
1362
1342
|
const startTime = Date.now();
|
|
1363
1343
|
const startMemory = process.memoryUsage();
|
|
1364
|
-
|
|
1344
|
+
|
|
1365
1345
|
const batchProcessor = new BatchProcessor({ batchSize });
|
|
1366
1346
|
const results = await batchProcessor.processBatch(items, processor);
|
|
1367
|
-
|
|
1347
|
+
|
|
1368
1348
|
const endTime = Date.now();
|
|
1369
1349
|
const endMemory = process.memoryUsage();
|
|
1370
|
-
|
|
1350
|
+
|
|
1371
1351
|
return {
|
|
1372
1352
|
duration: endTime - startTime,
|
|
1373
1353
|
throughput: items.length / ((endTime - startTime) / 1000),
|
|
1374
1354
|
memoryDelta: endMemory.heapUsed - startMemory.heapUsed,
|
|
1375
1355
|
successRate: results.successful.length / items.length,
|
|
1376
|
-
batchSize
|
|
1356
|
+
batchSize,
|
|
1377
1357
|
};
|
|
1378
1358
|
}
|
|
1379
|
-
|
|
1359
|
+
|
|
1380
1360
|
analyzeMetrics(metrics) {
|
|
1381
|
-
const durations = metrics.map(m => m.duration);
|
|
1382
|
-
const throughputs = metrics.map(m => m.throughput);
|
|
1383
|
-
const memoryDeltas = metrics.map(m => m.memoryDelta);
|
|
1384
|
-
|
|
1361
|
+
const durations = metrics.map((m) => m.duration);
|
|
1362
|
+
const throughputs = metrics.map((m) => m.throughput);
|
|
1363
|
+
const memoryDeltas = metrics.map((m) => m.memoryDelta);
|
|
1364
|
+
|
|
1385
1365
|
return {
|
|
1386
1366
|
avgDuration: durations.reduce((a, b) => a + b) / durations.length,
|
|
1387
1367
|
minDuration: Math.min(...durations),
|
|
1388
1368
|
maxDuration: Math.max(...durations),
|
|
1389
1369
|
avgThroughput: throughputs.reduce((a, b) => a + b) / throughputs.length,
|
|
1390
1370
|
avgMemoryDelta: memoryDeltas.reduce((a, b) => a + b) / memoryDeltas.length,
|
|
1391
|
-
successRate: metrics[0].successRate
|
|
1371
|
+
successRate: metrics[0].successRate,
|
|
1392
1372
|
};
|
|
1393
1373
|
}
|
|
1394
1374
|
}
|
|
@@ -1400,20 +1380,21 @@ const results = await tester.runLoadTest({
|
|
|
1400
1380
|
batchSizes: [1, 5, 10, 20, 50, 100],
|
|
1401
1381
|
processor: async (item) => {
|
|
1402
1382
|
// Simulate work
|
|
1403
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
1383
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
1404
1384
|
return item.data.toUpperCase();
|
|
1405
|
-
}
|
|
1385
|
+
},
|
|
1406
1386
|
});
|
|
1407
1387
|
|
|
1408
|
-
console.log(
|
|
1409
|
-
|
|
1410
|
-
|
|
1388
|
+
console.log(
|
|
1389
|
+
'Optimal batch size:',
|
|
1390
|
+
Object.entries(results).sort(([, a], [, b]) => b.avgThroughput - a.avgThroughput)[0][0],
|
|
1411
1391
|
);
|
|
1412
1392
|
```
|
|
1413
1393
|
|
|
1414
1394
|
### Debugging Batch Operations
|
|
1415
1395
|
|
|
1416
1396
|
#### Batch Operation Debugger
|
|
1397
|
+
|
|
1417
1398
|
```javascript
|
|
1418
1399
|
class BatchDebugger {
|
|
1419
1400
|
constructor(options = {}) {
|
|
@@ -1421,28 +1402,24 @@ class BatchDebugger {
|
|
|
1421
1402
|
this.logLevel = options.logLevel || 'info';
|
|
1422
1403
|
this.traces = [];
|
|
1423
1404
|
}
|
|
1424
|
-
|
|
1405
|
+
|
|
1425
1406
|
async debugBatch(items, processor, options = {}) {
|
|
1426
1407
|
const { batchSize = 5, breakOn = [] } = options;
|
|
1427
1408
|
const results = { successful: [], failed: [] };
|
|
1428
|
-
|
|
1409
|
+
|
|
1429
1410
|
for (let i = 0; i < items.length; i += batchSize) {
|
|
1430
1411
|
const batch = items.slice(i, i + batchSize);
|
|
1431
1412
|
const batchId = `batch-${i / batchSize}`;
|
|
1432
|
-
|
|
1413
|
+
|
|
1433
1414
|
this.log('info', `Processing ${batchId} with ${batch.length} items`);
|
|
1434
|
-
|
|
1415
|
+
|
|
1435
1416
|
// Check for breakpoint
|
|
1436
1417
|
if (this.enableBreakpoints && breakOn.includes(batchId)) {
|
|
1437
1418
|
await this.breakpoint(batchId, batch);
|
|
1438
1419
|
}
|
|
1439
|
-
|
|
1440
|
-
const batchResults = await this.processBatchWithTrace(
|
|
1441
|
-
|
|
1442
|
-
processor,
|
|
1443
|
-
batchId
|
|
1444
|
-
);
|
|
1445
|
-
|
|
1420
|
+
|
|
1421
|
+
const batchResults = await this.processBatchWithTrace(batch, processor, batchId);
|
|
1422
|
+
|
|
1446
1423
|
// Collect results
|
|
1447
1424
|
batchResults.forEach((result, index) => {
|
|
1448
1425
|
if (result.status === 'fulfilled') {
|
|
@@ -1451,15 +1428,15 @@ class BatchDebugger {
|
|
|
1451
1428
|
results.failed.push({
|
|
1452
1429
|
item: batch[index],
|
|
1453
1430
|
error: result.reason,
|
|
1454
|
-
trace: this.traces.find(t => t.itemId === batch[index].id)
|
|
1431
|
+
trace: this.traces.find((t) => t.itemId === batch[index].id),
|
|
1455
1432
|
});
|
|
1456
1433
|
}
|
|
1457
1434
|
});
|
|
1458
1435
|
}
|
|
1459
|
-
|
|
1436
|
+
|
|
1460
1437
|
return results;
|
|
1461
1438
|
}
|
|
1462
|
-
|
|
1439
|
+
|
|
1463
1440
|
async processBatchWithTrace(batch, processor, batchId) {
|
|
1464
1441
|
return Promise.allSettled(
|
|
1465
1442
|
batch.map(async (item) => {
|
|
@@ -1467,18 +1444,18 @@ class BatchDebugger {
|
|
|
1467
1444
|
itemId: item.id,
|
|
1468
1445
|
batchId,
|
|
1469
1446
|
startTime: Date.now(),
|
|
1470
|
-
steps: []
|
|
1447
|
+
steps: [],
|
|
1471
1448
|
};
|
|
1472
|
-
|
|
1449
|
+
|
|
1473
1450
|
try {
|
|
1474
1451
|
const instrumentedProcessor = this.instrumentProcessor(processor, trace);
|
|
1475
1452
|
const result = await instrumentedProcessor(item);
|
|
1476
|
-
|
|
1453
|
+
|
|
1477
1454
|
trace.endTime = Date.now();
|
|
1478
1455
|
trace.duration = trace.endTime - trace.startTime;
|
|
1479
1456
|
trace.status = 'success';
|
|
1480
1457
|
trace.result = result;
|
|
1481
|
-
|
|
1458
|
+
|
|
1482
1459
|
this.traces.push(trace);
|
|
1483
1460
|
return result;
|
|
1484
1461
|
} catch (error) {
|
|
@@ -1487,85 +1464,85 @@ class BatchDebugger {
|
|
|
1487
1464
|
trace.status = 'error';
|
|
1488
1465
|
trace.error = {
|
|
1489
1466
|
message: error.message,
|
|
1490
|
-
stack: error.stack
|
|
1467
|
+
stack: error.stack,
|
|
1491
1468
|
};
|
|
1492
|
-
|
|
1469
|
+
|
|
1493
1470
|
this.traces.push(trace);
|
|
1494
1471
|
throw error;
|
|
1495
1472
|
}
|
|
1496
|
-
})
|
|
1473
|
+
}),
|
|
1497
1474
|
);
|
|
1498
1475
|
}
|
|
1499
|
-
|
|
1476
|
+
|
|
1500
1477
|
instrumentProcessor(processor, trace) {
|
|
1501
1478
|
return new Proxy(processor, {
|
|
1502
1479
|
apply: async (target, thisArg, args) => {
|
|
1503
1480
|
trace.steps.push({
|
|
1504
1481
|
type: 'function-call',
|
|
1505
1482
|
timestamp: Date.now(),
|
|
1506
|
-
args: args.map(arg => this.sanitizeForLog(arg))
|
|
1483
|
+
args: args.map((arg) => this.sanitizeForLog(arg)),
|
|
1507
1484
|
});
|
|
1508
|
-
|
|
1485
|
+
|
|
1509
1486
|
try {
|
|
1510
1487
|
const result = await target.apply(thisArg, args);
|
|
1511
1488
|
trace.steps.push({
|
|
1512
1489
|
type: 'function-return',
|
|
1513
1490
|
timestamp: Date.now(),
|
|
1514
|
-
result: this.sanitizeForLog(result)
|
|
1491
|
+
result: this.sanitizeForLog(result),
|
|
1515
1492
|
});
|
|
1516
1493
|
return result;
|
|
1517
1494
|
} catch (error) {
|
|
1518
1495
|
trace.steps.push({
|
|
1519
1496
|
type: 'function-error',
|
|
1520
1497
|
timestamp: Date.now(),
|
|
1521
|
-
error: error.message
|
|
1498
|
+
error: error.message,
|
|
1522
1499
|
});
|
|
1523
1500
|
throw error;
|
|
1524
1501
|
}
|
|
1525
|
-
}
|
|
1502
|
+
},
|
|
1526
1503
|
});
|
|
1527
1504
|
}
|
|
1528
|
-
|
|
1505
|
+
|
|
1529
1506
|
sanitizeForLog(value) {
|
|
1530
1507
|
if (typeof value === 'object' && value !== null) {
|
|
1531
1508
|
return JSON.stringify(value).substring(0, 100) + '...';
|
|
1532
1509
|
}
|
|
1533
1510
|
return value;
|
|
1534
1511
|
}
|
|
1535
|
-
|
|
1512
|
+
|
|
1536
1513
|
async breakpoint(batchId, batch) {
|
|
1537
1514
|
console.log(`\nBREAKPOINT: ${batchId}`);
|
|
1538
1515
|
console.log('Batch items:', batch);
|
|
1539
1516
|
console.log('Press any key to continue...');
|
|
1540
|
-
|
|
1541
|
-
await new Promise(resolve => {
|
|
1517
|
+
|
|
1518
|
+
await new Promise((resolve) => {
|
|
1542
1519
|
process.stdin.once('data', resolve);
|
|
1543
1520
|
});
|
|
1544
1521
|
}
|
|
1545
|
-
|
|
1522
|
+
|
|
1546
1523
|
log(level, message) {
|
|
1547
1524
|
const levels = ['debug', 'info', 'warn', 'error'];
|
|
1548
1525
|
if (levels.indexOf(level) >= levels.indexOf(this.logLevel)) {
|
|
1549
1526
|
console.log(`[${level.toUpperCase()}] ${message}`);
|
|
1550
1527
|
}
|
|
1551
1528
|
}
|
|
1552
|
-
|
|
1529
|
+
|
|
1553
1530
|
getTraceReport() {
|
|
1554
1531
|
const report = {
|
|
1555
1532
|
totalTraces: this.traces.length,
|
|
1556
|
-
successful: this.traces.filter(t => t.status === 'success').length,
|
|
1557
|
-
failed: this.traces.filter(t => t.status === 'error').length,
|
|
1533
|
+
successful: this.traces.filter((t) => t.status === 'success').length,
|
|
1534
|
+
failed: this.traces.filter((t) => t.status === 'error').length,
|
|
1558
1535
|
avgDuration: this.traces.reduce((sum, t) => sum + t.duration, 0) / this.traces.length,
|
|
1559
1536
|
slowestItems: this.traces
|
|
1560
1537
|
.sort((a, b) => b.duration - a.duration)
|
|
1561
1538
|
.slice(0, 5)
|
|
1562
|
-
.map(t => ({
|
|
1539
|
+
.map((t) => ({
|
|
1563
1540
|
itemId: t.itemId,
|
|
1564
1541
|
duration: t.duration,
|
|
1565
|
-
stepCount: t.steps.length
|
|
1566
|
-
}))
|
|
1542
|
+
stepCount: t.steps.length,
|
|
1543
|
+
})),
|
|
1567
1544
|
};
|
|
1568
|
-
|
|
1545
|
+
|
|
1569
1546
|
return report;
|
|
1570
1547
|
}
|
|
1571
1548
|
}
|
|
@@ -1583,36 +1560,42 @@ class BatchDebugger {
|
|
|
1583
1560
|
## Batch Operation Review Checklist
|
|
1584
1561
|
|
|
1585
1562
|
### Architecture & Design
|
|
1563
|
+
|
|
1586
1564
|
- [ ] Is batch processing the right approach for this use case?
|
|
1587
1565
|
- [ ] Are batch sizes appropriately configured?
|
|
1588
1566
|
- [ ] Is there proper resource management (memory, file handles, connections)?
|
|
1589
1567
|
- [ ] Are dependencies between operations properly handled?
|
|
1590
1568
|
|
|
1591
1569
|
### Error Handling
|
|
1570
|
+
|
|
1592
1571
|
- [ ] Are all Promise.all replaced with Promise.allSettled where appropriate?
|
|
1593
1572
|
- [ ] Is there proper error aggregation and reporting?
|
|
1594
1573
|
- [ ] Can the operation recover from partial failures?
|
|
1595
1574
|
- [ ] Are errors properly typed and descriptive?
|
|
1596
1575
|
|
|
1597
1576
|
### Performance
|
|
1577
|
+
|
|
1598
1578
|
- [ ] Has the batch size been tested for optimal performance?
|
|
1599
1579
|
- [ ] Is there proper backpressure handling?
|
|
1600
1580
|
- [ ] Are resources pooled appropriately?
|
|
1601
1581
|
- [ ] Has memory usage been profiled?
|
|
1602
1582
|
|
|
1603
1583
|
### Security
|
|
1584
|
+
|
|
1604
1585
|
- [ ] Are file operations atomic where necessary?
|
|
1605
1586
|
- [ ] Is there proper access control for parallel operations?
|
|
1606
1587
|
- [ ] Are credentials handled securely in batch contexts?
|
|
1607
1588
|
- [ ] Is there audit logging for sensitive operations?
|
|
1608
1589
|
|
|
1609
1590
|
### Testing
|
|
1591
|
+
|
|
1610
1592
|
- [ ] Are there unit tests for both success and failure cases?
|
|
1611
1593
|
- [ ] Has concurrent operation been tested?
|
|
1612
1594
|
- [ ] Are there integration tests for the full workflow?
|
|
1613
1595
|
- [ ] Has performance been benchmarked?
|
|
1614
1596
|
|
|
1615
1597
|
### Documentation
|
|
1598
|
+
|
|
1616
1599
|
- [ ] Is the batch operation's purpose clearly documented?
|
|
1617
1600
|
- [ ] Are configuration options explained?
|
|
1618
1601
|
- [ ] Are error scenarios documented?
|
|
@@ -1626,40 +1609,40 @@ class BatchDebugger {
|
|
|
1626
1609
|
```javascript
|
|
1627
1610
|
/**
|
|
1628
1611
|
* Processes multiple files in parallel batches with automatic retry and checkpointing.
|
|
1629
|
-
*
|
|
1612
|
+
*
|
|
1630
1613
|
* @description
|
|
1631
1614
|
* This function handles large-scale file processing with the following features:
|
|
1632
1615
|
* - Automatic batching to prevent resource exhaustion
|
|
1633
1616
|
* - Checkpoint/resume capability for long-running operations
|
|
1634
1617
|
* - Exponential backoff retry for transient failures
|
|
1635
1618
|
* - Comprehensive error reporting and audit logging
|
|
1636
|
-
*
|
|
1619
|
+
*
|
|
1637
1620
|
* @param {Array<FileItem>} files - Array of file items to process
|
|
1638
1621
|
* @param {ProcessorFunction} processor - Function to process each file
|
|
1639
1622
|
* @param {BatchOptions} options - Configuration options
|
|
1640
|
-
*
|
|
1623
|
+
*
|
|
1641
1624
|
* @param {number} [options.batchSize=10] - Number of files to process concurrently
|
|
1642
1625
|
* @param {number} [options.maxRetries=3] - Maximum retry attempts per file
|
|
1643
1626
|
* @param {string} [options.checkpointPath] - Path to store checkpoint data
|
|
1644
1627
|
* @param {boolean} [options.continueOnError=true] - Whether to continue processing on errors
|
|
1645
|
-
*
|
|
1628
|
+
*
|
|
1646
1629
|
* @returns {Promise<BatchResult>} Results including successful and failed operations
|
|
1647
|
-
*
|
|
1630
|
+
*
|
|
1648
1631
|
* @example
|
|
1649
1632
|
* const results = await batchProcessFiles(files, compressFile, {
|
|
1650
1633
|
* batchSize: 5,
|
|
1651
1634
|
* maxRetries: 3,
|
|
1652
1635
|
* checkpointPath: './checkpoint.json'
|
|
1653
1636
|
* });
|
|
1654
|
-
*
|
|
1637
|
+
*
|
|
1655
1638
|
* @throws {BatchProcessError} When all retries are exhausted
|
|
1656
1639
|
* @throws {CheckpointError} When checkpoint operations fail
|
|
1657
|
-
*
|
|
1640
|
+
*
|
|
1658
1641
|
* @performance
|
|
1659
1642
|
* - Memory: O(batchSize) - Only holds active batch in memory
|
|
1660
1643
|
* - Time: O(n/batchSize) - Processes in parallel batches
|
|
1661
1644
|
* - Optimal batch size: 2 * CPU cores for CPU-bound, 10-20 for I/O-bound
|
|
1662
|
-
*
|
|
1645
|
+
*
|
|
1663
1646
|
* @since 2.0.0
|
|
1664
1647
|
*/
|
|
1665
1648
|
async function batchProcessFiles(files, processor, options = {}) {
|
|
@@ -1706,33 +1689,39 @@ Closes #123
|
|
|
1706
1689
|
|
|
1707
1690
|
#### Batch Operations Runbook Template
|
|
1708
1691
|
|
|
1709
|
-
|
|
1692
|
+
````markdown
|
|
1710
1693
|
# Batch Operation Runbook: [Operation Name]
|
|
1711
1694
|
|
|
1712
1695
|
## Overview
|
|
1696
|
+
|
|
1713
1697
|
Brief description of what this batch operation does and when to use it.
|
|
1714
1698
|
|
|
1715
1699
|
## Prerequisites
|
|
1700
|
+
|
|
1716
1701
|
- Required permissions
|
|
1717
1702
|
- System requirements
|
|
1718
1703
|
- Dependencies
|
|
1719
1704
|
|
|
1720
1705
|
## Configuration
|
|
1706
|
+
|
|
1721
1707
|
```yaml
|
|
1722
|
-
batchSize: 10
|
|
1723
|
-
maxRetries: 3
|
|
1724
|
-
timeout: 300000
|
|
1708
|
+
batchSize: 10 # Optimal for standard workload
|
|
1709
|
+
maxRetries: 3 # Handles transient failures
|
|
1710
|
+
timeout: 300000 # 5 minutes per batch
|
|
1725
1711
|
checkpointEnabled: true
|
|
1726
1712
|
```
|
|
1713
|
+
````
|
|
1727
1714
|
|
|
1728
1715
|
## Normal Operation
|
|
1729
1716
|
|
|
1730
1717
|
### Starting the Process
|
|
1718
|
+
|
|
1731
1719
|
```bash
|
|
1732
1720
|
npm run batch:process -- --config=production.json
|
|
1733
1721
|
```
|
|
1734
1722
|
|
|
1735
1723
|
### Monitoring
|
|
1724
|
+
|
|
1736
1725
|
- Check logs at: `/var/log/batch-processor/`
|
|
1737
1726
|
- Metrics dashboard: `http://metrics.internal/batch-ops`
|
|
1738
1727
|
- Key metrics to watch:
|
|
@@ -1745,16 +1734,19 @@ npm run batch:process -- --config=production.json
|
|
|
1745
1734
|
### Common Issues
|
|
1746
1735
|
|
|
1747
1736
|
#### High Error Rate
|
|
1737
|
+
|
|
1748
1738
|
1. Check recent changes to data format
|
|
1749
1739
|
2. Verify external service availability
|
|
1750
1740
|
3. Review error logs for patterns
|
|
1751
1741
|
|
|
1752
1742
|
#### Performance Degradation
|
|
1743
|
+
|
|
1753
1744
|
1. Check batch size configuration
|
|
1754
1745
|
2. Monitor resource utilization
|
|
1755
1746
|
3. Look for lock contention
|
|
1756
1747
|
|
|
1757
1748
|
#### Memory Issues
|
|
1749
|
+
|
|
1758
1750
|
1. Reduce batch size
|
|
1759
1751
|
2. Enable streaming mode
|
|
1760
1752
|
3. Check for memory leaks
|
|
@@ -1762,20 +1754,24 @@ npm run batch:process -- --config=production.json
|
|
|
1762
1754
|
### Recovery Procedures
|
|
1763
1755
|
|
|
1764
1756
|
#### From Checkpoint
|
|
1757
|
+
|
|
1765
1758
|
```bash
|
|
1766
1759
|
npm run batch:resume -- --checkpoint=./checkpoint.json
|
|
1767
1760
|
```
|
|
1768
1761
|
|
|
1769
1762
|
#### Manual Retry
|
|
1763
|
+
|
|
1770
1764
|
```bash
|
|
1771
1765
|
npm run batch:retry -- --failed-items=./failed.json
|
|
1772
1766
|
```
|
|
1773
1767
|
|
|
1774
1768
|
## Escalation
|
|
1769
|
+
|
|
1775
1770
|
- Primary: @batch-ops-team
|
|
1776
1771
|
- Secondary: @platform-team
|
|
1777
1772
|
- Emergency: PagerDuty rotation
|
|
1778
|
-
|
|
1773
|
+
|
|
1774
|
+
````
|
|
1779
1775
|
|
|
1780
1776
|
---
|
|
1781
1777
|
|
|
@@ -1789,30 +1785,30 @@ npm run batch:retry -- --failed-items=./failed.json
|
|
|
1789
1785
|
async function batchReadFiles(filePaths, options = {}) {
|
|
1790
1786
|
const { batchSize = 5, encoding = 'utf8' } = options;
|
|
1791
1787
|
const fileHandles = new Map();
|
|
1792
|
-
|
|
1788
|
+
|
|
1793
1789
|
try {
|
|
1794
1790
|
const results = [];
|
|
1795
|
-
|
|
1791
|
+
|
|
1796
1792
|
for (let i = 0; i < filePaths.length; i += batchSize) {
|
|
1797
1793
|
const batch = filePaths.slice(i, i + batchSize);
|
|
1798
|
-
|
|
1794
|
+
|
|
1799
1795
|
const batchResults = await Promise.allSettled(
|
|
1800
1796
|
batch.map(async (filePath) => {
|
|
1801
1797
|
const handle = await fs.open(filePath, 'r');
|
|
1802
1798
|
fileHandles.set(filePath, handle);
|
|
1803
|
-
|
|
1799
|
+
|
|
1804
1800
|
const content = await handle.readFile({ encoding });
|
|
1805
|
-
|
|
1801
|
+
|
|
1806
1802
|
handle.close();
|
|
1807
1803
|
fileHandles.delete(filePath);
|
|
1808
|
-
|
|
1804
|
+
|
|
1809
1805
|
return { filePath, content };
|
|
1810
1806
|
})
|
|
1811
1807
|
);
|
|
1812
|
-
|
|
1808
|
+
|
|
1813
1809
|
results.push(...batchResults);
|
|
1814
1810
|
}
|
|
1815
|
-
|
|
1811
|
+
|
|
1816
1812
|
return results;
|
|
1817
1813
|
} finally {
|
|
1818
1814
|
// Ensure all handles are closed
|
|
@@ -1821,43 +1817,40 @@ async function batchReadFiles(filePaths, options = {}) {
|
|
|
1821
1817
|
}
|
|
1822
1818
|
}
|
|
1823
1819
|
}
|
|
1824
|
-
|
|
1820
|
+
````
|
|
1825
1821
|
|
|
1826
1822
|
#### Batch Write Operations
|
|
1823
|
+
|
|
1827
1824
|
```javascript
|
|
1828
1825
|
// Best Practice: Atomic writes with rollback capability
|
|
1829
1826
|
async function batchWriteFiles(fileWrites, options = {}) {
|
|
1830
1827
|
const { batchSize = 3, atomic = true } = options;
|
|
1831
1828
|
const tempFiles = [];
|
|
1832
|
-
|
|
1829
|
+
|
|
1833
1830
|
try {
|
|
1834
1831
|
// Write to temp files first
|
|
1835
1832
|
for (let i = 0; i < fileWrites.length; i += batchSize) {
|
|
1836
1833
|
const batch = fileWrites.slice(i, i + batchSize);
|
|
1837
|
-
|
|
1834
|
+
|
|
1838
1835
|
await Promise.all(
|
|
1839
1836
|
batch.map(async ({ path, content }) => {
|
|
1840
1837
|
const tempPath = `${path}.tmp.${Date.now()}`;
|
|
1841
1838
|
tempFiles.push({ temp: tempPath, final: path });
|
|
1842
|
-
|
|
1839
|
+
|
|
1843
1840
|
await fs.writeFile(tempPath, content, { flag: 'wx' });
|
|
1844
|
-
})
|
|
1841
|
+
}),
|
|
1845
1842
|
);
|
|
1846
1843
|
}
|
|
1847
|
-
|
|
1844
|
+
|
|
1848
1845
|
// Atomic rename all at once
|
|
1849
1846
|
if (atomic) {
|
|
1850
|
-
await Promise.all(
|
|
1851
|
-
tempFiles.map(({ temp, final }) => fs.rename(temp, final))
|
|
1852
|
-
);
|
|
1847
|
+
await Promise.all(tempFiles.map(({ temp, final }) => fs.rename(temp, final)));
|
|
1853
1848
|
}
|
|
1854
|
-
|
|
1849
|
+
|
|
1855
1850
|
return { success: true, count: fileWrites.length };
|
|
1856
1851
|
} catch (error) {
|
|
1857
1852
|
// Cleanup temp files on error
|
|
1858
|
-
await Promise.allSettled(
|
|
1859
|
-
tempFiles.map(({ temp }) => fs.unlink(temp))
|
|
1860
|
-
);
|
|
1853
|
+
await Promise.allSettled(tempFiles.map(({ temp }) => fs.unlink(temp)));
|
|
1861
1854
|
throw error;
|
|
1862
1855
|
}
|
|
1863
1856
|
}
|
|
@@ -1866,49 +1859,46 @@ async function batchWriteFiles(fileWrites, options = {}) {
|
|
|
1866
1859
|
### Search Operations (Grep, Glob)
|
|
1867
1860
|
|
|
1868
1861
|
#### Batch Grep Operations
|
|
1862
|
+
|
|
1869
1863
|
```javascript
|
|
1870
1864
|
// Best Practice: Parallel search with result streaming
|
|
1871
1865
|
async function batchGrep(pattern, directories, options = {}) {
|
|
1872
|
-
const {
|
|
1873
|
-
|
|
1874
|
-
filePattern = '*',
|
|
1875
|
-
maxResults = 1000
|
|
1876
|
-
} = options;
|
|
1877
|
-
|
|
1866
|
+
const { batchSize = 10, filePattern = '*', maxResults = 1000 } = options;
|
|
1867
|
+
|
|
1878
1868
|
const results = [];
|
|
1879
1869
|
let resultCount = 0;
|
|
1880
|
-
|
|
1870
|
+
|
|
1881
1871
|
for (let i = 0; i < directories.length; i += batchSize) {
|
|
1882
1872
|
const batch = directories.slice(i, i + batchSize);
|
|
1883
|
-
|
|
1873
|
+
|
|
1884
1874
|
const batchPromises = batch.map(async (dir) => {
|
|
1885
1875
|
const files = await glob(`${dir}/**/${filePattern}`);
|
|
1886
1876
|
const dirResults = [];
|
|
1887
|
-
|
|
1877
|
+
|
|
1888
1878
|
for (const file of files) {
|
|
1889
1879
|
if (resultCount >= maxResults) break;
|
|
1890
|
-
|
|
1880
|
+
|
|
1891
1881
|
const matches = await grepFile(file, pattern);
|
|
1892
1882
|
if (matches.length > 0) {
|
|
1893
1883
|
dirResults.push({ file, matches });
|
|
1894
1884
|
resultCount += matches.length;
|
|
1895
1885
|
}
|
|
1896
1886
|
}
|
|
1897
|
-
|
|
1887
|
+
|
|
1898
1888
|
return dirResults;
|
|
1899
1889
|
});
|
|
1900
|
-
|
|
1890
|
+
|
|
1901
1891
|
const batchResults = await Promise.allSettled(batchPromises);
|
|
1902
|
-
|
|
1892
|
+
|
|
1903
1893
|
batchResults.forEach((result) => {
|
|
1904
1894
|
if (result.status === 'fulfilled') {
|
|
1905
1895
|
results.push(...result.value);
|
|
1906
1896
|
}
|
|
1907
1897
|
});
|
|
1908
|
-
|
|
1898
|
+
|
|
1909
1899
|
if (resultCount >= maxResults) break;
|
|
1910
1900
|
}
|
|
1911
|
-
|
|
1901
|
+
|
|
1912
1902
|
return results;
|
|
1913
1903
|
}
|
|
1914
1904
|
```
|
|
@@ -1916,6 +1906,7 @@ async function batchGrep(pattern, directories, options = {}) {
|
|
|
1916
1906
|
### Task Management
|
|
1917
1907
|
|
|
1918
1908
|
#### Batch Task Execution
|
|
1909
|
+
|
|
1919
1910
|
```javascript
|
|
1920
1911
|
// Best Practice: Priority-based task queue with concurrency control
|
|
1921
1912
|
class BatchTaskManager {
|
|
@@ -1925,24 +1916,24 @@ class BatchTaskManager {
|
|
|
1925
1916
|
this.active = new Set();
|
|
1926
1917
|
this.completed = new Map();
|
|
1927
1918
|
}
|
|
1928
|
-
|
|
1919
|
+
|
|
1929
1920
|
addTask(task, priority = 0) {
|
|
1930
1921
|
this.queue.push({ task, priority, id: Date.now() });
|
|
1931
1922
|
this.queue.sort((a, b) => b.priority - a.priority);
|
|
1932
1923
|
this.processQueue();
|
|
1933
1924
|
}
|
|
1934
|
-
|
|
1925
|
+
|
|
1935
1926
|
async processQueue() {
|
|
1936
1927
|
while (this.queue.length > 0 && this.active.size < this.concurrency) {
|
|
1937
1928
|
const { task, id } = this.queue.shift();
|
|
1938
|
-
|
|
1929
|
+
|
|
1939
1930
|
this.active.add(id);
|
|
1940
|
-
|
|
1931
|
+
|
|
1941
1932
|
this.executeTask(task, id)
|
|
1942
|
-
.then(result => {
|
|
1933
|
+
.then((result) => {
|
|
1943
1934
|
this.completed.set(id, { status: 'success', result });
|
|
1944
1935
|
})
|
|
1945
|
-
.catch(error => {
|
|
1936
|
+
.catch((error) => {
|
|
1946
1937
|
this.completed.set(id, { status: 'error', error });
|
|
1947
1938
|
})
|
|
1948
1939
|
.finally(() => {
|
|
@@ -1951,28 +1942,28 @@ class BatchTaskManager {
|
|
|
1951
1942
|
});
|
|
1952
1943
|
}
|
|
1953
1944
|
}
|
|
1954
|
-
|
|
1945
|
+
|
|
1955
1946
|
async executeTask(task, id) {
|
|
1956
1947
|
const startTime = Date.now();
|
|
1957
|
-
|
|
1948
|
+
|
|
1958
1949
|
try {
|
|
1959
1950
|
const result = await task();
|
|
1960
1951
|
const duration = Date.now() - startTime;
|
|
1961
|
-
|
|
1952
|
+
|
|
1962
1953
|
console.log(`Task ${id} completed in ${duration}ms`);
|
|
1963
|
-
|
|
1954
|
+
|
|
1964
1955
|
return result;
|
|
1965
1956
|
} catch (error) {
|
|
1966
1957
|
console.error(`Task ${id} failed:`, error.message);
|
|
1967
1958
|
throw error;
|
|
1968
1959
|
}
|
|
1969
1960
|
}
|
|
1970
|
-
|
|
1961
|
+
|
|
1971
1962
|
async waitForAll() {
|
|
1972
1963
|
while (this.active.size > 0 || this.queue.length > 0) {
|
|
1973
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
1964
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1974
1965
|
}
|
|
1975
|
-
|
|
1966
|
+
|
|
1976
1967
|
return this.completed;
|
|
1977
1968
|
}
|
|
1978
1969
|
}
|
|
@@ -1981,6 +1972,7 @@ class BatchTaskManager {
|
|
|
1981
1972
|
### Memory Operations
|
|
1982
1973
|
|
|
1983
1974
|
#### Batch Memory Operations
|
|
1975
|
+
|
|
1984
1976
|
```javascript
|
|
1985
1977
|
// Best Practice: Memory-aware batch processing with garbage collection
|
|
1986
1978
|
class MemoryAwareBatchProcessor {
|
|
@@ -1988,27 +1980,27 @@ class MemoryAwareBatchProcessor {
|
|
|
1988
1980
|
this.memoryThreshold = options.memoryThreshold || 0.8; // 80% of available memory
|
|
1989
1981
|
this.gcThreshold = options.gcThreshold || 100 * 1024 * 1024; // 100MB
|
|
1990
1982
|
}
|
|
1991
|
-
|
|
1983
|
+
|
|
1992
1984
|
async processBatch(items, processor) {
|
|
1993
1985
|
const results = [];
|
|
1994
1986
|
let processedCount = 0;
|
|
1995
1987
|
let lastGC = Date.now();
|
|
1996
|
-
|
|
1988
|
+
|
|
1997
1989
|
for (const item of items) {
|
|
1998
1990
|
// Check memory before processing
|
|
1999
1991
|
const memUsage = process.memoryUsage();
|
|
2000
1992
|
const memPercent = memUsage.heapUsed / memUsage.heapTotal;
|
|
2001
|
-
|
|
1993
|
+
|
|
2002
1994
|
if (memPercent > this.memoryThreshold) {
|
|
2003
1995
|
console.warn('Memory threshold reached, triggering GC');
|
|
2004
1996
|
if (global.gc) {
|
|
2005
1997
|
global.gc();
|
|
2006
1998
|
}
|
|
2007
|
-
|
|
1999
|
+
|
|
2008
2000
|
// Wait for memory to be freed
|
|
2009
|
-
await new Promise(resolve => setTimeout(resolve, 100));
|
|
2001
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2010
2002
|
}
|
|
2011
|
-
|
|
2003
|
+
|
|
2012
2004
|
// Process item
|
|
2013
2005
|
try {
|
|
2014
2006
|
const result = await processor(item);
|
|
@@ -2016,23 +2008,24 @@ class MemoryAwareBatchProcessor {
|
|
|
2016
2008
|
} catch (error) {
|
|
2017
2009
|
results.push({ status: 'error', error });
|
|
2018
2010
|
}
|
|
2019
|
-
|
|
2011
|
+
|
|
2020
2012
|
processedCount++;
|
|
2021
|
-
|
|
2013
|
+
|
|
2022
2014
|
// Periodic garbage collection
|
|
2023
|
-
if (Date.now() - lastGC > 30000) {
|
|
2015
|
+
if (Date.now() - lastGC > 30000) {
|
|
2016
|
+
// Every 30 seconds
|
|
2024
2017
|
if (global.gc && memUsage.heapUsed > this.gcThreshold) {
|
|
2025
2018
|
global.gc();
|
|
2026
2019
|
lastGC = Date.now();
|
|
2027
2020
|
}
|
|
2028
2021
|
}
|
|
2029
|
-
|
|
2022
|
+
|
|
2030
2023
|
// Yield to event loop periodically
|
|
2031
2024
|
if (processedCount % 100 === 0) {
|
|
2032
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
2025
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
2033
2026
|
}
|
|
2034
2027
|
}
|
|
2035
|
-
|
|
2028
|
+
|
|
2036
2029
|
return results;
|
|
2037
2030
|
}
|
|
2038
2031
|
}
|
|
@@ -2041,6 +2034,7 @@ class MemoryAwareBatchProcessor {
|
|
|
2041
2034
|
## Practical Checklists
|
|
2042
2035
|
|
|
2043
2036
|
### Pre-Implementation Checklist
|
|
2037
|
+
|
|
2044
2038
|
- [ ] Determine if batch processing is appropriate
|
|
2045
2039
|
- [ ] Estimate resource requirements
|
|
2046
2040
|
- [ ] Design error handling strategy
|
|
@@ -2049,6 +2043,7 @@ class MemoryAwareBatchProcessor {
|
|
|
2049
2043
|
- [ ] Define success metrics
|
|
2050
2044
|
|
|
2051
2045
|
### Implementation Checklist
|
|
2046
|
+
|
|
2052
2047
|
- [ ] Use Promise.allSettled for partial failure handling
|
|
2053
2048
|
- [ ] Implement proper resource cleanup
|
|
2054
2049
|
- [ ] Add comprehensive logging
|
|
@@ -2057,6 +2052,7 @@ class MemoryAwareBatchProcessor {
|
|
|
2057
2052
|
- [ ] Document configuration options
|
|
2058
2053
|
|
|
2059
2054
|
### Deployment Checklist
|
|
2055
|
+
|
|
2060
2056
|
- [ ] Load test with realistic data
|
|
2061
2057
|
- [ ] Configure monitoring alerts
|
|
2062
2058
|
- [ ] Create runbook documentation
|
|
@@ -2065,6 +2061,7 @@ class MemoryAwareBatchProcessor {
|
|
|
2065
2061
|
- [ ] Train operations team
|
|
2066
2062
|
|
|
2067
2063
|
### Post-Deployment Checklist
|
|
2064
|
+
|
|
2068
2065
|
- [ ] Monitor performance metrics
|
|
2069
2066
|
- [ ] Review error rates
|
|
2070
2067
|
- [ ] Gather user feedback
|
|
@@ -2079,10 +2076,11 @@ class MemoryAwareBatchProcessor {
|
|
|
2079
2076
|
Batch operations are powerful tools for handling large-scale data processing, but they require careful design and implementation. By following these best practices, you can build robust, performant, and maintainable batch processing systems that scale with your needs.
|
|
2080
2077
|
|
|
2081
2078
|
Remember:
|
|
2079
|
+
|
|
2082
2080
|
- Start simple and iterate
|
|
2083
2081
|
- Measure everything
|
|
2084
2082
|
- Plan for failure
|
|
2085
2083
|
- Document thoroughly
|
|
2086
2084
|
- Share knowledge with your team
|
|
2087
2085
|
|
|
2088
|
-
For questions or contributions to this guide, please contact the platform team or submit a pull request to the documentation repository.
|
|
2086
|
+
For questions or contributions to this guide, please contact the platform team or submit a pull request to the documentation repository.
|