monomind 1.10.0 → 1.10.1
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/bin/monomind.js +50 -0
- package/package.json +11 -71
- package/.claude/agents/academic/academic-anthropologist.md +0 -126
- package/.claude/agents/academic/academic-geographer.md +0 -128
- package/.claude/agents/academic/academic-historian.md +0 -124
- package/.claude/agents/academic/academic-narratologist.md +0 -119
- package/.claude/agents/academic/academic-psychologist.md +0 -119
- package/.claude/agents/analysis/analyze-code-quality.md +0 -58
- package/.claude/agents/analysis/code-analyzer.md +0 -189
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +0 -58
- package/.claude/agents/architecture/system-design/arch-system-design.md +0 -54
- package/.claude/agents/consensus/crdt-synchronizer.md +0 -977
- package/.claude/agents/consensus/performance-benchmarker.md +0 -831
- package/.claude/agents/consensus/quorum-manager.md +0 -803
- package/.claude/agents/consensus/security-manager.md +0 -602
- package/.claude/agents/core/coder.md +0 -262
- package/.claude/agents/core/planner.md +0 -170
- package/.claude/agents/core/researcher.md +0 -192
- package/.claude/agents/core/reviewer.md +0 -327
- package/.claude/agents/core/tester.md +0 -318
- package/.claude/agents/data/ml/data-ml-model.md +0 -76
- package/.claude/agents/design/design-monodesign.md +0 -121
- package/.claude/agents/development/dev-backend-api.md +0 -178
- package/.claude/agents/devops/ci-cd/ops-cicd-github.md +0 -52
- package/.claude/agents/documentation/api-docs/docs-api-openapi.md +0 -63
- package/.claude/agents/engineering/engineering-ai-data-remediation-engineer.md +0 -212
- package/.claude/agents/engineering/engineering-ai-engineer.md +0 -165
- package/.claude/agents/engineering/engineering-autonomous-optimization-architect.md +0 -108
- package/.claude/agents/engineering/engineering-backend-architect.md +0 -254
- package/.claude/agents/engineering/engineering-code-reviewer.md +0 -95
- package/.claude/agents/engineering/engineering-data-engineer.md +0 -307
- package/.claude/agents/engineering/engineering-database-optimizer.md +0 -200
- package/.claude/agents/engineering/engineering-devops-automator.md +0 -430
- package/.claude/agents/engineering/engineering-embedded-firmware-engineer.md +0 -174
- package/.claude/agents/engineering/engineering-feishu-integration-developer.md +0 -607
- package/.claude/agents/engineering/engineering-frontend-developer.md +0 -249
- package/.claude/agents/engineering/engineering-git-workflow-master.md +0 -108
- package/.claude/agents/engineering/engineering-incident-response-commander.md +0 -482
- package/.claude/agents/engineering/engineering-mobile-app-builder.md +0 -499
- package/.claude/agents/engineering/engineering-rapid-prototyper.md +0 -463
- package/.claude/agents/engineering/engineering-security-engineer.md +0 -303
- package/.claude/agents/engineering/engineering-senior-developer.md +0 -195
- package/.claude/agents/engineering/engineering-software-architect.md +0 -100
- package/.claude/agents/engineering/engineering-solidity-smart-contract-engineer.md +0 -528
- package/.claude/agents/engineering/engineering-sre.md +0 -114
- package/.claude/agents/engineering/engineering-technical-writer.md +0 -412
- package/.claude/agents/engineering/engineering-threat-detection-engineer.md +0 -540
- package/.claude/agents/engineering/engineering-wechat-mini-program-developer.md +0 -351
- package/.claude/agents/game-development/blender/blender-addon-engineer.md +0 -235
- package/.claude/agents/game-development/game-audio-engineer.md +0 -265
- package/.claude/agents/game-development/game-designer.md +0 -168
- package/.claude/agents/game-development/godot/godot-gameplay-scripter.md +0 -335
- package/.claude/agents/game-development/godot/godot-multiplayer-engineer.md +0 -298
- package/.claude/agents/game-development/godot/godot-shader-developer.md +0 -267
- package/.claude/agents/game-development/level-designer.md +0 -209
- package/.claude/agents/game-development/narrative-designer.md +0 -244
- package/.claude/agents/game-development/roblox-studio/roblox-avatar-creator.md +0 -298
- package/.claude/agents/game-development/roblox-studio/roblox-experience-designer.md +0 -306
- package/.claude/agents/game-development/roblox-studio/roblox-systems-scripter.md +0 -326
- package/.claude/agents/game-development/technical-artist.md +0 -230
- package/.claude/agents/game-development/unity/unity-architect.md +0 -272
- package/.claude/agents/game-development/unity/unity-editor-tool-developer.md +0 -311
- package/.claude/agents/game-development/unity/unity-multiplayer-engineer.md +0 -322
- package/.claude/agents/game-development/unity/unity-shader-graph-artist.md +0 -270
- package/.claude/agents/game-development/unreal-engine/unreal-multiplayer-architect.md +0 -314
- package/.claude/agents/game-development/unreal-engine/unreal-systems-engineer.md +0 -311
- package/.claude/agents/game-development/unreal-engine/unreal-technical-artist.md +0 -257
- package/.claude/agents/game-development/unreal-engine/unreal-world-builder.md +0 -274
- package/.claude/agents/github/code-review-swarm.md +0 -557
- package/.claude/agents/github/github-modes.md +0 -154
- package/.claude/agents/github/issue-tracker.md +0 -299
- package/.claude/agents/github/multi-repo-swarm.md +0 -525
- package/.claude/agents/github/pr-manager.md +0 -163
- package/.claude/agents/github/project-board-sync.md +0 -478
- package/.claude/agents/github/release-manager.md +0 -296
- package/.claude/agents/github/release-swarm.md +0 -597
- package/.claude/agents/github/repo-architect.md +0 -359
- package/.claude/agents/github/swarm-issue.md +0 -548
- package/.claude/agents/github/swarm-pr.md +0 -427
- package/.claude/agents/github/sync-coordinator.md +0 -355
- package/.claude/agents/github/workflow-automation.md +0 -640
- package/.claude/agents/goal/agent.md +0 -804
- package/.claude/agents/goal/code-goal-planner.md +0 -445
- package/.claude/agents/goal/goal-planner.md +0 -168
- package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +0 -129
- package/.claude/agents/hive-mind/queen-coordinator.md +0 -202
- package/.claude/agents/hive-mind/scout-explorer.md +0 -241
- package/.claude/agents/hive-mind/swarm-memory-manager.md +0 -192
- package/.claude/agents/hive-mind/worker-specialist.md +0 -216
- package/.claude/agents/marketing/marketing-ai-citation-strategist.md +0 -171
- package/.claude/agents/marketing/marketing-app-store-optimizer.md +0 -322
- package/.claude/agents/marketing/marketing-baidu-seo-specialist.md +0 -227
- package/.claude/agents/marketing/marketing-bilibili-content-strategist.md +0 -200
- package/.claude/agents/marketing/marketing-book-co-author.md +0 -111
- package/.claude/agents/marketing/marketing-carousel-growth-engine.md +0 -200
- package/.claude/agents/marketing/marketing-china-ecommerce-operator.md +0 -284
- package/.claude/agents/marketing/marketing-competitive-content.md +0 -155
- package/.claude/agents/marketing/marketing-content-creator.md +0 -67
- package/.claude/agents/marketing/marketing-cro-specialist.md +0 -147
- package/.claude/agents/marketing/marketing-cross-border-ecommerce.md +0 -260
- package/.claude/agents/marketing/marketing-douyin-strategist.md +0 -150
- package/.claude/agents/marketing/marketing-email-specialist.md +0 -90
- package/.claude/agents/marketing/marketing-growth-hacker.md +0 -54
- package/.claude/agents/marketing/marketing-instagram-curator.md +0 -114
- package/.claude/agents/marketing/marketing-kuaishou-strategist.md +0 -224
- package/.claude/agents/marketing/marketing-launch-strategist.md +0 -129
- package/.claude/agents/marketing/marketing-linkedin-content-creator.md +0 -215
- package/.claude/agents/marketing/marketing-livestream-commerce-coach.md +0 -306
- package/.claude/agents/marketing/marketing-podcast-strategist.md +0 -278
- package/.claude/agents/marketing/marketing-pricing-strategist.md +0 -127
- package/.claude/agents/marketing/marketing-private-domain-operator.md +0 -309
- package/.claude/agents/marketing/marketing-reddit-community-builder.md +0 -124
- package/.claude/agents/marketing/marketing-seo-specialist.md +0 -279
- package/.claude/agents/marketing/marketing-short-video-editing-coach.md +0 -413
- package/.claude/agents/marketing/marketing-social-media-strategist.md +0 -125
- package/.claude/agents/marketing/marketing-tiktok-strategist.md +0 -126
- package/.claude/agents/marketing/marketing-twitter-engager.md +0 -127
- package/.claude/agents/marketing/marketing-wechat-official-account.md +0 -146
- package/.claude/agents/marketing/marketing-weibo-strategist.md +0 -241
- package/.claude/agents/marketing/marketing-xiaohongshu-specialist.md +0 -139
- package/.claude/agents/marketing/marketing-zhihu-strategist.md +0 -163
- package/.claude/agents/neural/safla-neural.md +0 -74
- package/.claude/agents/optimization/benchmark-suite.md +0 -663
- package/.claude/agents/optimization/load-balancer.md +0 -429
- package/.claude/agents/optimization/performance-monitor.md +0 -670
- package/.claude/agents/optimization/resource-allocator.md +0 -672
- package/.claude/agents/optimization/topology-optimizer.md +0 -806
- package/.claude/agents/paid-media/paid-media-auditor.md +0 -71
- package/.claude/agents/paid-media/paid-media-creative-strategist.md +0 -71
- package/.claude/agents/paid-media/paid-media-paid-social-strategist.md +0 -71
- package/.claude/agents/paid-media/paid-media-ppc-strategist.md +0 -71
- package/.claude/agents/paid-media/paid-media-programmatic-buyer.md +0 -71
- package/.claude/agents/paid-media/paid-media-search-query-analyst.md +0 -71
- package/.claude/agents/paid-media/paid-media-tracking-specialist.md +0 -71
- package/.claude/agents/payments/agentic-payments.md +0 -126
- package/.claude/agents/product/product-behavioral-nudge-engine.md +0 -81
- package/.claude/agents/product/product-feedback-synthesizer.md +0 -119
- package/.claude/agents/product/product-manager.md +0 -469
- package/.claude/agents/product/product-sprint-prioritizer.md +0 -154
- package/.claude/agents/product/product-trend-researcher.md +0 -159
- package/.claude/agents/project-management/project-management-experiment-tracker.md +0 -199
- package/.claude/agents/project-management/project-management-jira-workflow-steward.md +0 -231
- package/.claude/agents/project-management/project-management-project-shepherd.md +0 -195
- package/.claude/agents/project-management/project-management-studio-operations.md +0 -201
- package/.claude/agents/project-management/project-management-studio-producer.md +0 -204
- package/.claude/agents/project-management/project-manager-senior.md +0 -136
- package/.claude/agents/reasoning/agent.md +0 -804
- package/.claude/agents/reasoning/goal-planner.md +0 -73
- package/.claude/agents/sales/sales-account-strategist.md +0 -228
- package/.claude/agents/sales/sales-coach.md +0 -272
- package/.claude/agents/sales/sales-deal-strategist.md +0 -181
- package/.claude/agents/sales/sales-discovery-coach.md +0 -226
- package/.claude/agents/sales/sales-engineer.md +0 -183
- package/.claude/agents/sales/sales-outbound-strategist.md +0 -202
- package/.claude/agents/sales/sales-pipeline-analyst.md +0 -268
- package/.claude/agents/sales/sales-proposal-strategist.md +0 -218
- package/.claude/agents/schemas/architecture-output.json +0 -43
- package/.claude/agents/schemas/code-review-output.json +0 -28
- package/.claude/agents/schemas/generic-task-input.json +0 -12
- package/.claude/agents/schemas/implementation-output.json +0 -18
- package/.claude/agents/schemas/research-output.json +0 -31
- package/.claude/agents/schemas/security-audit-output.json +0 -29
- package/.claude/agents/schemas/test-report-output.json +0 -29
- package/.claude/agents/sona/sona-learning-optimizer.md +0 -65
- package/.claude/agents/sparc/architecture.md +0 -453
- package/.claude/agents/sparc/pseudocode.md +0 -299
- package/.claude/agents/sparc/refinement.md +0 -504
- package/.claude/agents/sparc/specification.md +0 -258
- package/.claude/agents/spatial-computing/macos-spatial-metal-engineer.md +0 -338
- package/.claude/agents/spatial-computing/terminal-integration-specialist.md +0 -71
- package/.claude/agents/spatial-computing/visionos-spatial-engineer.md +0 -55
- package/.claude/agents/specialists/integration-architect.md +0 -94
- package/.claude/agents/specialists/memory-specialist.md +0 -298
- package/.claude/agents/specialists/performance-engineer.md +0 -387
- package/.claude/agents/specialists/queen-coordinator.md +0 -67
- package/.claude/agents/specialists/security-architect.md +0 -154
- package/.claude/agents/specialized/accounts-payable-agent.md +0 -186
- package/.claude/agents/specialized/agentic-identity-trust.md +0 -388
- package/.claude/agents/specialized/agents-orchestrator.md +0 -368
- package/.claude/agents/specialized/automation-governance-architect.md +0 -217
- package/.claude/agents/specialized/blockchain-security-auditor.md +0 -497
- package/.claude/agents/specialized/compliance-auditor.md +0 -159
- package/.claude/agents/specialized/corporate-training-designer.md +0 -193
- package/.claude/agents/specialized/data-consolidation-agent.md +0 -61
- package/.claude/agents/specialized/government-digital-presales-consultant.md +0 -364
- package/.claude/agents/specialized/healthcare-marketing-compliance.md +0 -396
- package/.claude/agents/specialized/identity-graph-operator.md +0 -261
- package/.claude/agents/specialized/lsp-index-engineer.md +0 -315
- package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +0 -89
- package/.claude/agents/specialized/recruitment-specialist.md +0 -510
- package/.claude/agents/specialized/report-distribution-agent.md +0 -66
- package/.claude/agents/specialized/sales-data-extraction-agent.md +0 -68
- package/.claude/agents/specialized/specialized-cultural-intelligence-strategist.md +0 -89
- package/.claude/agents/specialized/specialized-developer-advocate.md +0 -318
- package/.claude/agents/specialized/specialized-document-generator.md +0 -56
- package/.claude/agents/specialized/specialized-french-consulting-market.md +0 -193
- package/.claude/agents/specialized/specialized-korean-business-navigator.md +0 -217
- package/.claude/agents/specialized/specialized-mcp-builder.md +0 -64
- package/.claude/agents/specialized/specialized-model-qa.md +0 -489
- package/.claude/agents/specialized/specialized-salesforce-architect.md +0 -181
- package/.claude/agents/specialized/specialized-workflow-architect.md +0 -598
- package/.claude/agents/specialized/study-abroad-advisor.md +0 -283
- package/.claude/agents/specialized/supply-chain-strategist.md +0 -583
- package/.claude/agents/specialized/zk-steward.md +0 -212
- package/.claude/agents/sublinear/consensus-coordinator.md +0 -333
- package/.claude/agents/sublinear/matrix-optimizer.md +0 -180
- package/.claude/agents/sublinear/pagerank-analyzer.md +0 -295
- package/.claude/agents/sublinear/performance-optimizer.md +0 -363
- package/.claude/agents/sublinear/trading-predictor.md +0 -242
- package/.claude/agents/support/support-analytics-reporter.md +0 -366
- package/.claude/agents/support/support-executive-summary-generator.md +0 -213
- package/.claude/agents/support/support-finance-tracker.md +0 -443
- package/.claude/agents/support/support-infrastructure-maintainer.md +0 -619
- package/.claude/agents/support/support-legal-compliance-checker.md +0 -589
- package/.claude/agents/support/support-support-responder.md +0 -586
- package/.claude/agents/swarm/adaptive-coordinator.md +0 -364
- package/.claude/agents/swarm/hierarchical-coordinator.md +0 -318
- package/.claude/agents/swarm/mesh-coordinator.md +0 -363
- package/.claude/agents/templates/automation-smart-agent.md +0 -185
- package/.claude/agents/templates/coordinator-swarm-init.md +0 -83
- package/.claude/agents/templates/github-pr-manager.md +0 -155
- package/.claude/agents/templates/implementer-sparc-coder.md +0 -231
- package/.claude/agents/templates/memory-coordinator.md +0 -163
- package/.claude/agents/templates/migration-plan.md +0 -724
- package/.claude/agents/templates/orchestrator-task.md +0 -120
- package/.claude/agents/templates/performance-analyzer.md +0 -179
- package/.claude/agents/templates/sparc-coordinator.md +0 -163
- package/.claude/agents/testing/production-validator.md +0 -374
- package/.claude/agents/testing/tdd-london-swarm.md +0 -241
- package/.claude/agents/testing/testing-accessibility-auditor.md +0 -322
- package/.claude/agents/testing/testing-api-tester.md +0 -307
- package/.claude/agents/testing/testing-evidence-collector.md +0 -211
- package/.claude/agents/testing/testing-performance-benchmarker.md +0 -269
- package/.claude/agents/testing/testing-reality-checker.md +0 -237
- package/.claude/agents/testing/testing-test-results-analyzer.md +0 -306
- package/.claude/agents/testing/testing-tool-evaluator.md +0 -395
- package/.claude/agents/testing/testing-workflow-optimizer.md +0 -451
- package/.claude/checkpoints/1767754460.json +0 -8
- package/.claude/commands/agents/README.md +0 -14
- package/.claude/commands/agents/agent-capabilities.md +0 -25
- package/.claude/commands/agents/agent-coordination.md +0 -32
- package/.claude/commands/agents/agent-spawning.md +0 -32
- package/.claude/commands/agents/agent-types.md +0 -30
- package/.claude/commands/analysis/README.md +0 -18
- package/.claude/commands/analysis/bottleneck-detect.md +0 -69
- package/.claude/commands/analysis/performance-bottlenecks.md +0 -59
- package/.claude/commands/analysis/performance-report.md +0 -52
- package/.claude/commands/analysis/token-efficiency.md +0 -42
- package/.claude/commands/analysis/token-usage.md +0 -47
- package/.claude/commands/automation/README.md +0 -19
- package/.claude/commands/automation/auto-agent.md +0 -86
- package/.claude/commands/automation/self-healing.md +0 -108
- package/.claude/commands/automation/session-memory.md +0 -89
- package/.claude/commands/automation/smart-agents.md +0 -81
- package/.claude/commands/automation/smart-spawn.md +0 -66
- package/.claude/commands/automation/workflow-select.md +0 -60
- package/.claude/commands/browse.md +0 -32
- package/.claude/commands/coordination/README.md +0 -13
- package/.claude/commands/coordination/agent-spawn.md +0 -69
- package/.claude/commands/coordination/swarm-init.md +0 -82
- package/.claude/commands/coordination/task-orchestrate.md +0 -79
- package/.claude/commands/github/README.md +0 -24
- package/.claude/commands/github/github-modes.md +0 -151
- package/.claude/commands/github/issue-tracker.md +0 -293
- package/.claude/commands/github/pr-manager.md +0 -173
- package/.claude/commands/github/release-manager.md +0 -343
- package/.claude/commands/github/repo-architect.md +0 -379
- package/.claude/commands/github/sync-coordinator.md +0 -297
- package/.claude/commands/hive-mind/README.md +0 -42
- package/.claude/commands/hive-mind/hive-mind-consensus.md +0 -72
- package/.claude/commands/hive-mind/hive-mind-init.md +0 -68
- package/.claude/commands/hive-mind/hive-mind-memory.md +0 -73
- package/.claude/commands/hive-mind/hive-mind-spawn.md +0 -82
- package/.claude/commands/hive-mind/hive-mind-status.md +0 -56
- package/.claude/commands/hive-mind/hive-mind-stop.md +0 -55
- package/.claude/commands/hive-mind/hive-mind.md +0 -87
- package/.claude/commands/hooks/README.md +0 -66
- package/.claude/commands/hooks/overview.md +0 -117
- package/.claude/commands/hooks/post-edit.md +0 -78
- package/.claude/commands/hooks/post-task.md +0 -62
- package/.claude/commands/hooks/pre-edit.md +0 -81
- package/.claude/commands/hooks/pre-task.md +0 -76
- package/.claude/commands/hooks/session-end.md +0 -82
- package/.claude/commands/hooks/setup.md +0 -132
- package/.claude/commands/mastermind/_repeat.md +0 -451
- package/.claude/commands/mastermind/architect.md +0 -55
- package/.claude/commands/mastermind/brain.md +0 -102
- package/.claude/commands/mastermind/build.md +0 -26
- package/.claude/commands/mastermind/content.md +0 -26
- package/.claude/commands/mastermind/createorg.md +0 -97
- package/.claude/commands/mastermind/finance.md +0 -26
- package/.claude/commands/mastermind/idea.md +0 -26
- package/.claude/commands/mastermind/marketing.md +0 -26
- package/.claude/commands/mastermind/master.md +0 -772
- package/.claude/commands/mastermind/ops.md +0 -26
- package/.claude/commands/mastermind/release.md +0 -26
- package/.claude/commands/mastermind/research.md +0 -26
- package/.claude/commands/mastermind/review.md +0 -26
- package/.claude/commands/mastermind/runorg.md +0 -109
- package/.claude/commands/mastermind/sales.md +0 -26
- package/.claude/commands/mastermind/techport.md +0 -26
- package/.claude/commands/mastermind.md +0 -121
- package/.claude/commands/memory/README.md +0 -79
- package/.claude/commands/memory/memory-search.md +0 -77
- package/.claude/commands/monitoring/README.md +0 -69
- package/.claude/commands/monitoring/agent-metrics.md +0 -65
- package/.claude/commands/monitoring/agents.md +0 -71
- package/.claude/commands/monitoring/status.md +0 -108
- package/.claude/commands/monograph/README.md +0 -102
- package/.claude/commands/monograph/monograph-build.md +0 -79
- package/.claude/commands/monograph/monograph-search.md +0 -96
- package/.claude/commands/monograph/monograph-stats.md +0 -53
- package/.claude/commands/monograph/monograph-watch.md +0 -63
- package/.claude/commands/monograph/monograph-wiki.md +0 -91
- package/.claude/commands/monomind/createtask.md +0 -277
- package/.claude/commands/monomind/do.md +0 -446
- package/.claude/commands/monomind/help.md +0 -118
- package/.claude/commands/monomind/idea.md +0 -273
- package/.claude/commands/monomind/improve.md +0 -350
- package/.claude/commands/monomind/memory.md +0 -230
- package/.claude/commands/monomind/repeat.md +0 -257
- package/.claude/commands/monomind/review.md +0 -317
- package/.claude/commands/monomind/specialagents.md +0 -125
- package/.claude/commands/monomind/swarm.md +0 -161
- package/.claude/commands/monomind/understand.md +0 -150
- package/.claude/commands/optimization/README.md +0 -73
- package/.claude/commands/optimization/auto-topology.md +0 -85
- package/.claude/commands/optimization/parallel-execution.md +0 -76
- package/.claude/commands/optimization/performance-optimize.md +0 -79
- package/.claude/commands/pair/README.md +0 -79
- package/.claude/commands/pair/examples.md +0 -156
- package/.claude/commands/pair/modes.md +0 -122
- package/.claude/commands/pair/session.md +0 -124
- package/.claude/commands/sparc/analyzer.md +0 -35
- package/.claude/commands/sparc/architect.md +0 -36
- package/.claude/commands/sparc/ask.md +0 -56
- package/.claude/commands/sparc/batch-executor.md +0 -37
- package/.claude/commands/sparc/code.md +0 -48
- package/.claude/commands/sparc/coder.md +0 -37
- package/.claude/commands/sparc/debug.md +0 -42
- package/.claude/commands/sparc/debugger.md +0 -37
- package/.claude/commands/sparc/designer.md +0 -36
- package/.claude/commands/sparc/devops.md +0 -68
- package/.claude/commands/sparc/docs-writer.md +0 -39
- package/.claude/commands/sparc/documenter.md +0 -37
- package/.claude/commands/sparc/innovator.md +0 -37
- package/.claude/commands/sparc/integration.md +0 -42
- package/.claude/commands/sparc/mcp.md +0 -76
- package/.claude/commands/sparc/memory-manager.md +0 -57
- package/.claude/commands/sparc/optimizer.md +0 -37
- package/.claude/commands/sparc/orchestrator.md +0 -70
- package/.claude/commands/sparc/post-deployment-monitoring-mode.md +0 -42
- package/.claude/commands/sparc/refinement-optimization-mode.md +0 -42
- package/.claude/commands/sparc/researcher.md +0 -37
- package/.claude/commands/sparc/reviewer.md +0 -37
- package/.claude/commands/sparc/security-review.md +0 -39
- package/.claude/commands/sparc/sparc-modes.md +0 -120
- package/.claude/commands/sparc/sparc.md +0 -71
- package/.claude/commands/sparc/spec-pseudocode.md +0 -39
- package/.claude/commands/sparc/supabase-admin.md +0 -301
- package/.claude/commands/sparc/swarm-coordinator.md +0 -50
- package/.claude/commands/sparc/tdd.md +0 -37
- package/.claude/commands/sparc/tester.md +0 -37
- package/.claude/commands/sparc/tutorial.md +0 -38
- package/.claude/commands/sparc/workflow-manager.md +0 -37
- package/.claude/commands/sparc.md +0 -112
- package/.claude/commands/stream-chain/pipeline.md +0 -116
- package/.claude/commands/stream-chain/run.md +0 -156
- package/.claude/commands/swarm/README.md +0 -40
- package/.claude/commands/swarm/analysis.md +0 -73
- package/.claude/commands/swarm/development.md +0 -72
- package/.claude/commands/swarm/examples.md +0 -103
- package/.claude/commands/swarm/maintenance.md +0 -75
- package/.claude/commands/swarm/optimization.md +0 -84
- package/.claude/commands/swarm/research.md +0 -76
- package/.claude/commands/swarm/swarm-analysis.md +0 -62
- package/.claude/commands/swarm/swarm-background.md +0 -65
- package/.claude/commands/swarm/swarm-modes.md +0 -67
- package/.claude/commands/swarm/swarm-monitor.md +0 -54
- package/.claude/commands/swarm/swarm-status.md +0 -44
- package/.claude/commands/swarm/swarm-strategies.md +0 -76
- package/.claude/commands/swarm/swarm.md +0 -79
- package/.claude/commands/swarm/testing.md +0 -80
- package/.claude/commands/tokens.md +0 -18
- package/.claude/commands/training/README.md +0 -39
- package/.claude/commands/training/model-update.md +0 -78
- package/.claude/commands/training/neural-patterns.md +0 -73
- package/.claude/commands/training/neural-train.md +0 -79
- package/.claude/commands/training/pattern-learn.md +0 -69
- package/.claude/commands/training/specialization.md +0 -92
- package/.claude/commands/truth/start.md +0 -121
- package/.claude/commands/ts.md +0 -14
- package/.claude/commands/verify/check.md +0 -106
- package/.claude/commands/verify/start.md +0 -105
- package/.claude/commands/workflows/README.md +0 -65
- package/.claude/commands/workflows/development.md +0 -86
- package/.claude/commands/workflows/research.md +0 -89
- package/.claude/commands/workflows/workflow-create.md +0 -84
- package/.claude/commands/workflows/workflow-execute.md +0 -103
- package/.claude/commands/workflows/workflow-export.md +0 -90
- package/.claude/config/v1-dependency-optimization.json +0 -266
- package/.claude/config/v1-performance-targets.json +0 -251
- package/.claude/helpers/README.md +0 -105
- package/.claude/helpers/auto-memory-hook.mjs +0 -369
- package/.claude/helpers/context-persistence-hook.mjs +0 -1988
- package/.claude/helpers/control-start.cjs +0 -91
- package/.claude/helpers/extras-registry.json +0 -5141
- package/.claude/helpers/graphify-freshen.cjs +0 -98
- package/.claude/helpers/hook-handler.cjs +0 -1718
- package/.claude/helpers/intelligence.cjs +0 -227
- package/.claude/helpers/learning-service.mjs +0 -1144
- package/.claude/helpers/loop-tracker.cjs +0 -107
- package/.claude/helpers/memory-palace.cjs +0 -401
- package/.claude/helpers/memory.cjs +0 -84
- package/.claude/helpers/metrics-db.mjs +0 -488
- package/.claude/helpers/router.cjs +0 -450
- package/.claude/helpers/session.cjs +0 -125
- package/.claude/helpers/skill-registry.json +0 -946
- package/.claude/helpers/statusline.cjs +0 -1331
- package/.claude/helpers/swarm-hooks.sh +0 -761
- package/.claude/helpers/toggle-statusline.cjs +0 -58
- package/.claude/helpers/token-tracker.cjs +0 -934
- package/.claude/mcp.json +0 -3
- package/.claude/scheduled_tasks.lock +0 -1
- package/.claude/settings.json +0 -318
- package/.claude/settings.local.json +0 -52
- package/.claude/skills/.monomind/data/ranked-context.json +0 -5
- package/.claude/skills/.monomind/sessions/current.json +0 -13
- package/.claude/skills/.monomind/sessions/session-1777829336455.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777831614725.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777832095857.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777839814183.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777841847131.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777843309463.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777880867159.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777881884593.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777884090471.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777884808221.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777885672155.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777886852818.json +0 -15
- package/.claude/skills/.monomind/sessions/session-1777896532690.json +0 -15
- package/.claude/skills/agent-browser-testing/SKILL.md +0 -312
- package/.claude/skills/agentdb-advanced/SKILL.md +0 -549
- package/.claude/skills/agentdb-learning/SKILL.md +0 -544
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +0 -337
- package/.claude/skills/agentdb-optimization/SKILL.md +0 -508
- package/.claude/skills/agentdb-vector-search/SKILL.md +0 -335
- package/.claude/skills/agentic-integration/SKILL.md +0 -265
- package/.claude/skills/agentic-jujutsu/SKILL.md +0 -645
- package/.claude/skills/cli-modernization/SKILL.md +0 -950
- package/.claude/skills/core-implementation/SKILL.md +0 -892
- package/.claude/skills/ddd-architecture/SKILL.md +0 -444
- package/.claude/skills/github-code-review/SKILL.md +0 -1147
- package/.claude/skills/github-multi-repo/SKILL.md +0 -912
- package/.claude/skills/github-project-management/SKILL.md +0 -1245
- package/.claude/skills/github-release-management/SKILL.md +0 -1118
- package/.claude/skills/github-workflow-automation/SKILL.md +0 -1107
- package/.claude/skills/hive-mind-advanced/SKILL.md +0 -709
- package/.claude/skills/hooks-automation/SKILL.md +0 -1196
- package/.claude/skills/mastermind/_agent-select.md +0 -132
- package/.claude/skills/mastermind/_intake.md +0 -83
- package/.claude/skills/mastermind/_protocol.md +0 -380
- package/.claude/skills/mastermind/access.md +0 -236
- package/.claude/skills/mastermind/activity.md +0 -191
- package/.claude/skills/mastermind/adapter-manager.md +0 -259
- package/.claude/skills/mastermind/adapters.md +0 -204
- package/.claude/skills/mastermind/agent-detail.md +0 -242
- package/.claude/skills/mastermind/agents.md +0 -178
- package/.claude/skills/mastermind/approval-detail.md +0 -259
- package/.claude/skills/mastermind/approve.md +0 -181
- package/.claude/skills/mastermind/architect.md +0 -863
- package/.claude/skills/mastermind/backup.md +0 -197
- package/.claude/skills/mastermind/bootstrap.md +0 -190
- package/.claude/skills/mastermind/budgets.md +0 -237
- package/.claude/skills/mastermind/build.md +0 -170
- package/.claude/skills/mastermind/companies.md +0 -256
- package/.claude/skills/mastermind/content.md +0 -197
- package/.claude/skills/mastermind/costs.md +0 -151
- package/.claude/skills/mastermind/createorg.md +0 -344
- package/.claude/skills/mastermind/diagnose.md +0 -249
- package/.claude/skills/mastermind/env.md +0 -198
- package/.claude/skills/mastermind/environments.md +0 -250
- package/.claude/skills/mastermind/export.md +0 -324
- package/.claude/skills/mastermind/finance.md +0 -166
- package/.claude/skills/mastermind/goal-detail.md +0 -255
- package/.claude/skills/mastermind/goals.md +0 -149
- package/.claude/skills/mastermind/heartbeat.md +0 -164
- package/.claude/skills/mastermind/idea.md +0 -1120
- package/.claude/skills/mastermind/import.md +0 -281
- package/.claude/skills/mastermind/inbox.md +0 -214
- package/.claude/skills/mastermind/instance-settings.md +0 -315
- package/.claude/skills/mastermind/instance.md +0 -231
- package/.claude/skills/mastermind/invite-landing.md +0 -227
- package/.claude/skills/mastermind/invites.md +0 -254
- package/.claude/skills/mastermind/issue-detail.md +0 -291
- package/.claude/skills/mastermind/issues.md +0 -235
- package/.claude/skills/mastermind/join-queue.md +0 -170
- package/.claude/skills/mastermind/liveness.md +0 -392
- package/.claude/skills/mastermind/marketing.md +0 -228
- package/.claude/skills/mastermind/memory.md +0 -321
- package/.claude/skills/mastermind/monotask.md +0 -350
- package/.claude/skills/mastermind/my-issues.md +0 -146
- package/.claude/skills/mastermind/new-agent.md +0 -241
- package/.claude/skills/mastermind/ops.md +0 -168
- package/.claude/skills/mastermind/org-chart.md +0 -207
- package/.claude/skills/mastermind/org-settings.md +0 -217
- package/.claude/skills/mastermind/plan-to-tasks.md +0 -136
- package/.claude/skills/mastermind/plugin-manager.md +0 -241
- package/.claude/skills/mastermind/plugin-settings.md +0 -273
- package/.claude/skills/mastermind/plugins.md +0 -190
- package/.claude/skills/mastermind/profile.md +0 -187
- package/.claude/skills/mastermind/project-detail.md +0 -249
- package/.claude/skills/mastermind/project-workspace.md +0 -244
- package/.claude/skills/mastermind/projects.md +0 -164
- package/.claude/skills/mastermind/references/copywriting-frameworks.md +0 -181
- package/.claude/skills/mastermind/references/persuasion-psychology.md +0 -158
- package/.claude/skills/mastermind/release.md +0 -168
- package/.claude/skills/mastermind/research.md +0 -168
- package/.claude/skills/mastermind/review.md +0 -169
- package/.claude/skills/mastermind/routine-detail.md +0 -253
- package/.claude/skills/mastermind/routines.md +0 -202
- package/.claude/skills/mastermind/runorg.md +0 -373
- package/.claude/skills/mastermind/sales.md +0 -170
- package/.claude/skills/mastermind/search.md +0 -186
- package/.claude/skills/mastermind/secrets.md +0 -199
- package/.claude/skills/mastermind/skills.md +0 -156
- package/.claude/skills/mastermind/tasks.md +0 -149
- package/.claude/skills/mastermind/techport.md +0 -743
- package/.claude/skills/mastermind/threads.md +0 -259
- package/.claude/skills/mastermind/tree-control.md +0 -250
- package/.claude/skills/mastermind/wiki.md +0 -314
- package/.claude/skills/mastermind/workspace-detail.md +0 -317
- package/.claude/skills/mastermind/workspaces.md +0 -261
- package/.claude/skills/mastermind/worktree.md +0 -187
- package/.claude/skills/mcp-optimization/SKILL.md +0 -837
- package/.claude/skills/memory-unification/SKILL.md +0 -196
- package/.claude/skills/monodesign/SKILL.md +0 -302
- package/.claude/skills/monodesign/reference/adapt.md +0 -190
- package/.claude/skills/monodesign/reference/animate.md +0 -175
- package/.claude/skills/monodesign/reference/antipatterns-catalog.md +0 -187
- package/.claude/skills/monodesign/reference/audit.md +0 -133
- package/.claude/skills/monodesign/reference/bolder.md +0 -113
- package/.claude/skills/monodesign/reference/brand-workflow.md +0 -180
- package/.claude/skills/monodesign/reference/brand.md +0 -114
- package/.claude/skills/monodesign/reference/clarify.md +0 -174
- package/.claude/skills/monodesign/reference/cognitive-load.md +0 -106
- package/.claude/skills/monodesign/reference/color-and-contrast.md +0 -105
- package/.claude/skills/monodesign/reference/colorize.md +0 -154
- package/.claude/skills/monodesign/reference/component-specs.md +0 -260
- package/.claude/skills/monodesign/reference/component-states.md +0 -274
- package/.claude/skills/monodesign/reference/component-system.md +0 -358
- package/.claude/skills/monodesign/reference/copy-formulas.md +0 -160
- package/.claude/skills/monodesign/reference/craft.md +0 -193
- package/.claude/skills/monodesign/reference/critique.md +0 -213
- package/.claude/skills/monodesign/reference/delight.md +0 -302
- package/.claude/skills/monodesign/reference/design-principles.md +0 -246
- package/.claude/skills/monodesign/reference/distill.md +0 -111
- package/.claude/skills/monodesign/reference/document.md +0 -427
- package/.claude/skills/monodesign/reference/extract.md +0 -69
- package/.claude/skills/monodesign/reference/harden.md +0 -347
- package/.claude/skills/monodesign/reference/heuristics-scoring.md +0 -234
- package/.claude/skills/monodesign/reference/image-prompts.md +0 -118
- package/.claude/skills/monodesign/reference/interaction-design.md +0 -195
- package/.claude/skills/monodesign/reference/layout.md +0 -141
- package/.claude/skills/monodesign/reference/live.md +0 -622
- package/.claude/skills/monodesign/reference/motion-design.md +0 -109
- package/.claude/skills/monodesign/reference/onboard.md +0 -234
- package/.claude/skills/monodesign/reference/optimize.md +0 -258
- package/.claude/skills/monodesign/reference/overdrive.md +0 -130
- package/.claude/skills/monodesign/reference/personas.md +0 -179
- package/.claude/skills/monodesign/reference/polish.md +0 -233
- package/.claude/skills/monodesign/reference/pre-delivery-checklist.md +0 -108
- package/.claude/skills/monodesign/reference/product.md +0 -62
- package/.claude/skills/monodesign/reference/quieter.md +0 -99
- package/.claude/skills/monodesign/reference/responsive-design.md +0 -114
- package/.claude/skills/monodesign/reference/shape.md +0 -151
- package/.claude/skills/monodesign/reference/spatial-design.md +0 -100
- package/.claude/skills/monodesign/reference/teach.md +0 -156
- package/.claude/skills/monodesign/reference/token-architecture.md +0 -222
- package/.claude/skills/monodesign/reference/typeset.md +0 -124
- package/.claude/skills/monodesign/reference/typography.md +0 -159
- package/.claude/skills/monodesign/reference/ux-research.md +0 -143
- package/.claude/skills/monodesign/reference/ux-rules.md +0 -211
- package/.claude/skills/monodesign/reference/ux-writing.md +0 -107
- package/.claude/skills/monomotion/SKILL.md +0 -145
- package/.claude/skills/monomotion/rules/api-control.md +0 -139
- package/.claude/skills/monomotion/rules/effects.md +0 -109
- package/.claude/skills/monomotion/rules/integration.md +0 -140
- package/.claude/skills/monomotion/rules/scroll.md +0 -131
- package/.claude/skills/monomotion/rules/sequencing.md +0 -105
- package/.claude/skills/monomotion/rules/svg.md +0 -101
- package/.claude/skills/monomotion/rules/text.md +0 -119
- package/.claude/skills/pair-programming/SKILL.md +0 -1202
- package/.claude/skills/performance-analysis/SKILL.md +0 -560
- package/.claude/skills/performance-optimization/SKILL.md +0 -416
- package/.claude/skills/reasoningbank-agentdb/SKILL.md +0 -444
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +0 -199
- package/.claude/skills/security-hardening/SKILL.md +0 -101
- package/.claude/skills/skill-builder/SKILL.md +0 -910
- package/.claude/skills/sparc-methodology/SKILL.md +0 -950
- package/.claude/skills/specialagent/SKILL.md +0 -208
- package/.claude/skills/stop-slop/SKILL.md +0 -67
- package/.claude/skills/stop-slop/references/examples.md +0 -61
- package/.claude/skills/stop-slop/references/phrases.md +0 -130
- package/.claude/skills/stop-slop/references/structures.md +0 -136
- package/.claude/skills/stream-chain/SKILL.md +0 -560
- package/.claude/skills/swarm-advanced/SKILL.md +0 -940
- package/.claude/skills/swarm-coordination/SKILL.md +0 -451
- package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
- package/.claude/skills/verification-quality/SKILL.md +0 -674
- package/.claude/statusline-command.sh +0 -176
- package/.claude/statusline.mjs +0 -109
- package/.claude/statusline.sh +0 -431
- package/.claude/workflows/feature-dev.yaml +0 -18
- package/.claude/workflows/security-audit.yaml +0 -10
- package/.claude-plugin/README.md +0 -705
- package/.claude-plugin/docs/INSTALLATION.md +0 -258
- package/.claude-plugin/docs/PLUGIN_SUMMARY.md +0 -359
- package/.claude-plugin/docs/QUICKSTART.md +0 -360
- package/.claude-plugin/docs/STRUCTURE.md +0 -126
- package/.claude-plugin/hooks/hooks.json +0 -74
- package/.claude-plugin/marketplace.json +0 -98
- package/.claude-plugin/plugin.json +0 -70
- package/.claude-plugin/scripts/install.sh +0 -234
- package/.claude-plugin/scripts/uninstall.sh +0 -36
- package/.claude-plugin/scripts/verify.sh +0 -108
- package/LICENSE +0 -21
- package/README.md +0 -441
- package/bin/cli.js +0 -11
- package/bin/npx-safe-launch.js +0 -9
- package/packages/@monomind/cli/README.md +0 -441
- package/packages/@monomind/cli/bin/cli.js +0 -221
- package/packages/@monomind/cli/bin/mcp-server.js +0 -189
- package/packages/@monomind/cli/bin/preinstall.cjs +0 -2
- package/packages/@monomind/cli/bundled-graph/dist/tsconfig.tsbuildinfo +0 -1
- package/packages/@monomind/cli/bundled-graph/package.json +0 -57
- package/packages/@monomind/cli/package.json +0 -114
- package/packages/@monomind/guidance/README.md +0 -1192
- package/packages/@monomind/guidance/dist/adversarial.d.ts +0 -284
- package/packages/@monomind/guidance/dist/adversarial.js +0 -572
- package/packages/@monomind/guidance/dist/analyzer.d.ts +0 -530
- package/packages/@monomind/guidance/dist/analyzer.js +0 -2518
- package/packages/@monomind/guidance/dist/artifacts.d.ts +0 -283
- package/packages/@monomind/guidance/dist/artifacts.js +0 -356
- package/packages/@monomind/guidance/dist/authority.d.ts +0 -290
- package/packages/@monomind/guidance/dist/authority.js +0 -558
- package/packages/@monomind/guidance/dist/capabilities.d.ts +0 -209
- package/packages/@monomind/guidance/dist/capabilities.js +0 -485
- package/packages/@monomind/guidance/dist/coherence.d.ts +0 -233
- package/packages/@monomind/guidance/dist/coherence.js +0 -372
- package/packages/@monomind/guidance/dist/compiler.d.ts +0 -87
- package/packages/@monomind/guidance/dist/compiler.js +0 -419
- package/packages/@monomind/guidance/dist/conformance-kit.d.ts +0 -225
- package/packages/@monomind/guidance/dist/conformance-kit.js +0 -629
- package/packages/@monomind/guidance/dist/continue-gate.d.ts +0 -214
- package/packages/@monomind/guidance/dist/continue-gate.js +0 -353
- package/packages/@monomind/guidance/dist/crypto-utils.d.ts +0 -17
- package/packages/@monomind/guidance/dist/crypto-utils.js +0 -24
- package/packages/@monomind/guidance/dist/evolution.d.ts +0 -282
- package/packages/@monomind/guidance/dist/evolution.js +0 -500
- package/packages/@monomind/guidance/dist/gates.d.ts +0 -79
- package/packages/@monomind/guidance/dist/gates.js +0 -302
- package/packages/@monomind/guidance/dist/gateway.d.ts +0 -206
- package/packages/@monomind/guidance/dist/gateway.js +0 -452
- package/packages/@monomind/guidance/dist/generators.d.ts +0 -153
- package/packages/@monomind/guidance/dist/generators.js +0 -682
- package/packages/@monomind/guidance/dist/headless.d.ts +0 -177
- package/packages/@monomind/guidance/dist/headless.js +0 -342
- package/packages/@monomind/guidance/dist/hooks.d.ts +0 -109
- package/packages/@monomind/guidance/dist/hooks.js +0 -347
- package/packages/@monomind/guidance/dist/index.d.ts +0 -205
- package/packages/@monomind/guidance/dist/index.js +0 -321
- package/packages/@monomind/guidance/dist/ledger.d.ts +0 -162
- package/packages/@monomind/guidance/dist/ledger.js +0 -375
- package/packages/@monomind/guidance/dist/manifest-validator.d.ts +0 -289
- package/packages/@monomind/guidance/dist/manifest-validator.js +0 -838
- package/packages/@monomind/guidance/dist/memory-gate.d.ts +0 -222
- package/packages/@monomind/guidance/dist/memory-gate.js +0 -382
- package/packages/@monomind/guidance/dist/meta-governance.d.ts +0 -265
- package/packages/@monomind/guidance/dist/meta-governance.js +0 -348
- package/packages/@monomind/guidance/dist/optimizer.d.ts +0 -104
- package/packages/@monomind/guidance/dist/optimizer.js +0 -329
- package/packages/@monomind/guidance/dist/persistence.d.ts +0 -189
- package/packages/@monomind/guidance/dist/persistence.js +0 -464
- package/packages/@monomind/guidance/dist/proof.d.ts +0 -185
- package/packages/@monomind/guidance/dist/proof.js +0 -238
- package/packages/@monomind/guidance/dist/retriever.d.ts +0 -116
- package/packages/@monomind/guidance/dist/retriever.js +0 -394
- package/packages/@monomind/guidance/dist/ruvbot-integration.d.ts +0 -370
- package/packages/@monomind/guidance/dist/ruvbot-integration.js +0 -738
- package/packages/@monomind/guidance/dist/temporal.d.ts +0 -426
- package/packages/@monomind/guidance/dist/temporal.js +0 -658
- package/packages/@monomind/guidance/dist/trust.d.ts +0 -283
- package/packages/@monomind/guidance/dist/trust.js +0 -473
- package/packages/@monomind/guidance/dist/truth-anchors.d.ts +0 -276
- package/packages/@monomind/guidance/dist/truth-anchors.js +0 -488
- package/packages/@monomind/guidance/dist/types.d.ts +0 -378
- package/packages/@monomind/guidance/dist/types.js +0 -10
- package/packages/@monomind/guidance/dist/uncertainty.d.ts +0 -372
- package/packages/@monomind/guidance/dist/uncertainty.js +0 -619
- package/packages/@monomind/guidance/dist/wasm-kernel.d.ts +0 -48
- package/packages/@monomind/guidance/dist/wasm-kernel.js +0 -158
- package/packages/@monomind/guidance/package.json +0 -198
- package/packages/@monomind/shared/README.md +0 -322
- package/packages/@monomind/shared/dist/agent-contract.d.ts +0 -28
- package/packages/@monomind/shared/dist/agent-contract.js +0 -57
- package/packages/@monomind/shared/dist/agent-error-result.d.ts +0 -17
- package/packages/@monomind/shared/dist/agent-error-result.js +0 -23
- package/packages/@monomind/shared/dist/core/config/defaults.d.ts +0 -41
- package/packages/@monomind/shared/dist/core/config/defaults.js +0 -186
- package/packages/@monomind/shared/dist/core/config/index.d.ts +0 -8
- package/packages/@monomind/shared/dist/core/config/index.js +0 -12
- package/packages/@monomind/shared/dist/core/config/loader.d.ts +0 -45
- package/packages/@monomind/shared/dist/core/config/loader.js +0 -238
- package/packages/@monomind/shared/dist/core/config/schema.d.ts +0 -324
- package/packages/@monomind/shared/dist/core/config/schema.js +0 -160
- package/packages/@monomind/shared/dist/core/config/validator.d.ts +0 -92
- package/packages/@monomind/shared/dist/core/config/validator.js +0 -147
- package/packages/@monomind/shared/dist/core/event-bus.d.ts +0 -31
- package/packages/@monomind/shared/dist/core/event-bus.js +0 -197
- package/packages/@monomind/shared/dist/core/index.d.ts +0 -15
- package/packages/@monomind/shared/dist/core/index.js +0 -19
- package/packages/@monomind/shared/dist/core/interfaces/agent.interface.d.ts +0 -200
- package/packages/@monomind/shared/dist/core/interfaces/agent.interface.js +0 -6
- package/packages/@monomind/shared/dist/core/interfaces/coordinator.interface.d.ts +0 -310
- package/packages/@monomind/shared/dist/core/interfaces/coordinator.interface.js +0 -7
- package/packages/@monomind/shared/dist/core/interfaces/event.interface.d.ts +0 -224
- package/packages/@monomind/shared/dist/core/interfaces/event.interface.js +0 -46
- package/packages/@monomind/shared/dist/core/interfaces/index.d.ts +0 -10
- package/packages/@monomind/shared/dist/core/interfaces/index.js +0 -15
- package/packages/@monomind/shared/dist/core/interfaces/memory.interface.d.ts +0 -298
- package/packages/@monomind/shared/dist/core/interfaces/memory.interface.js +0 -7
- package/packages/@monomind/shared/dist/core/interfaces/task.interface.d.ts +0 -185
- package/packages/@monomind/shared/dist/core/interfaces/task.interface.js +0 -6
- package/packages/@monomind/shared/dist/core/orchestrator/event-coordinator.d.ts +0 -35
- package/packages/@monomind/shared/dist/core/orchestrator/event-coordinator.js +0 -101
- package/packages/@monomind/shared/dist/core/orchestrator/health-monitor.d.ts +0 -60
- package/packages/@monomind/shared/dist/core/orchestrator/health-monitor.js +0 -166
- package/packages/@monomind/shared/dist/core/orchestrator/index.d.ts +0 -46
- package/packages/@monomind/shared/dist/core/orchestrator/index.js +0 -64
- package/packages/@monomind/shared/dist/core/orchestrator/lifecycle-manager.d.ts +0 -56
- package/packages/@monomind/shared/dist/core/orchestrator/lifecycle-manager.js +0 -195
- package/packages/@monomind/shared/dist/core/orchestrator/session-manager.d.ts +0 -83
- package/packages/@monomind/shared/dist/core/orchestrator/session-manager.js +0 -193
- package/packages/@monomind/shared/dist/core/orchestrator/task-manager.d.ts +0 -49
- package/packages/@monomind/shared/dist/core/orchestrator/task-manager.js +0 -253
- package/packages/@monomind/shared/dist/events/domain-events.d.ts +0 -282
- package/packages/@monomind/shared/dist/events/domain-events.js +0 -165
- package/packages/@monomind/shared/dist/events/event-store.d.ts +0 -126
- package/packages/@monomind/shared/dist/events/event-store.js +0 -416
- package/packages/@monomind/shared/dist/events/event-store.test.d.ts +0 -8
- package/packages/@monomind/shared/dist/events/event-store.test.js +0 -293
- package/packages/@monomind/shared/dist/events/example-usage.d.ts +0 -10
- package/packages/@monomind/shared/dist/events/example-usage.js +0 -193
- package/packages/@monomind/shared/dist/events/index.d.ts +0 -21
- package/packages/@monomind/shared/dist/events/index.js +0 -22
- package/packages/@monomind/shared/dist/events/projections.d.ts +0 -177
- package/packages/@monomind/shared/dist/events/projections.js +0 -421
- package/packages/@monomind/shared/dist/events/rvf-event-log.d.ts +0 -82
- package/packages/@monomind/shared/dist/events/rvf-event-log.js +0 -340
- package/packages/@monomind/shared/dist/events/state-reconstructor.d.ts +0 -101
- package/packages/@monomind/shared/dist/events/state-reconstructor.js +0 -263
- package/packages/@monomind/shared/dist/events.d.ts +0 -80
- package/packages/@monomind/shared/dist/events.js +0 -249
- package/packages/@monomind/shared/dist/hooks/example-usage.d.ts +0 -42
- package/packages/@monomind/shared/dist/hooks/example-usage.js +0 -351
- package/packages/@monomind/shared/dist/hooks/executor.d.ts +0 -100
- package/packages/@monomind/shared/dist/hooks/executor.js +0 -264
- package/packages/@monomind/shared/dist/hooks/hooks.test.d.ts +0 -9
- package/packages/@monomind/shared/dist/hooks/hooks.test.js +0 -322
- package/packages/@monomind/shared/dist/hooks/index.d.ts +0 -52
- package/packages/@monomind/shared/dist/hooks/index.js +0 -51
- package/packages/@monomind/shared/dist/hooks/registry.d.ts +0 -133
- package/packages/@monomind/shared/dist/hooks/registry.js +0 -277
- package/packages/@monomind/shared/dist/hooks/safety/bash-safety.d.ts +0 -105
- package/packages/@monomind/shared/dist/hooks/safety/bash-safety.js +0 -481
- package/packages/@monomind/shared/dist/hooks/safety/file-organization.d.ts +0 -144
- package/packages/@monomind/shared/dist/hooks/safety/file-organization.js +0 -328
- package/packages/@monomind/shared/dist/hooks/safety/git-commit.d.ts +0 -158
- package/packages/@monomind/shared/dist/hooks/safety/git-commit.js +0 -450
- package/packages/@monomind/shared/dist/hooks/safety/index.d.ts +0 -17
- package/packages/@monomind/shared/dist/hooks/safety/index.js +0 -17
- package/packages/@monomind/shared/dist/hooks/session-hooks.d.ts +0 -234
- package/packages/@monomind/shared/dist/hooks/session-hooks.js +0 -334
- package/packages/@monomind/shared/dist/hooks/task-hooks.d.ts +0 -163
- package/packages/@monomind/shared/dist/hooks/task-hooks.js +0 -326
- package/packages/@monomind/shared/dist/hooks/types.d.ts +0 -267
- package/packages/@monomind/shared/dist/hooks/types.js +0 -62
- package/packages/@monomind/shared/dist/hooks/verify-exports.test.d.ts +0 -9
- package/packages/@monomind/shared/dist/hooks/verify-exports.test.js +0 -93
- package/packages/@monomind/shared/dist/index.d.ts +0 -46
- package/packages/@monomind/shared/dist/index.js +0 -77
- package/packages/@monomind/shared/dist/mcp/connection-pool.d.ts +0 -98
- package/packages/@monomind/shared/dist/mcp/connection-pool.js +0 -364
- package/packages/@monomind/shared/dist/mcp/index.d.ts +0 -69
- package/packages/@monomind/shared/dist/mcp/index.js +0 -84
- package/packages/@monomind/shared/dist/mcp/server.d.ts +0 -166
- package/packages/@monomind/shared/dist/mcp/server.js +0 -593
- package/packages/@monomind/shared/dist/mcp/session-manager.d.ts +0 -136
- package/packages/@monomind/shared/dist/mcp/session-manager.js +0 -335
- package/packages/@monomind/shared/dist/mcp/tool-registry.d.ts +0 -178
- package/packages/@monomind/shared/dist/mcp/tool-registry.js +0 -439
- package/packages/@monomind/shared/dist/mcp/transport/http.d.ts +0 -104
- package/packages/@monomind/shared/dist/mcp/transport/http.js +0 -476
- package/packages/@monomind/shared/dist/mcp/transport/index.d.ts +0 -102
- package/packages/@monomind/shared/dist/mcp/transport/index.js +0 -238
- package/packages/@monomind/shared/dist/mcp/transport/stdio.d.ts +0 -104
- package/packages/@monomind/shared/dist/mcp/transport/stdio.js +0 -263
- package/packages/@monomind/shared/dist/mcp/transport/websocket.d.ts +0 -133
- package/packages/@monomind/shared/dist/mcp/transport/websocket.js +0 -396
- package/packages/@monomind/shared/dist/mcp/types.d.ts +0 -438
- package/packages/@monomind/shared/dist/mcp/types.js +0 -54
- package/packages/@monomind/shared/dist/plugin-interface.d.ts +0 -544
- package/packages/@monomind/shared/dist/plugin-interface.js +0 -23
- package/packages/@monomind/shared/dist/plugin-loader.d.ts +0 -139
- package/packages/@monomind/shared/dist/plugin-loader.js +0 -434
- package/packages/@monomind/shared/dist/plugin-registry.d.ts +0 -183
- package/packages/@monomind/shared/dist/plugin-registry.js +0 -457
- package/packages/@monomind/shared/dist/plugins/index.d.ts +0 -10
- package/packages/@monomind/shared/dist/plugins/index.js +0 -10
- package/packages/@monomind/shared/dist/plugins/official/hive-mind-plugin.d.ts +0 -106
- package/packages/@monomind/shared/dist/plugins/official/hive-mind-plugin.js +0 -241
- package/packages/@monomind/shared/dist/plugins/official/index.d.ts +0 -10
- package/packages/@monomind/shared/dist/plugins/official/index.js +0 -10
- package/packages/@monomind/shared/dist/plugins/official/maestro-plugin.d.ts +0 -121
- package/packages/@monomind/shared/dist/plugins/official/maestro-plugin.js +0 -355
- package/packages/@monomind/shared/dist/plugins/types.d.ts +0 -93
- package/packages/@monomind/shared/dist/plugins/types.js +0 -9
- package/packages/@monomind/shared/dist/reducers.d.ts +0 -33
- package/packages/@monomind/shared/dist/reducers.js +0 -89
- package/packages/@monomind/shared/dist/resilience/bulkhead.d.ts +0 -105
- package/packages/@monomind/shared/dist/resilience/bulkhead.js +0 -206
- package/packages/@monomind/shared/dist/resilience/circuit-breaker.d.ts +0 -132
- package/packages/@monomind/shared/dist/resilience/circuit-breaker.js +0 -233
- package/packages/@monomind/shared/dist/resilience/index.d.ts +0 -19
- package/packages/@monomind/shared/dist/resilience/index.js +0 -19
- package/packages/@monomind/shared/dist/resilience/rate-limiter.d.ts +0 -168
- package/packages/@monomind/shared/dist/resilience/rate-limiter.js +0 -314
- package/packages/@monomind/shared/dist/resilience/retry.d.ts +0 -91
- package/packages/@monomind/shared/dist/resilience/retry.js +0 -159
- package/packages/@monomind/shared/dist/retry-policy.d.ts +0 -14
- package/packages/@monomind/shared/dist/retry-policy.js +0 -23
- package/packages/@monomind/shared/dist/retry-runner.d.ts +0 -21
- package/packages/@monomind/shared/dist/retry-runner.js +0 -57
- package/packages/@monomind/shared/dist/schema-validator.d.ts +0 -46
- package/packages/@monomind/shared/dist/schema-validator.js +0 -133
- package/packages/@monomind/shared/dist/scratchpad.d.ts +0 -23
- package/packages/@monomind/shared/dist/scratchpad.js +0 -32
- package/packages/@monomind/shared/dist/security/index.d.ts +0 -10
- package/packages/@monomind/shared/dist/security/index.js +0 -12
- package/packages/@monomind/shared/dist/security/input-validation.d.ts +0 -73
- package/packages/@monomind/shared/dist/security/input-validation.js +0 -201
- package/packages/@monomind/shared/dist/security/secure-random.d.ts +0 -92
- package/packages/@monomind/shared/dist/security/secure-random.js +0 -142
- package/packages/@monomind/shared/dist/services/index.d.ts +0 -7
- package/packages/@monomind/shared/dist/services/index.js +0 -7
- package/packages/@monomind/shared/dist/services/progress.service.d.ts +0 -124
- package/packages/@monomind/shared/dist/services/progress.service.js +0 -402
- package/packages/@monomind/shared/dist/state-manager.d.ts +0 -34
- package/packages/@monomind/shared/dist/state-manager.js +0 -73
- package/packages/@monomind/shared/dist/state-validator.d.ts +0 -20
- package/packages/@monomind/shared/dist/state-validator.js +0 -49
- package/packages/@monomind/shared/dist/swarm-state.d.ts +0 -52
- package/packages/@monomind/shared/dist/swarm-state.js +0 -18
- package/packages/@monomind/shared/dist/testing/fixture-builder.d.ts +0 -14
- package/packages/@monomind/shared/dist/testing/fixture-builder.js +0 -32
- package/packages/@monomind/shared/dist/testing/index.d.ts +0 -2
- package/packages/@monomind/shared/dist/testing/index.js +0 -2
- package/packages/@monomind/shared/dist/testing/test-model.d.ts +0 -29
- package/packages/@monomind/shared/dist/testing/test-model.js +0 -53
- package/packages/@monomind/shared/dist/types/agent-registry.d.ts +0 -62
- package/packages/@monomind/shared/dist/types/agent-registry.js +0 -8
- package/packages/@monomind/shared/dist/types/agent-version.d.ts +0 -49
- package/packages/@monomind/shared/dist/types/agent-version.js +0 -7
- package/packages/@monomind/shared/dist/types/agent.types.d.ts +0 -137
- package/packages/@monomind/shared/dist/types/agent.types.js +0 -6
- package/packages/@monomind/shared/dist/types/benchmark.d.ts +0 -39
- package/packages/@monomind/shared/dist/types/benchmark.js +0 -6
- package/packages/@monomind/shared/dist/types/communication-flow.d.ts +0 -25
- package/packages/@monomind/shared/dist/types/communication-flow.js +0 -7
- package/packages/@monomind/shared/dist/types/consensus-audit.d.ts +0 -40
- package/packages/@monomind/shared/dist/types/consensus-audit.js +0 -7
- package/packages/@monomind/shared/dist/types/dlq.d.ts +0 -40
- package/packages/@monomind/shared/dist/types/dlq.js +0 -7
- package/packages/@monomind/shared/dist/types/eval.d.ts +0 -59
- package/packages/@monomind/shared/dist/types/eval.js +0 -6
- package/packages/@monomind/shared/dist/types/index.d.ts +0 -19
- package/packages/@monomind/shared/dist/types/index.js +0 -33
- package/packages/@monomind/shared/dist/types/mcp.types.d.ts +0 -266
- package/packages/@monomind/shared/dist/types/mcp.types.js +0 -7
- package/packages/@monomind/shared/dist/types/memory.types.d.ts +0 -236
- package/packages/@monomind/shared/dist/types/memory.types.js +0 -7
- package/packages/@monomind/shared/dist/types/retry.d.ts +0 -72
- package/packages/@monomind/shared/dist/types/retry.js +0 -40
- package/packages/@monomind/shared/dist/types/specialization.d.ts +0 -27
- package/packages/@monomind/shared/dist/types/specialization.js +0 -8
- package/packages/@monomind/shared/dist/types/swarm.types.d.ts +0 -186
- package/packages/@monomind/shared/dist/types/swarm.types.js +0 -65
- package/packages/@monomind/shared/dist/types/task.types.d.ts +0 -178
- package/packages/@monomind/shared/dist/types/task.types.js +0 -32
- package/packages/@monomind/shared/dist/types/termination.d.ts +0 -29
- package/packages/@monomind/shared/dist/types/termination.js +0 -14
- package/packages/@monomind/shared/dist/types/tool-version.d.ts +0 -41
- package/packages/@monomind/shared/dist/types/tool-version.js +0 -8
- package/packages/@monomind/shared/dist/types/trigger.d.ts +0 -40
- package/packages/@monomind/shared/dist/types/trigger.js +0 -8
- package/packages/@monomind/shared/dist/types.d.ts +0 -197
- package/packages/@monomind/shared/dist/types.js +0 -21
- package/packages/@monomind/shared/dist/utils/secure-logger.d.ts +0 -69
- package/packages/@monomind/shared/dist/utils/secure-logger.js +0 -208
- package/packages/@monomind/shared/package.json +0 -42
- package/packages/README.md +0 -513
|
@@ -1,1718 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Monomind Hook Handler (Cross-Platform)
|
|
4
|
-
* Dispatches hook events to the appropriate helper modules.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
|
|
10
|
-
const helpersDir = __dirname;
|
|
11
|
-
const CWD = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
12
|
-
|
|
13
|
-
// Resolve @monoes/monograph — it lives in pnpm's virtual store, not a named symlink.
|
|
14
|
-
// Try common locations; fall back gracefully so all hooks remain non-fatal.
|
|
15
|
-
function _requireMonograph() {
|
|
16
|
-
var candidates = [
|
|
17
|
-
path.join(CWD, 'node_modules/.pnpm/node_modules/@monoes/monograph'),
|
|
18
|
-
path.join(CWD, 'packages/node_modules/.pnpm/node_modules/@monoes/monograph'),
|
|
19
|
-
path.join(CWD, 'node_modules/@monoes/monograph'),
|
|
20
|
-
];
|
|
21
|
-
for (var i = 0; i < candidates.length; i++) {
|
|
22
|
-
try { if (fs.existsSync(candidates[i])) return require(candidates[i]); } catch(e) {}
|
|
23
|
-
}
|
|
24
|
-
try { return require('@monoes/monograph'); } catch(e) {}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function safeRequire(modulePath) {
|
|
29
|
-
try {
|
|
30
|
-
if (fs.existsSync(modulePath)) {
|
|
31
|
-
const origLog = console.log;
|
|
32
|
-
const origError = console.error;
|
|
33
|
-
console.log = () => {};
|
|
34
|
-
console.error = () => {};
|
|
35
|
-
try {
|
|
36
|
-
const mod = require(modulePath);
|
|
37
|
-
return mod;
|
|
38
|
-
} finally {
|
|
39
|
-
console.log = origLog;
|
|
40
|
-
console.error = origError;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} catch (e) {
|
|
44
|
-
// silently fail
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const router = safeRequire(path.join(helpersDir, 'router.cjs'));
|
|
50
|
-
const session = safeRequire(path.join(helpersDir, 'session.cjs'));
|
|
51
|
-
const memory = safeRequire(path.join(helpersDir, 'memory.cjs'));
|
|
52
|
-
const intelligence = safeRequire(path.join(helpersDir, 'intelligence.cjs'));
|
|
53
|
-
|
|
54
|
-
// Module-level reference to @monomind/hooks — populated at session-restore,
|
|
55
|
-
// then used by pre-task / post-task to bridge into the hook registry (Tasks 26, 39).
|
|
56
|
-
let _hooksModule = null;
|
|
57
|
-
|
|
58
|
-
// ── MicroAgent Trigger Scanner (Task 32) ────────────────────────────────────
|
|
59
|
-
function _triggerExtractYamlValue(raw) {
|
|
60
|
-
var v = raw.trim();
|
|
61
|
-
if (v.startsWith('"') && v.endsWith('"')) {
|
|
62
|
-
// YAML double-quoted: unescape \\ → \ so regex patterns like "\\b" become \b (word boundary)
|
|
63
|
-
v = v.slice(1, -1).replace(/\\\\/g, '\\');
|
|
64
|
-
} else if (v.startsWith("'") && v.endsWith("'")) {
|
|
65
|
-
v = v.slice(1, -1);
|
|
66
|
-
}
|
|
67
|
-
return v;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function _triggerFinalize(partial, agentSlug) {
|
|
71
|
-
return { pattern: partial.pattern, mode: partial.mode || 'inject', priority: partial.priority || 0, agentSlug: agentSlug };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function _triggerExtractFromFrontmatter(content, agentSlug) {
|
|
75
|
-
var fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
76
|
-
if (!fmMatch) return [];
|
|
77
|
-
var block = fmMatch[1];
|
|
78
|
-
var triggers = [];
|
|
79
|
-
var lines = block.split('\n');
|
|
80
|
-
var inTriggers = false;
|
|
81
|
-
var cur = null;
|
|
82
|
-
for (var i = 0; i < lines.length; i++) {
|
|
83
|
-
var line = lines[i];
|
|
84
|
-
var trimmed = line.trim();
|
|
85
|
-
var indent = line.length - line.trimStart().length;
|
|
86
|
-
if (trimmed === 'triggers:' || trimmed.startsWith('triggers:')) { inTriggers = true; continue; }
|
|
87
|
-
if (inTriggers && indent === 0 && /^[a-zA-Z]/.test(trimmed)) {
|
|
88
|
-
inTriggers = false;
|
|
89
|
-
if (cur && cur.pattern) triggers.push(_triggerFinalize(cur, agentSlug));
|
|
90
|
-
cur = null; continue;
|
|
91
|
-
}
|
|
92
|
-
if (!inTriggers) continue;
|
|
93
|
-
if (trimmed.startsWith('- pattern:')) {
|
|
94
|
-
if (cur && cur.pattern) triggers.push(_triggerFinalize(cur, agentSlug));
|
|
95
|
-
cur = { pattern: _triggerExtractYamlValue(trimmed.replace(/^- pattern:\s*/, '')), agentSlug: agentSlug };
|
|
96
|
-
} else if (cur && trimmed.startsWith('mode:')) {
|
|
97
|
-
var mv = _triggerExtractYamlValue(trimmed.replace(/^mode:\s*/, ''));
|
|
98
|
-
if (mv === 'inject' || mv === 'takeover') cur.mode = mv;
|
|
99
|
-
} else if (cur && trimmed.startsWith('priority:')) {
|
|
100
|
-
var pv = parseInt(trimmed.replace(/^priority:\s*/, ''), 10);
|
|
101
|
-
if (!isNaN(pv)) cur.priority = pv;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (cur && cur.pattern) triggers.push(_triggerFinalize(cur, agentSlug));
|
|
105
|
-
return triggers;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function _triggerCollectMdFiles(dir) {
|
|
109
|
-
var results = [];
|
|
110
|
-
try {
|
|
111
|
-
var entries = fs.readdirSync(dir);
|
|
112
|
-
for (var i = 0; i < entries.length; i++) {
|
|
113
|
-
var full = path.join(dir, entries[i]);
|
|
114
|
-
try {
|
|
115
|
-
var st = fs.lstatSync(full);
|
|
116
|
-
if (st.isDirectory()) results = results.concat(_triggerCollectMdFiles(full));
|
|
117
|
-
else if (entries[i].endsWith('.md')) results.push(full);
|
|
118
|
-
} catch (e) {}
|
|
119
|
-
}
|
|
120
|
-
} catch (e) {}
|
|
121
|
-
return results;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function _triggerBuildIndex(agentDir) {
|
|
125
|
-
var patterns = [];
|
|
126
|
-
var files = _triggerCollectMdFiles(agentDir);
|
|
127
|
-
for (var i = 0; i < files.length; i++) {
|
|
128
|
-
var content;
|
|
129
|
-
try { content = fs.readFileSync(files[i], 'utf-8'); } catch (e) { continue; }
|
|
130
|
-
var slug = files[i].split('/').pop().replace(/\.md$/i, '').toLowerCase().replace(/[^a-z0-9-]/g, '-');
|
|
131
|
-
patterns = patterns.concat(_triggerExtractFromFrontmatter(content, slug));
|
|
132
|
-
}
|
|
133
|
-
return patterns;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function scanMicroAgentTriggers(prompt) {
|
|
137
|
-
if (!prompt || typeof prompt !== 'string') return { matches: [], injectAgents: [] };
|
|
138
|
-
var indexPath = path.join(CWD, '.monomind', 'trigger-index.json');
|
|
139
|
-
var agentDir = path.join(CWD, '.claude', 'agents');
|
|
140
|
-
var patterns = [];
|
|
141
|
-
var cacheLoaded = false;
|
|
142
|
-
|
|
143
|
-
// Load cached index if fresh (< 1 hour)
|
|
144
|
-
try {
|
|
145
|
-
if (fs.existsSync(indexPath)) {
|
|
146
|
-
var idx = JSON.parse(fs.readFileSync(indexPath, 'utf-8'));
|
|
147
|
-
var age = Date.now() - new Date(idx.builtAt || 0).getTime();
|
|
148
|
-
if (age < 3600000 && Array.isArray(idx.patterns)) {
|
|
149
|
-
patterns = idx.patterns;
|
|
150
|
-
cacheLoaded = true; // valid even when empty (no triggers defined)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
} catch (e) {}
|
|
154
|
-
|
|
155
|
-
// Rebuild only when cache is missing or stale — not when it's a valid empty result
|
|
156
|
-
if (!cacheLoaded) {
|
|
157
|
-
patterns = _triggerBuildIndex(agentDir);
|
|
158
|
-
try {
|
|
159
|
-
fs.mkdirSync(path.join(CWD, '.monomind'), { recursive: true });
|
|
160
|
-
fs.writeFileSync(indexPath, JSON.stringify({ patterns: patterns, builtAt: new Date().toISOString(), totalAgentsScanned: patterns.length }));
|
|
161
|
-
} catch (e) {}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Sort by descending priority
|
|
165
|
-
patterns.sort(function(a, b) { return (b.priority || 0) - (a.priority || 0); });
|
|
166
|
-
|
|
167
|
-
// Apply patterns
|
|
168
|
-
var matches = [];
|
|
169
|
-
var seen = {};
|
|
170
|
-
for (var i = 0; i < patterns.length; i++) {
|
|
171
|
-
var p = patterns[i];
|
|
172
|
-
if (p.mode !== 'inject' && p.mode !== 'takeover') continue;
|
|
173
|
-
if (seen[p.agentSlug]) continue;
|
|
174
|
-
try {
|
|
175
|
-
var re = new RegExp(p.pattern, 'i');
|
|
176
|
-
var m = re.exec(prompt);
|
|
177
|
-
if (m) {
|
|
178
|
-
seen[p.agentSlug] = true;
|
|
179
|
-
matches.push({ agentSlug: p.agentSlug, mode: p.mode, matchedText: m[0] });
|
|
180
|
-
if (p.mode === 'takeover') {
|
|
181
|
-
return { matches: matches, takeoverAgent: p.agentSlug, injectAgents: [] };
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
} catch (e) {}
|
|
185
|
-
}
|
|
186
|
-
return { matches: matches, injectAgents: matches.map(function(m) { return m.agentSlug; }) };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ── Task 28: Knowledge Base — inline CJS search + auto-indexer ─────────────
|
|
190
|
-
//
|
|
191
|
-
// Purpose: give KnowledgeRetriever a real search function and pre-populate
|
|
192
|
-
// the knowledge store with project documents (CLAUDE.md, todo.md, etc.) so
|
|
193
|
-
// retrieveForTask() actually returns useful context on session restore.
|
|
194
|
-
// No compiled deps required — reads/writes JSONL directly.
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Build a simple keyword-overlap search function over chunks.jsonl.
|
|
198
|
-
* Returns results sorted by descending score; compatible with SearchFn signature.
|
|
199
|
-
*/
|
|
200
|
-
var _KNOWLEDGE_STOPWORDS = new Set(['the','and','or','but','if','in','on','to','is','it','be','do','of','for','not','at','by','as','we','us','an','a','i']);
|
|
201
|
-
|
|
202
|
-
function _buildKnowledgeSearchFn(knowledgeDir) {
|
|
203
|
-
return async function(query, opts) {
|
|
204
|
-
var chunksFile = path.join(knowledgeDir, 'chunks.jsonl');
|
|
205
|
-
if (!fs.existsSync(chunksFile)) return [];
|
|
206
|
-
var lines;
|
|
207
|
-
try {
|
|
208
|
-
lines = fs.readFileSync(chunksFile, 'utf-8').trim().split('\n').filter(Boolean);
|
|
209
|
-
} catch (e) { return []; }
|
|
210
|
-
|
|
211
|
-
var ns = (opts && opts.namespace) || null;
|
|
212
|
-
var limit = (opts && opts.limit) || 10;
|
|
213
|
-
var minScore = (opts && opts.minScore != null) ? opts.minScore : 0.3;
|
|
214
|
-
var queryTerms = query.toLowerCase().split(/\s+/).filter(function(t) { return t.length >= 2 && !_KNOWLEDGE_STOPWORDS.has(t); });
|
|
215
|
-
if (queryTerms.length === 0) return [];
|
|
216
|
-
|
|
217
|
-
var results = [];
|
|
218
|
-
for (var i = 0; i < lines.length; i++) {
|
|
219
|
-
try {
|
|
220
|
-
var chunk = JSON.parse(lines[i]);
|
|
221
|
-
if (ns && chunk.namespace !== ns) continue;
|
|
222
|
-
var textLower = (chunk.text || '').toLowerCase();
|
|
223
|
-
var matchCount = queryTerms.filter(function(t) { return textLower.includes(t); }).length;
|
|
224
|
-
var score = matchCount / queryTerms.length;
|
|
225
|
-
if (score >= minScore) {
|
|
226
|
-
results.push({ key: chunk.chunkId, value: chunk.text, score: score, metadata: chunk.metadata || {} });
|
|
227
|
-
}
|
|
228
|
-
} catch (e) {}
|
|
229
|
-
}
|
|
230
|
-
results.sort(function(a, b) { return b.score - a.score; });
|
|
231
|
-
return results.slice(0, limit);
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Index project knowledge sources into chunks.jsonl.
|
|
237
|
-
* Skips re-indexing if content hasn't changed (hash-gated).
|
|
238
|
-
* Returns the number of new chunks written.
|
|
239
|
-
*/
|
|
240
|
-
function _autoIndexKnowledge(knowledgeDir) {
|
|
241
|
-
var crypto = require('crypto');
|
|
242
|
-
var sources = [
|
|
243
|
-
{ filePath: path.join(CWD, 'CLAUDE.md'), label: 'project-instructions' },
|
|
244
|
-
{ filePath: path.join(CWD, 'docs/todo.md'), label: 'project-todo' },
|
|
245
|
-
{ filePath: path.join(CWD, 'CLAUDE.local.md'), label: 'local-instructions' },
|
|
246
|
-
];
|
|
247
|
-
|
|
248
|
-
// Compute a combined hash of all source file sizes (fast proxy for content change)
|
|
249
|
-
var hashInput = '';
|
|
250
|
-
for (var i = 0; i < sources.length; i++) {
|
|
251
|
-
try {
|
|
252
|
-
if (fs.existsSync(sources[i].filePath)) {
|
|
253
|
-
var st = fs.statSync(sources[i].filePath);
|
|
254
|
-
hashInput += sources[i].filePath + ':' + st.size + ':' + st.mtimeMs + ';';
|
|
255
|
-
}
|
|
256
|
-
} catch (e) {}
|
|
257
|
-
}
|
|
258
|
-
// Include monograph graph build time in hash so re-index happens after graph rebuild
|
|
259
|
-
try {
|
|
260
|
-
var statsForHash = JSON.parse(fs.readFileSync(path.join(CWD, '.monomind', 'graph', 'stats.json'), 'utf-8'));
|
|
261
|
-
hashInput += 'monograph:' + (statsForHash.builtAt || 0) + ';';
|
|
262
|
-
} catch(e) {}
|
|
263
|
-
|
|
264
|
-
var contentHash = crypto.createHash('md5').update(hashInput).digest('hex');
|
|
265
|
-
|
|
266
|
-
var chunksFile = path.join(knowledgeDir, 'chunks.jsonl');
|
|
267
|
-
var hashFile = path.join(knowledgeDir, '.index-hash');
|
|
268
|
-
var existingHash = '';
|
|
269
|
-
try { existingHash = fs.readFileSync(hashFile, 'utf-8').trim(); } catch (e) {}
|
|
270
|
-
|
|
271
|
-
// Nothing changed — skip re-index
|
|
272
|
-
var existingChunkCount = 0;
|
|
273
|
-
try { if (fs.existsSync(chunksFile)) { existingChunkCount = fs.readFileSync(chunksFile, 'utf-8').trim().split('\n').filter(Boolean).length; } } catch (e) {}
|
|
274
|
-
if (existingHash === contentHash && existingChunkCount > 0) return 0;
|
|
275
|
-
|
|
276
|
-
// Build new chunks
|
|
277
|
-
var newLines = [];
|
|
278
|
-
for (var si = 0; si < sources.length; si++) {
|
|
279
|
-
var src = sources[si];
|
|
280
|
-
try {
|
|
281
|
-
if (!fs.existsSync(src.filePath)) continue;
|
|
282
|
-
var content = fs.readFileSync(src.filePath, 'utf-8');
|
|
283
|
-
// Split on blank lines or markdown headers (## / ###)
|
|
284
|
-
var sections = content.split(/\n{2,}|\n(?=#{1,3} )/);
|
|
285
|
-
for (var ci = 0; ci < sections.length; ci++) {
|
|
286
|
-
var text = sections[ci].trim();
|
|
287
|
-
if (text.length < 40 || text.length > 3000) continue;
|
|
288
|
-
var chunkId = crypto.createHash('md5').update(src.filePath + ':' + ci).digest('hex').slice(0, 16);
|
|
289
|
-
newLines.push(JSON.stringify({
|
|
290
|
-
chunkId: chunkId,
|
|
291
|
-
namespace: 'knowledge:shared',
|
|
292
|
-
text: text,
|
|
293
|
-
metadata: { filePath: src.filePath, label: src.label, chunkIndex: ci }
|
|
294
|
-
}));
|
|
295
|
-
}
|
|
296
|
-
} catch (e) {}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Inject monograph graph summary as a knowledge chunk
|
|
300
|
-
try {
|
|
301
|
-
var statsPath = path.join(CWD, '.monomind', 'graph', 'stats.json');
|
|
302
|
-
var graphPath = path.join(CWD, '.monomind', 'graph', 'graph.json');
|
|
303
|
-
if (fs.existsSync(statsPath) && fs.existsSync(graphPath)) {
|
|
304
|
-
var stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8'));
|
|
305
|
-
var graphStat = fs.statSync(graphPath);
|
|
306
|
-
// Only read graph if under 10MB
|
|
307
|
-
if (graphStat.size < 10 * 1024 * 1024) {
|
|
308
|
-
var graph = JSON.parse(fs.readFileSync(graphPath, 'utf-8'));
|
|
309
|
-
var rawNodes = Array.isArray(graph.nodes) ? graph.nodes : [];
|
|
310
|
-
var rawEdges = Array.isArray(graph.edges) ? graph.edges : (Array.isArray(graph.links) ? graph.links : []);
|
|
311
|
-
// Top 15 nodes by degree (god nodes)
|
|
312
|
-
var degree = {};
|
|
313
|
-
rawNodes.forEach(function(n) { degree[n.id] = 0; });
|
|
314
|
-
rawEdges.forEach(function(e) {
|
|
315
|
-
if (degree[e.source] !== undefined) degree[e.source]++;
|
|
316
|
-
if (degree[e.target] !== undefined) degree[e.target]++;
|
|
317
|
-
});
|
|
318
|
-
var topNodes = rawNodes
|
|
319
|
-
.filter(function(n) { return n.sourceFile && n.sourceFile !== ''; })
|
|
320
|
-
.sort(function(a, b) { return (degree[b.id] || 0) - (degree[a.id] || 0); })
|
|
321
|
-
.slice(0, 15);
|
|
322
|
-
// Community summary — group by type
|
|
323
|
-
var typeCounts = {};
|
|
324
|
-
rawNodes.forEach(function(n) { var t = n.type || n.label || 'unknown'; typeCounts[t] = (typeCounts[t] || 0) + 1; });
|
|
325
|
-
var topTypes = Object.entries(typeCounts).sort(function(a,b){return b[1]-a[1];}).slice(0,8).map(function(e){return e[0]+':'+e[1];}).join(', ');
|
|
326
|
-
var builtDate = stats.builtAt ? new Date(stats.builtAt).toISOString().slice(0,10) : 'unknown';
|
|
327
|
-
var summaryText = [
|
|
328
|
-
'MONOGRAPH KNOWLEDGE GRAPH SUMMARY',
|
|
329
|
-
'Built: ' + builtDate + ' | Nodes: ' + (stats.nodes || rawNodes.length) + ' | Edges: ' + (stats.edges || rawEdges.length) + ' | Files: ' + (stats.files || 0),
|
|
330
|
-
'',
|
|
331
|
-
'TOP GOD NODES (highest connectivity):',
|
|
332
|
-
topNodes.map(function(n) {
|
|
333
|
-
return ' ' + (n.name || n.id) + ' [' + (n.type || n.label || '?') + '] — ' + (n.sourceFile || '') + ' (degree: ' + (degree[n.id] || 0) + ')';
|
|
334
|
-
}).join('\n'),
|
|
335
|
-
'',
|
|
336
|
-
'NODE TYPE DISTRIBUTION: ' + topTypes,
|
|
337
|
-
'',
|
|
338
|
-
'Use mcp__monomind__monograph_suggest to find files relevant to your task.',
|
|
339
|
-
'Use mcp__monomind__monograph_query to search for symbols.',
|
|
340
|
-
'Use mcp__monomind__monograph_god_nodes for architecture overview.',
|
|
341
|
-
].join('\n');
|
|
342
|
-
var chunkId = crypto.createHash('md5').update('monograph-graph-summary').digest('hex').slice(0, 16);
|
|
343
|
-
newLines.push(JSON.stringify({
|
|
344
|
-
chunkId: chunkId,
|
|
345
|
-
namespace: 'knowledge:shared',
|
|
346
|
-
text: summaryText,
|
|
347
|
-
metadata: { label: 'monograph-graph-summary', builtAt: stats.builtAt }
|
|
348
|
-
}));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
} catch (e) { /* graph not available yet, skip */ }
|
|
352
|
-
|
|
353
|
-
try {
|
|
354
|
-
fs.mkdirSync(knowledgeDir, { recursive: true });
|
|
355
|
-
fs.writeFileSync(chunksFile, newLines.length > 0 ? newLines.join('\n') + '\n' : '', 'utf-8');
|
|
356
|
-
fs.writeFileSync(hashFile, contentHash, 'utf-8');
|
|
357
|
-
} catch (e) {}
|
|
358
|
-
return newLines.length;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// ── Intelligence timeout protection (fixes #1530, #1531) ───────────────────
|
|
362
|
-
var INTELLIGENCE_TIMEOUT_MS = 1500;
|
|
363
|
-
function runWithTimeout(fn, label) {
|
|
364
|
-
return new Promise(function(resolve) {
|
|
365
|
-
var settled = false;
|
|
366
|
-
var timer = setTimeout(function() {
|
|
367
|
-
if (!settled) {
|
|
368
|
-
settled = true;
|
|
369
|
-
process.stderr.write("[WARN] " + label + " timed out after " + INTELLIGENCE_TIMEOUT_MS + "ms, skipping\n");
|
|
370
|
-
resolve(null);
|
|
371
|
-
}
|
|
372
|
-
}, INTELLIGENCE_TIMEOUT_MS);
|
|
373
|
-
Promise.resolve().then(fn).then(
|
|
374
|
-
function(result) { if (!settled) { settled = true; clearTimeout(timer); resolve(result); } },
|
|
375
|
-
function() { if (!settled) { settled = true; clearTimeout(timer); resolve(null); } }
|
|
376
|
-
);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const [,, command, ...args] = process.argv;
|
|
382
|
-
|
|
383
|
-
// Read stdin — Claude Code sends hook data as JSON via stdin
|
|
384
|
-
// Uses a timeout to prevent hanging when stdin is in an ambiguous state
|
|
385
|
-
// (not TTY, not a proper pipe) which happens with Claude Code hook invocations.
|
|
386
|
-
async function readStdin() {
|
|
387
|
-
if (process.stdin.isTTY) return '';
|
|
388
|
-
return new Promise((resolve) => {
|
|
389
|
-
let data = '';
|
|
390
|
-
const timer = setTimeout(() => {
|
|
391
|
-
process.stdin.removeAllListeners();
|
|
392
|
-
process.stdin.pause();
|
|
393
|
-
resolve(data);
|
|
394
|
-
}, 500);
|
|
395
|
-
process.stdin.setEncoding('utf8');
|
|
396
|
-
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
397
|
-
process.stdin.on('end', () => { clearTimeout(timer); resolve(data); });
|
|
398
|
-
process.stdin.on('error', () => { clearTimeout(timer); resolve(data); });
|
|
399
|
-
process.stdin.resume();
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
async function main() {
|
|
404
|
-
// Global safety timeout: hooks must NEVER hang (#1530, #1531)
|
|
405
|
-
var safetyTimer = setTimeout(function() {
|
|
406
|
-
process.stderr.write("[WARN] Hook handler global timeout (5s), forcing exit\n");
|
|
407
|
-
process.exit(0);
|
|
408
|
-
}, 5000);
|
|
409
|
-
safetyTimer.unref();
|
|
410
|
-
|
|
411
|
-
let stdinData = '';
|
|
412
|
-
try { stdinData = await readStdin(); } catch (e) { /* ignore stdin errors */ }
|
|
413
|
-
|
|
414
|
-
let hookInput = {};
|
|
415
|
-
if (stdinData.trim()) {
|
|
416
|
-
try {
|
|
417
|
-
const parsed = JSON.parse(stdinData);
|
|
418
|
-
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
419
|
-
hookInput = parsed;
|
|
420
|
-
}
|
|
421
|
-
} catch (e) { /* ignore parse errors */ }
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Merge stdin data into prompt resolution: prefer stdin fields, then env vars.
|
|
425
|
-
// NEVER fall back to argv args — shell glob expansion of braces in bash output
|
|
426
|
-
// creates junk files (#1342). Use env vars or stdin only.
|
|
427
|
-
// Normalize snake_case/camelCase: Claude Code sends tool_input/tool_name (snake_case)
|
|
428
|
-
var toolInput = hookInput.toolInput || hookInput.tool_input || {};
|
|
429
|
-
var toolName = hookInput.toolName || hookInput.tool_name || '';
|
|
430
|
-
|
|
431
|
-
var prompt = hookInput.prompt || hookInput.command
|
|
432
|
-
|| (typeof toolInput === 'string' ? toolInput : (toolInput.command || toolInput.prompt || ''))
|
|
433
|
-
|| process.env.PROMPT || process.env.TOOL_INPUT_command || '';
|
|
434
|
-
|
|
435
|
-
// Detect prompts that are predefined single-action commands that don't
|
|
436
|
-
// need agent routing or skill suggestions — invoking those adds token
|
|
437
|
-
// overhead without any benefit.
|
|
438
|
-
function isSimpleCommand(p) {
|
|
439
|
-
if (typeof p !== 'string') return false;
|
|
440
|
-
var s = p.trim();
|
|
441
|
-
// Slash commands: /ts, /list-agents, /commit, /help, /use-agent etc.
|
|
442
|
-
if (/^\/[a-z0-9_-]+(\s|$)/i.test(s)) return true;
|
|
443
|
-
// Short single-word operator tokens (toggle, list, status)
|
|
444
|
-
if (/^(ts|ls|ps|pwd|help|clear|exit|quit|status|toggle|refresh)$/i.test(s)) return true;
|
|
445
|
-
// Already-resolved command messages (Claude Code sends hook with command-name context)
|
|
446
|
-
var cmdName = hookInput.commandName || hookInput.command_name || '';
|
|
447
|
-
if (cmdName && cmdName.length > 0) return true;
|
|
448
|
-
return false;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
const handlers = {
|
|
452
|
-
'route': async () => {
|
|
453
|
-
// For slash commands and single-action invocations: skip routing panel output
|
|
454
|
-
// but still write last-route.json so the statusline reflects the current action.
|
|
455
|
-
if (isSimpleCommand(prompt)) {
|
|
456
|
-
try {
|
|
457
|
-
var cmdLabel = (typeof prompt === 'string' && prompt.trim().startsWith('/'))
|
|
458
|
-
? prompt.trim().split(/\s+/)[0] // e.g. "/ts"
|
|
459
|
-
: (hookInput.commandName || hookInput.command_name || 'command');
|
|
460
|
-
var routeDir = path.join(CWD, '.monomind');
|
|
461
|
-
fs.mkdirSync(routeDir, { recursive: true });
|
|
462
|
-
fs.writeFileSync(
|
|
463
|
-
path.join(routeDir, 'last-route.json'),
|
|
464
|
-
JSON.stringify({
|
|
465
|
-
agent: cmdLabel,
|
|
466
|
-
confidence: 1.0,
|
|
467
|
-
reason: 'predefined command — no routing needed',
|
|
468
|
-
semanticRouting: false,
|
|
469
|
-
updatedAt: new Date().toISOString(),
|
|
470
|
-
}),
|
|
471
|
-
'utf-8'
|
|
472
|
-
);
|
|
473
|
-
} catch (e) { /* non-fatal */ }
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
if (intelligence && intelligence.getContext) {
|
|
478
|
-
try {
|
|
479
|
-
const ctx = intelligence.getContext(prompt);
|
|
480
|
-
if (ctx) console.log(ctx);
|
|
481
|
-
} catch (e) { /* non-fatal */ }
|
|
482
|
-
}
|
|
483
|
-
if (router && (router.routeTaskSemantic || router.routeTask)) {
|
|
484
|
-
const routeFn = router.routeTaskSemantic || router.routeTask;
|
|
485
|
-
const result = await Promise.resolve(routeFn(prompt));
|
|
486
|
-
var output = [];
|
|
487
|
-
output.push('[INFO] Routing task: ' + (prompt.substring(0, 80) || '(no prompt)'));
|
|
488
|
-
output.push('');
|
|
489
|
-
output.push('+------------- monomind | Primary Recommendation --------------+');
|
|
490
|
-
output.push('| Agent: ' + (result.agent || 'unknown').substring(0, 54).padEnd(54) + '|');
|
|
491
|
-
output.push('| Confidence: ' + ((result.confidence != null ? (result.confidence * 100).toFixed(1) : '?') + '%').padEnd(49) + '|');
|
|
492
|
-
output.push('| Reason: ' + (result.reason || '').substring(0, 53).padEnd(53) + '|');
|
|
493
|
-
output.push('+--------------------------------------------------------------+');
|
|
494
|
-
|
|
495
|
-
// ── Persist routing result for statusline display ─────────────
|
|
496
|
-
try {
|
|
497
|
-
var routeDir = path.join(CWD, '.monomind');
|
|
498
|
-
fs.mkdirSync(routeDir, { recursive: true });
|
|
499
|
-
// Always use the resolved agent name — never persist "extras"
|
|
500
|
-
var resolvedAgent = result.agent;
|
|
501
|
-
if (!resolvedAgent || resolvedAgent === 'extras') {
|
|
502
|
-
var topExtra = result.extrasMatches && result.extrasMatches[0];
|
|
503
|
-
resolvedAgent = topExtra ? topExtra.name : 'Specialist Agent';
|
|
504
|
-
}
|
|
505
|
-
var routePayload = {
|
|
506
|
-
agent: resolvedAgent,
|
|
507
|
-
agentSlug: result.agentSlug || null,
|
|
508
|
-
confidence: result.confidence,
|
|
509
|
-
reason: result.reason,
|
|
510
|
-
semanticRouting: result.semanticRouting || false,
|
|
511
|
-
llmRouting: result.llmRouting || false,
|
|
512
|
-
updatedAt: new Date().toISOString(),
|
|
513
|
-
};
|
|
514
|
-
if (result.extrasMatches && result.extrasMatches.length > 0) {
|
|
515
|
-
routePayload.extrasMatches = result.extrasMatches.map(function(e) {
|
|
516
|
-
return { name: e.name, slug: e.slug, category: e.category };
|
|
517
|
-
});
|
|
518
|
-
}
|
|
519
|
-
fs.writeFileSync(
|
|
520
|
-
path.join(routeDir, 'last-route.json'),
|
|
521
|
-
JSON.stringify(routePayload),
|
|
522
|
-
'utf-8'
|
|
523
|
-
);
|
|
524
|
-
} catch (e) { /* non-fatal */ }
|
|
525
|
-
|
|
526
|
-
// ── Dev skill suggestions ──────────────────────────────────────
|
|
527
|
-
var matches = result.skillMatches || [];
|
|
528
|
-
if (matches.length > 0) {
|
|
529
|
-
// Check for high-confidence auto-invoke: if top skill scored >= 3 keyword
|
|
530
|
-
// hits and is the dominant match, auto-invoke instead of just suggesting
|
|
531
|
-
var topMatch = matches[0];
|
|
532
|
-
var autoInvoke = false;
|
|
533
|
-
if (topMatch && topMatch.score >= 3 && matches.length <= 2) {
|
|
534
|
-
autoInvoke = true;
|
|
535
|
-
} else if (topMatch && topMatch.score >= 2 && matches.length === 1 && (result.confidence ?? 0) < 0.7) {
|
|
536
|
-
// Single strong skill match with weak agent routing = skill should take over
|
|
537
|
-
autoInvoke = true;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if (autoInvoke) {
|
|
541
|
-
output.push('');
|
|
542
|
-
output.push('+======== SKILL AUTO-ACTIVATED (high confidence match) ========+');
|
|
543
|
-
output.push('| ' + topMatch.invoke.substring(0, 61).padEnd(61) + '|');
|
|
544
|
-
output.push('| INSTRUCTION: Invoke ' + topMatch.invoke.substring(0, 41).padEnd(41) + '|');
|
|
545
|
-
output.push('| BEFORE responding. This skill matched with very high |');
|
|
546
|
-
output.push('| confidence — do not skip it. |');
|
|
547
|
-
output.push('+==============================================================+');
|
|
548
|
-
} else {
|
|
549
|
-
output.push('');
|
|
550
|
-
if ((result.confidence ?? 0) < 0.8) {
|
|
551
|
-
output.push('+----------- Skill Suggestions (pick one if relevant) ---------+');
|
|
552
|
-
output.push('| No strong primary match — here are the best skill candidates |');
|
|
553
|
-
} else {
|
|
554
|
-
output.push('+----------- Matching Skills (invoke via Skill tool) ----------+');
|
|
555
|
-
}
|
|
556
|
-
matches.forEach(function(m, i) {
|
|
557
|
-
var label = (i + 1) + '. ' + m.skill;
|
|
558
|
-
var desc = (m.description || '').substring(0, 30);
|
|
559
|
-
var line = '| ' + label.substring(0, 30).padEnd(30) + desc.padEnd(30) + ' |';
|
|
560
|
-
output.push(line);
|
|
561
|
-
output.push('| invoke: ' + m.invoke.substring(0, 51).padEnd(51) + '|');
|
|
562
|
-
});
|
|
563
|
-
output.push('+--------------------------------------------------------------+');
|
|
564
|
-
if ((result.confidence ?? 0) < 0.8) {
|
|
565
|
-
output.push('| To use a skill: call Skill("skill-name") before responding. |');
|
|
566
|
-
output.push('+--------------------------------------------------------------+');
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// ── Specific agent panel ──────────────────────────────────────────────────
|
|
572
|
-
var specificAgents = result.specificAgents || [];
|
|
573
|
-
if (specificAgents.length > 0) {
|
|
574
|
-
output.push('');
|
|
575
|
-
var saHdr = '------- Specific Agents (' + specificAgents.length + ' available) ';
|
|
576
|
-
output.push('+' + saHdr + '-'.repeat(Math.max(1, 62 - saHdr.length)) + '+');
|
|
577
|
-
specificAgents.forEach(function(a, i) {
|
|
578
|
-
var label = (i + 1) + '. ' + a.label;
|
|
579
|
-
var note = (a.note || '').substring(0, 26);
|
|
580
|
-
output.push('| ' + label.substring(0, 33).padEnd(33) + note.padEnd(27) + ' |');
|
|
581
|
-
if (a.slug) {
|
|
582
|
-
output.push('| slug: ' + a.slug.substring(0, 52).padEnd(52) + ' |');
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
output.push('+--------------------------------------------------------------+');
|
|
586
|
-
output.push('| Use: Task({ subagent_type: "<slug>" }) or /specialagent |');
|
|
587
|
-
output.push('+--------------------------------------------------------------+');
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
// ── Specialist agents (non-dev domain) — only shown when specificAgents panel wasn't shown ──
|
|
591
|
-
var extras = result.extrasMatches || [];
|
|
592
|
-
var specificAgentsShown = (result.specificAgents || []).length > 0;
|
|
593
|
-
if (extras.length > 0 && !specificAgentsShown) {
|
|
594
|
-
output.push('');
|
|
595
|
-
var spHdr = '------- Specialist Agents (' + extras.length + ' matched) ';
|
|
596
|
-
output.push('+' + spHdr + '-'.repeat(Math.max(1, 62 - spHdr.length)) + '+');
|
|
597
|
-
extras.slice(0, 5).forEach(function(e, i) {
|
|
598
|
-
var label = (i + 1) + '. ' + e.name;
|
|
599
|
-
var cat = '[' + e.category + ']';
|
|
600
|
-
output.push('| ' + label.substring(0, 44).padEnd(44) + cat.substring(0, 16).padEnd(16) + ' |');
|
|
601
|
-
output.push('| slug: ' + e.slug.substring(0, 52).padEnd(52) + ' |');
|
|
602
|
-
});
|
|
603
|
-
output.push('+--------------------------------------------------------------+');
|
|
604
|
-
output.push('| Use: Task({ subagent_type: "<slug>" }) or /specialagent |');
|
|
605
|
-
output.push('+--------------------------------------------------------------+');
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
// ── MicroAgent Trigger Scan (Task 32) ──────────────────────────────
|
|
609
|
-
try {
|
|
610
|
-
var triggerResult = scanMicroAgentTriggers(typeof prompt === 'string' ? prompt : '');
|
|
611
|
-
if (triggerResult.matches.length > 0) {
|
|
612
|
-
output.push('');
|
|
613
|
-
if (triggerResult.takeoverAgent) {
|
|
614
|
-
var tAgent = triggerResult.takeoverAgent;
|
|
615
|
-
var tKw = triggerResult.matches[0].matchedText;
|
|
616
|
-
output.push('+============= MicroAgent TAKEOVER Detected ===================+');
|
|
617
|
-
output.push('| Specialist: ' + tAgent.substring(0, 49).padEnd(49) + '|');
|
|
618
|
-
output.push('| Keyword: ' + ('"' + tKw + '"').substring(0, 49).padEnd(49) + '|');
|
|
619
|
-
output.push('| Recommended: use this specialist instead of primary agent. |');
|
|
620
|
-
output.push('+==============================================================+');
|
|
621
|
-
} else {
|
|
622
|
-
output.push('+------- MicroAgent Specialists Triggered ---------------------+');
|
|
623
|
-
triggerResult.matches.forEach(function(m) {
|
|
624
|
-
var slug = m.agentSlug.substring(0, 37).padEnd(37);
|
|
625
|
-
var kw = ('(match: "' + m.matchedText + '")').substring(0, 21).padEnd(21);
|
|
626
|
-
output.push('| + ' + slug + kw + ' |');
|
|
627
|
-
});
|
|
628
|
-
output.push('+--------------------------------------------------------------+');
|
|
629
|
-
}
|
|
630
|
-
// Persist trigger matches alongside route result
|
|
631
|
-
try {
|
|
632
|
-
var routeFile = path.join(CWD, '.monomind', 'last-route.json');
|
|
633
|
-
var existing = JSON.parse(fs.readFileSync(routeFile, 'utf-8'));
|
|
634
|
-
existing.microAgents = { injectAgents: triggerResult.injectAgents || [], takeoverAgent: triggerResult.takeoverAgent || null };
|
|
635
|
-
fs.writeFileSync(routeFile, JSON.stringify(existing), 'utf-8');
|
|
636
|
-
} catch (e) {}
|
|
637
|
-
}
|
|
638
|
-
} catch (e) { /* non-fatal */ }
|
|
639
|
-
|
|
640
|
-
console.log(output.join('\n'));
|
|
641
|
-
|
|
642
|
-
// Inject monograph hint for complex tasks
|
|
643
|
-
try {
|
|
644
|
-
var graphStatsPath = path.join(CWD, '.monomind', 'graph', 'stats.json');
|
|
645
|
-
if (fs.existsSync(graphStatsPath)) {
|
|
646
|
-
var gStats = JSON.parse(fs.readFileSync(graphStatsPath, 'utf-8'));
|
|
647
|
-
if (gStats.nodes > 100) {
|
|
648
|
-
console.log('\n[MONOGRAPH] ' + gStats.nodes + ' nodes indexed. For this task, call mcp__monomind__monograph_suggest first.');
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
} catch(e) {}
|
|
652
|
-
|
|
653
|
-
// Swarm mode selection is available on-demand via /mastermind slash command.
|
|
654
|
-
} else {
|
|
655
|
-
console.log('[INFO] Router not available, using default routing');
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
// Task 22: TeamRoutingModes — only log when an explicit swarm config is present
|
|
659
|
-
try {
|
|
660
|
-
var swarmCfgPath = path.join(CWD, '.monomind', 'swarm-config.json');
|
|
661
|
-
if (fs.existsSync(swarmCfgPath)) {
|
|
662
|
-
var topology22 = JSON.parse(fs.readFileSync(swarmCfgPath, 'utf-8')).topology || 'mesh';
|
|
663
|
-
var mode22 = topology22 === 'hierarchical' ? 'route' : 'coordinate';
|
|
664
|
-
console.log('[ROUTING_MODE] topology=' + topology22 + ' → mode=' + mode22);
|
|
665
|
-
}
|
|
666
|
-
} catch (e) { /* non-fatal */ }
|
|
667
|
-
},
|
|
668
|
-
|
|
669
|
-
'load-agent': () => {
|
|
670
|
-
// Load and print full agent text so Claude can adopt its identity
|
|
671
|
-
const slug = args.join(' ').trim() || (typeof prompt === 'string' ? prompt.trim() : '');
|
|
672
|
-
if (!router || !router.loadExtrasAgent) {
|
|
673
|
-
console.error('[ERROR] Router does not support loadExtrasAgent');
|
|
674
|
-
process.exit(1);
|
|
675
|
-
}
|
|
676
|
-
const agent = router.loadExtrasAgent(slug);
|
|
677
|
-
if (!agent) {
|
|
678
|
-
console.error('[ERROR] Extras agent not found: ' + slug);
|
|
679
|
-
console.error('Run: node .claude/helpers/router.cjs --load-agent <slug> to check available slugs');
|
|
680
|
-
process.exit(1);
|
|
681
|
-
}
|
|
682
|
-
console.log('=== AGENT ACTIVATED: ' + agent.name + ' [' + agent.category + '] ===');
|
|
683
|
-
console.log('');
|
|
684
|
-
console.log(agent.content);
|
|
685
|
-
console.log('');
|
|
686
|
-
console.log('=== END AGENT: ' + agent.name + ' ===');
|
|
687
|
-
console.log('INSTRUCTION: You are now ' + agent.name + '. Adopt the identity, tone, and expertise described above for the remainder of this task.');
|
|
688
|
-
|
|
689
|
-
// Persist active agent for statusline
|
|
690
|
-
try {
|
|
691
|
-
var routeDir = path.join(CWD, '.monomind');
|
|
692
|
-
fs.mkdirSync(routeDir, { recursive: true });
|
|
693
|
-
fs.writeFileSync(
|
|
694
|
-
path.join(routeDir, 'last-route.json'),
|
|
695
|
-
JSON.stringify({
|
|
696
|
-
agent: agent.slug,
|
|
697
|
-
name: agent.name,
|
|
698
|
-
category: agent.category,
|
|
699
|
-
confidence: 1.0,
|
|
700
|
-
reason: 'manually activated via load-agent',
|
|
701
|
-
activated: true,
|
|
702
|
-
updatedAt: new Date().toISOString(),
|
|
703
|
-
}),
|
|
704
|
-
'utf-8'
|
|
705
|
-
);
|
|
706
|
-
} catch (e) { /* non-fatal */ }
|
|
707
|
-
},
|
|
708
|
-
|
|
709
|
-
'list-extras': () => {
|
|
710
|
-
if (!router || !router.loadExtrasRegistry) {
|
|
711
|
-
console.error('[ERROR] Extras registry not available');
|
|
712
|
-
process.exit(1);
|
|
713
|
-
}
|
|
714
|
-
const registry = router.loadExtrasRegistry();
|
|
715
|
-
const category = args[0] || '';
|
|
716
|
-
const entries = category
|
|
717
|
-
? registry.extras.filter(e => e.category === category)
|
|
718
|
-
: registry.extras;
|
|
719
|
-
const byCategory = {};
|
|
720
|
-
for (const e of entries) {
|
|
721
|
-
if (!byCategory[e.category]) byCategory[e.category] = [];
|
|
722
|
-
byCategory[e.category].push(e);
|
|
723
|
-
}
|
|
724
|
-
for (const [cat, agents] of Object.entries(byCategory)) {
|
|
725
|
-
console.log('\n[' + cat.toUpperCase() + ']');
|
|
726
|
-
for (const a of agents) {
|
|
727
|
-
console.log(' ' + a.slug.padEnd(45) + a.name);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
console.log('\nTotal: ' + entries.length + ' extras agents');
|
|
731
|
-
},
|
|
732
|
-
|
|
733
|
-
'pre-bash': () => {
|
|
734
|
-
var _rawCmd = hookInput.command || prompt;
|
|
735
|
-
var cmd = (typeof _rawCmd === 'string' ? _rawCmd : String(_rawCmd || '')).toLowerCase();
|
|
736
|
-
var dangerous = ['rm -rf /', 'rm -rf/', 'format c:', 'del /s /q c:\\', ':(){:|:&};:'];
|
|
737
|
-
for (var i = 0; i < dangerous.length; i++) {
|
|
738
|
-
if (cmd.includes(dangerous[i])) {
|
|
739
|
-
console.error('[BLOCKED] Dangerous command detected: ' + dangerous[i]);
|
|
740
|
-
process.exit(1);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
console.log('[OK] Command validated');
|
|
744
|
-
},
|
|
745
|
-
|
|
746
|
-
'post-edit': async () => {
|
|
747
|
-
if (session && session.metric) {
|
|
748
|
-
try { session.metric('edits'); } catch (e) { /* no active session */ }
|
|
749
|
-
}
|
|
750
|
-
if (intelligence && intelligence.recordEdit) {
|
|
751
|
-
try {
|
|
752
|
-
var file = hookInput.file_path || toolInput.file_path
|
|
753
|
-
|| process.env.TOOL_INPUT_file_path || args[0] || '';
|
|
754
|
-
intelligence.recordEdit(file);
|
|
755
|
-
} catch (e) { /* non-fatal */ }
|
|
756
|
-
}
|
|
757
|
-
// ── Security-Sensitive File Auto-Alert ────────────────────────────────
|
|
758
|
-
// When editing auth, security, crypto, or env-related files, flag it
|
|
759
|
-
try {
|
|
760
|
-
var editFile = (hookInput.file_path || toolInput.file_path
|
|
761
|
-
|| process.env.TOOL_INPUT_file_path || args[0] || '').toLowerCase();
|
|
762
|
-
var securityPatterns = /\b(auth|security|crypto|secret|credential|token|password|\.env|permission|acl|rbac|jwt|oauth|session|cookie)\b/;
|
|
763
|
-
if (securityPatterns.test(editFile) || editFile.includes('/security/') || editFile.includes('/auth/')) {
|
|
764
|
-
console.log('[SECURITY_EDIT] Security-sensitive file modified: ' + path.basename(editFile));
|
|
765
|
-
console.log('[SECURITY_EDIT] INSTRUCTION: Consider running a security review. Invoke Skill("code-review:code-review") with security focus, or run: npx monomind security scan --path "' + editFile + '"');
|
|
766
|
-
}
|
|
767
|
-
} catch (e) { /* non-fatal */ }
|
|
768
|
-
|
|
769
|
-
// ── Smart Test/Build Suggestions (PE-001) ───────────────────────────
|
|
770
|
-
try {
|
|
771
|
-
var editFile = (hookInput.file_path || toolInput.file_path
|
|
772
|
-
|| process.env.TOOL_INPUT_file_path || args[0] || '');
|
|
773
|
-
var editBase = path.basename(editFile).toLowerCase();
|
|
774
|
-
var editDir = path.dirname(editFile);
|
|
775
|
-
if (/\.(test|spec)\.(ts|js|tsx|jsx)$/.test(editBase)) {
|
|
776
|
-
console.log('[AUTO_SUGGEST] Test file modified — run: npm test -- --testPathPattern="' + path.basename(editFile) + '"');
|
|
777
|
-
} else if (editBase === 'package.json') {
|
|
778
|
-
console.log('[AUTO_SUGGEST] package.json changed — consider running: npm install');
|
|
779
|
-
} else if (editBase === 'tsconfig.json' || editBase === 'tsconfig.base.json') {
|
|
780
|
-
console.log('[AUTO_SUGGEST] TypeScript config changed — consider running: npm run build');
|
|
781
|
-
}
|
|
782
|
-
} catch (e) { /* non-fatal */ }
|
|
783
|
-
|
|
784
|
-
// ── Monograph Incremental Rebuild ─────────────────────────────────────
|
|
785
|
-
// After every code file edit, trigger a background monograph rebuild so
|
|
786
|
-
// the knowledge graph stays current. Debounced via a lock file (5s cooldown).
|
|
787
|
-
try {
|
|
788
|
-
var editedFile = (hookInput.file_path || toolInput.file_path
|
|
789
|
-
|| process.env.TOOL_INPUT_file_path || args[0] || '');
|
|
790
|
-
var codeExts = /\.(ts|tsx|js|jsx|mjs|cjs|py|go|rs|java|kt|cs|cpp|c|rb|swift|php)$/i;
|
|
791
|
-
if (editedFile && codeExts.test(editedFile)) {
|
|
792
|
-
var lockFile = path.join(CWD, '.monomind', 'graph', '.rebuild-lock');
|
|
793
|
-
var now = Date.now();
|
|
794
|
-
var lastBuild = 0;
|
|
795
|
-
try { lastBuild = parseInt(fs.readFileSync(lockFile, 'utf-8').trim(), 10) || 0; } catch (e) {}
|
|
796
|
-
var COOLDOWN_MS = 5000; // 5-second debounce
|
|
797
|
-
if (now - lastBuild > COOLDOWN_MS) {
|
|
798
|
-
fs.writeFileSync(lockFile, String(now), 'utf-8');
|
|
799
|
-
var { spawn: spawnRebuild } = require('child_process');
|
|
800
|
-
var rebuildScript = "import { buildAsync } from '@monoes/monograph'; await buildAsync(" + JSON.stringify(CWD) + ");";
|
|
801
|
-
var graphDir = path.join(CWD, '.monomind', 'graph');
|
|
802
|
-
var logPath = path.join(graphDir, 'build.log');
|
|
803
|
-
var logFd;
|
|
804
|
-
try { logFd = fs.openSync(logPath, 'a'); } catch(e) { logFd = 'ignore'; }
|
|
805
|
-
var child = spawnRebuild(process.execPath, ['--input-type=module', '--eval', rebuildScript], {
|
|
806
|
-
detached: true, stdio: ['ignore', logFd, logFd], cwd: CWD,
|
|
807
|
-
});
|
|
808
|
-
child.unref();
|
|
809
|
-
console.log('[MONOGRAPH] Incremental rebuild triggered for ' + path.basename(editedFile));
|
|
810
|
-
|
|
811
|
-
// Option C: fire ua-enrich.mjs in background after monograph rebuild
|
|
812
|
-
var uaEnrichScript = path.join(CWD, 'scripts', 'ua-enrich.mjs');
|
|
813
|
-
if (fs.existsSync(uaEnrichScript)) {
|
|
814
|
-
var uaChild = spawnRebuild(process.execPath, [uaEnrichScript, '--dir', CWD, '--file', editedFile, '--db', path.join(CWD, '.monomind', 'monograph.db')], {
|
|
815
|
-
detached: true, stdio: 'ignore', cwd: CWD,
|
|
816
|
-
});
|
|
817
|
-
uaChild.unref();
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
// Show importers of the edited file so Claude sees blast radius
|
|
821
|
-
try {
|
|
822
|
-
var mgDbPath4 = path.join(CWD, '.monomind', 'monograph.db');
|
|
823
|
-
if (fs.existsSync(mgDbPath4)) {
|
|
824
|
-
var mgMod4 = null;
|
|
825
|
-
mgMod4 = _requireMonograph();
|
|
826
|
-
if (mgMod4 && mgMod4.openDb) {
|
|
827
|
-
var db4 = mgMod4.openDb(mgDbPath4);
|
|
828
|
-
try {
|
|
829
|
-
var editedBase4 = path.basename(editedFile).replace(/\.[^.]+$/, '');
|
|
830
|
-
var editNode4 = db4.prepare("SELECT id, name, label FROM nodes WHERE file_path LIKE ? OR name = ? LIMIT 1")
|
|
831
|
-
.get('%' + path.sep + path.basename(editedFile), editedBase4);
|
|
832
|
-
if (editNode4) {
|
|
833
|
-
var editImporters4 = db4.prepare(
|
|
834
|
-
'SELECT n2.name FROM edges e JOIN nodes n2 ON n2.id = e.source_id WHERE e.target_id = ? LIMIT 8'
|
|
835
|
-
).all(editNode4.id);
|
|
836
|
-
if (editImporters4.length > 0) {
|
|
837
|
-
console.log('[MONOGRAPH_IMPACT] ' + editNode4.name + ' (' + editNode4.label + ') is depended on by: ' +
|
|
838
|
-
editImporters4.map(function(i) { return i.name; }).join(', '));
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
} finally { if (mgMod4.closeDb) mgMod4.closeDb(db4); }
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
} catch(e) { /* non-fatal */ }
|
|
845
|
-
}
|
|
846
|
-
} catch (e) { /* non-fatal */ }
|
|
847
|
-
|
|
848
|
-
console.log('[OK] Edit recorded');
|
|
849
|
-
},
|
|
850
|
-
|
|
851
|
-
'session-restore': async () => {
|
|
852
|
-
try {
|
|
853
|
-
if (session) {
|
|
854
|
-
var existing = session.restore && session.restore();
|
|
855
|
-
if (!existing) {
|
|
856
|
-
session.start && session.start();
|
|
857
|
-
}
|
|
858
|
-
} else {
|
|
859
|
-
console.log('[OK] Session restored: session-' + Date.now());
|
|
860
|
-
}
|
|
861
|
-
} catch (e) { console.log('[WARN] Session restore failed: ' + e.message); }
|
|
862
|
-
// Initialize intelligence (with timeout — #1530)
|
|
863
|
-
// Respects monomind.neural.enabled kill switch from settings.json
|
|
864
|
-
var neuralEnabled = true;
|
|
865
|
-
try {
|
|
866
|
-
var settingsPath = path.join(CWD, '.claude', 'settings.json');
|
|
867
|
-
if (fs.existsSync(settingsPath)) {
|
|
868
|
-
var settingsData = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
869
|
-
if (settingsData.monomind && settingsData.monomind.neural && settingsData.monomind.neural.enabled === false) {
|
|
870
|
-
neuralEnabled = false;
|
|
871
|
-
console.log('[NEURAL] Disabled via monomind.neural.enabled=false');
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
} catch (e) { /* non-fatal */ }
|
|
875
|
-
if (neuralEnabled && intelligence && intelligence.init) {
|
|
876
|
-
var initResult = await runWithTimeout(function() { return intelligence.init(); }, 'intelligence.init()');
|
|
877
|
-
if (initResult && initResult.nodes > 0) {
|
|
878
|
-
console.log('[INTELLIGENCE] Loaded ' + initResult.nodes + ' patterns, ' + initResult.edges + ' edges');
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
// GAP-001: Bridge hook-handler.cjs to @monomind/hooks compiled packages.
|
|
882
|
-
// Dynamic import() resolves ESM packages even from CJS — failures are silent.
|
|
883
|
-
try {
|
|
884
|
-
var hooksModule = await import('@monomind/hooks');
|
|
885
|
-
if (hooksModule && hooksModule.initDefaultWorkers) {
|
|
886
|
-
await runWithTimeout(function() { return hooksModule.initDefaultWorkers(); }, '@monomind/hooks.initDefaultWorkers()');
|
|
887
|
-
// Store reference so pre-task / post-task can call executeHooks (Tasks 26, 39)
|
|
888
|
-
_hooksModule = hooksModule;
|
|
889
|
-
console.log('[INFO] @monomind/hooks workers initialized');
|
|
890
|
-
}
|
|
891
|
-
} catch (e) { /* @monomind/hooks not compiled yet — skip */ }
|
|
892
|
-
|
|
893
|
-
// ── Context Persistence Auto-Restore ───────────────────────────────────
|
|
894
|
-
// Restore archived conversation context from previous sessions
|
|
895
|
-
try {
|
|
896
|
-
var cpHook = await import('file://' + path.join(__dirname, 'context-persistence-hook.mjs'));
|
|
897
|
-
var restoreFn = (cpHook && cpHook.restore) || (cpHook && cpHook.default && cpHook.default.restore);
|
|
898
|
-
if (restoreFn) {
|
|
899
|
-
var restored = await runWithTimeout(function() { return restoreFn(); }, 'context-persistence.restore()');
|
|
900
|
-
if (restored && restored.turns > 0) {
|
|
901
|
-
console.log('[CONTEXT_RESTORED] ' + restored.turns + ' turns from previous session');
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
} catch (e) { /* non-fatal — context-persistence may not be available */ }
|
|
905
|
-
|
|
906
|
-
// Task 28: AgentKnowledgeBase — preload shared knowledge context on session restore.
|
|
907
|
-
// Self-contained: auto-indexes project docs into chunks.jsonl, then keyword-searches
|
|
908
|
-
// them. Works without @monomind/memory being compiled. Falls back to KnowledgeRetriever
|
|
909
|
-
// if the compiled package IS available (richer dedup + formatting).
|
|
910
|
-
try {
|
|
911
|
-
var knowledgeDir = path.join(CWD, '.monomind', 'knowledge');
|
|
912
|
-
var indexed = _autoIndexKnowledge(knowledgeDir);
|
|
913
|
-
if (indexed > 0) {
|
|
914
|
-
console.log('[KNOWLEDGE_INDEXED] ' + indexed + ' chunks written from project sources');
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
var kSearchFn = _buildKnowledgeSearchFn(knowledgeDir);
|
|
918
|
-
var sessionCtx = (hookInput && (hookInput.sessionId || hookInput.session_id))
|
|
919
|
-
? 'session context: ' + (hookInput.sessionId || hookInput.session_id)
|
|
920
|
-
: 'project context general';
|
|
921
|
-
|
|
922
|
-
// Prefer compiled KnowledgeRetriever for dedup + formatting; inline fallback otherwise
|
|
923
|
-
var memoryMod = null;
|
|
924
|
-
try { memoryMod = await import('@monomind/memory'); } catch (e) {}
|
|
925
|
-
|
|
926
|
-
if (memoryMod && memoryMod.KnowledgeStore && memoryMod.KnowledgeRetriever) {
|
|
927
|
-
var kStore = new memoryMod.KnowledgeStore(knowledgeDir);
|
|
928
|
-
var kRetriever = new memoryMod.KnowledgeRetriever(kSearchFn, kStore);
|
|
929
|
-
var kResult = await kRetriever.retrieveForTask('shared', sessionCtx, 5);
|
|
930
|
-
if (kResult.excerpts.length > 0) {
|
|
931
|
-
console.log('[KNOWLEDGE_PRELOADED] ' + kResult.excerpts.length + ' excerpts (KnowledgeRetriever)');
|
|
932
|
-
}
|
|
933
|
-
} else {
|
|
934
|
-
// Inline fallback — no compiled deps needed
|
|
935
|
-
var directResults = await kSearchFn(sessionCtx, { namespace: 'knowledge:shared', limit: 5, minScore: 0.3 });
|
|
936
|
-
if (directResults.length > 0) {
|
|
937
|
-
console.log('[KNOWLEDGE_PRELOADED] ' + directResults.length + ' excerpts (direct keyword search)');
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
} catch (e) { /* non-fatal */ }
|
|
941
|
-
|
|
942
|
-
// ── Monograph Context Injection ──────────────────────────────────────────
|
|
943
|
-
// On session start, query monograph DB for god nodes, inject as context,
|
|
944
|
-
// and write them into knowledge/chunks.jsonl for semantic search recall.
|
|
945
|
-
try {
|
|
946
|
-
var mgDbPath = path.join(CWD, '.monomind', 'monograph.db');
|
|
947
|
-
if (fs.existsSync(mgDbPath)) {
|
|
948
|
-
var mgMod = null;
|
|
949
|
-
mgMod = _requireMonograph();
|
|
950
|
-
if (mgMod && mgMod.openDb) {
|
|
951
|
-
var mgDb = mgMod.openDb(mgDbPath);
|
|
952
|
-
try {
|
|
953
|
-
var mgNodeCount = mgDb.prepare('SELECT COUNT(*) AS c FROM nodes').get().c;
|
|
954
|
-
var mgEdgeCount = mgDb.prepare('SELECT COUNT(*) AS c FROM edges').get().c;
|
|
955
|
-
var mgGodNodes = mgDb.prepare(
|
|
956
|
-
'SELECT n.name, n.label, n.file_path, ' +
|
|
957
|
-
'(SELECT COUNT(*) FROM edges WHERE source_id=n.id OR target_id=n.id) AS deg ' +
|
|
958
|
-
'FROM nodes n ORDER BY deg DESC LIMIT 12'
|
|
959
|
-
).all();
|
|
960
|
-
if (mgGodNodes.length > 0) {
|
|
961
|
-
var mgGodStr = mgGodNodes.slice(0, 8).map(function(n) {
|
|
962
|
-
return n.name + ' (' + n.label + ', ' + n.deg + ' links)';
|
|
963
|
-
}).join(', ');
|
|
964
|
-
console.log('[MONOGRAPH_CONTEXT] ' + mgNodeCount + ' nodes · ' + mgEdgeCount + ' edges. Key nodes: ' + mgGodStr);
|
|
965
|
-
// Write god nodes into knowledge chunks so semantic search finds them
|
|
966
|
-
var mgKnowledgeDir = path.join(CWD, '.monomind', 'knowledge');
|
|
967
|
-
var mgChunksFile = path.join(mgKnowledgeDir, 'chunks.jsonl');
|
|
968
|
-
try {
|
|
969
|
-
fs.mkdirSync(mgKnowledgeDir, { recursive: true });
|
|
970
|
-
var mgGodChunk = JSON.stringify({
|
|
971
|
-
id: 'monograph-god-nodes',
|
|
972
|
-
text: 'Codebase architecture — high-centrality nodes (most depended-on): ' + mgGodNodes.map(function(n) {
|
|
973
|
-
return n.name + ' [' + n.label + '] at ' + (n.file_path || '') + ' (' + n.deg + ' connections)';
|
|
974
|
-
}).join('; '),
|
|
975
|
-
namespace: 'knowledge:monograph',
|
|
976
|
-
metadata: { label: 'monograph-god-nodes', nodes: mgNodeCount, edges: mgEdgeCount }
|
|
977
|
-
});
|
|
978
|
-
var mgExisting = [];
|
|
979
|
-
try { mgExisting = fs.readFileSync(mgChunksFile, 'utf-8').trim().split('\n').filter(Boolean); } catch(e) {}
|
|
980
|
-
mgExisting = mgExisting.filter(function(line) {
|
|
981
|
-
try { return JSON.parse(line).id !== 'monograph-god-nodes'; } catch(e) { return true; }
|
|
982
|
-
});
|
|
983
|
-
mgExisting.push(mgGodChunk);
|
|
984
|
-
fs.writeFileSync(mgChunksFile, mgExisting.join('\n') + '\n');
|
|
985
|
-
} catch(e) {}
|
|
986
|
-
}
|
|
987
|
-
} finally { if (mgMod.closeDb) mgMod.closeDb(mgDb); }
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
} catch(e) { /* non-fatal */ }
|
|
991
|
-
|
|
992
|
-
// Task 23: SharedInstructions — auto-load .agents/shared_instructions.md on session restore
|
|
993
|
-
// Hard limit: 1500 chars (~375 tokens). Content beyond this is truncated and flagged.
|
|
994
|
-
var SI_CHAR_LIMIT = 1500;
|
|
995
|
-
var applySharedInstrLimit = function(content, source) {
|
|
996
|
-
if (content.length > SI_CHAR_LIMIT) {
|
|
997
|
-
console.warn('[SHARED_INSTRUCTIONS_OVERLIMIT] ' + content.length + ' chars exceeds limit of ' + SI_CHAR_LIMIT +
|
|
998
|
-
' — truncating. Edit ' + source + ' to stay under limit.');
|
|
999
|
-
return content.slice(0, SI_CHAR_LIMIT) + '\n… [truncated — file exceeds ' + SI_CHAR_LIMIT + ' char limit]';
|
|
1000
|
-
}
|
|
1001
|
-
return content;
|
|
1002
|
-
};
|
|
1003
|
-
try {
|
|
1004
|
-
var siMod = await import('file://' + path.join(CWD, 'packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js'));
|
|
1005
|
-
var loader = siMod.sharedInstructionsLoader || (siMod.SharedInstructionsLoader ? new siMod.SharedInstructionsLoader() : null);
|
|
1006
|
-
if (loader) {
|
|
1007
|
-
var sharedInstr = loader.getSharedInstructions(CWD);
|
|
1008
|
-
if (sharedInstr) {
|
|
1009
|
-
var sharedInstrSafe = applySharedInstrLimit(sharedInstr, '.agents/shared_instructions.md');
|
|
1010
|
-
console.log('[SHARED_INSTRUCTIONS] Loaded ' + sharedInstrSafe.length + ' chars from .agents/shared_instructions.md');
|
|
1011
|
-
console.log(sharedInstrSafe);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
} catch (e) {
|
|
1015
|
-
// Try direct filesystem fallback
|
|
1016
|
-
try {
|
|
1017
|
-
var siPath = path.join(CWD, '.agents', 'shared_instructions.md');
|
|
1018
|
-
if (fs.existsSync(siPath)) {
|
|
1019
|
-
var siContent = fs.readFileSync(siPath, 'utf-8');
|
|
1020
|
-
var siContentSafe = applySharedInstrLimit(siContent, siPath);
|
|
1021
|
-
console.log('[SHARED_INSTRUCTIONS] Loaded ' + siContentSafe.length + ' chars from .agents/shared_instructions.md');
|
|
1022
|
-
console.log(siContentSafe);
|
|
1023
|
-
}
|
|
1024
|
-
} catch (e2) { /* non-fatal */ }
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
// Memory Palace — inject L0 (identity) + L1 (essential story) into session context
|
|
1028
|
-
try {
|
|
1029
|
-
var palace = require('./memory-palace.cjs');
|
|
1030
|
-
var palaceContext = palace.wakeUp(CWD);
|
|
1031
|
-
if (palaceContext) {
|
|
1032
|
-
console.log(palaceContext);
|
|
1033
|
-
}
|
|
1034
|
-
} catch (e) { /* non-fatal — palace not available */ }
|
|
1035
|
-
|
|
1036
|
-
// ── Periodic Update Check (once per day) ──────────────────────────────
|
|
1037
|
-
try {
|
|
1038
|
-
var updateCheckFile = path.join(CWD, '.monomind', 'last-update-check.json');
|
|
1039
|
-
var shouldCheck = true;
|
|
1040
|
-
if (fs.existsSync(updateCheckFile)) {
|
|
1041
|
-
var lastCheck = JSON.parse(fs.readFileSync(updateCheckFile, 'utf-8'));
|
|
1042
|
-
var hoursSince = (Date.now() - new Date(lastCheck.timestamp).getTime()) / (1000 * 60 * 60);
|
|
1043
|
-
if (hoursSince < 24) shouldCheck = false;
|
|
1044
|
-
}
|
|
1045
|
-
if (shouldCheck) {
|
|
1046
|
-
// Non-blocking: write marker immediately, check asynchronously
|
|
1047
|
-
fs.mkdirSync(path.join(CWD, '.monomind'), { recursive: true });
|
|
1048
|
-
fs.writeFileSync(updateCheckFile, JSON.stringify({ timestamp: new Date().toISOString() }), 'utf-8');
|
|
1049
|
-
try {
|
|
1050
|
-
var localPkg = path.join(CWD, 'packages/@monomind/cli/package.json');
|
|
1051
|
-
if (fs.existsSync(localPkg)) {
|
|
1052
|
-
var localVer = JSON.parse(fs.readFileSync(localPkg, 'utf-8')).version;
|
|
1053
|
-
if (localVer) {
|
|
1054
|
-
// Non-blocking spawn — never holds the event loop during hook execution
|
|
1055
|
-
var spawnFn = require('child_process').spawn;
|
|
1056
|
-
var child = spawnFn('npm', ['view', '@monomind/cli', 'version'], {
|
|
1057
|
-
stdio: ['ignore', 'pipe', 'ignore'],
|
|
1058
|
-
shell: false,
|
|
1059
|
-
});
|
|
1060
|
-
// Required: without an error listener, ENOENT (npm not in PATH) crashes the process
|
|
1061
|
-
child.on('error', function() {});
|
|
1062
|
-
var out = '';
|
|
1063
|
-
child.stdout.on('data', function(d) { out += d; });
|
|
1064
|
-
child.on('close', function() {
|
|
1065
|
-
var current = out.trim();
|
|
1066
|
-
var pendingUpdatePath = path.join(CWD, '.monomind', 'pending-update.json');
|
|
1067
|
-
if (current && current !== localVer) {
|
|
1068
|
-
// Write result to a sidecar file — picked up on next session-start
|
|
1069
|
-
try {
|
|
1070
|
-
fs.writeFileSync(
|
|
1071
|
-
pendingUpdatePath,
|
|
1072
|
-
JSON.stringify({ from: localVer, to: current, checkedAt: new Date().toISOString() }),
|
|
1073
|
-
'utf-8'
|
|
1074
|
-
);
|
|
1075
|
-
} catch (e2) {}
|
|
1076
|
-
} else if (current) {
|
|
1077
|
-
// Versions match — clear any stale notification so it doesn't show forever
|
|
1078
|
-
try { fs.unlinkSync(pendingUpdatePath); } catch (e2) {}
|
|
1079
|
-
}
|
|
1080
|
-
});
|
|
1081
|
-
child.unref();
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
} catch (e) { /* npm not available — skip silently */ }
|
|
1085
|
-
}
|
|
1086
|
-
// Surface any previously-detected update on every session restore (not just on check day)
|
|
1087
|
-
try {
|
|
1088
|
-
var pendingUpdate = path.join(CWD, '.monomind', 'pending-update.json');
|
|
1089
|
-
if (fs.existsSync(pendingUpdate)) {
|
|
1090
|
-
var upd = JSON.parse(fs.readFileSync(pendingUpdate, 'utf-8'));
|
|
1091
|
-
if (upd && upd.from && upd.to && upd.from !== upd.to) {
|
|
1092
|
-
console.log('[UPDATE_AVAILABLE] @monomind/cli ' + upd.from + ' → ' + upd.to + ' (run: npx monomind update)');
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
} catch (e) {}
|
|
1096
|
-
} catch (e) { /* non-fatal */ }
|
|
1097
|
-
|
|
1098
|
-
// ── Daemon Auto-Start Check ────────────────────────────────────────────
|
|
1099
|
-
// If daemon is not running, suggest starting it (or auto-start if config says so)
|
|
1100
|
-
try {
|
|
1101
|
-
var daemonPid = path.join(CWD, '.monomind', 'daemon.pid');
|
|
1102
|
-
var daemonRunning = false;
|
|
1103
|
-
if (fs.existsSync(daemonPid)) {
|
|
1104
|
-
try {
|
|
1105
|
-
var pid = parseInt(fs.readFileSync(daemonPid, 'utf-8').trim(), 10);
|
|
1106
|
-
process.kill(pid, 0); // throws if process doesn't exist
|
|
1107
|
-
daemonRunning = true;
|
|
1108
|
-
} catch (e) { /* pid stale */ }
|
|
1109
|
-
}
|
|
1110
|
-
if (!daemonRunning) {
|
|
1111
|
-
// Check config for autoStart preference
|
|
1112
|
-
var daemonCfg = {};
|
|
1113
|
-
try {
|
|
1114
|
-
var cfgPath = path.join(CWD, 'monomind.config.json');
|
|
1115
|
-
if (fs.existsSync(cfgPath)) daemonCfg = JSON.parse(fs.readFileSync(cfgPath, 'utf-8')).daemon || {};
|
|
1116
|
-
} catch (e) {}
|
|
1117
|
-
if (daemonCfg.autoStart) {
|
|
1118
|
-
// Auto-start daemon in background
|
|
1119
|
-
var spawn = require('child_process').spawn;
|
|
1120
|
-
var child = spawn('npx', ['monomind', 'daemon', 'start'], {
|
|
1121
|
-
cwd: CWD, detached: true, stdio: 'ignore'
|
|
1122
|
-
});
|
|
1123
|
-
child.on('error', function() {});
|
|
1124
|
-
child.unref();
|
|
1125
|
-
console.log('[DAEMON_AUTOSTART] Background daemon started (pid ' + child.pid + ')');
|
|
1126
|
-
} else {
|
|
1127
|
-
console.log('[DAEMON_STOPPED] Background daemon is not running. To auto-start, set daemon.autoStart=true in monomind.config.json or run: npx monomind daemon start');
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
} catch (e) { /* non-fatal */ }
|
|
1131
|
-
|
|
1132
|
-
// Token Usage — inject daily/monthly cost summary from JSONL session logs
|
|
1133
|
-
try {
|
|
1134
|
-
var tokenTracker = require('./token-tracker.cjs');
|
|
1135
|
-
var tokenSummary = tokenTracker.quickSummary();
|
|
1136
|
-
if (tokenSummary) {
|
|
1137
|
-
console.log(tokenSummary);
|
|
1138
|
-
}
|
|
1139
|
-
// Write structured cache for statusline (best-effort, non-blocking)
|
|
1140
|
-
try {
|
|
1141
|
-
var tokenData = tokenTracker.quickSummaryData();
|
|
1142
|
-
if (tokenData) {
|
|
1143
|
-
var metricsDir = path.join(CWD, '.monomind', 'metrics');
|
|
1144
|
-
if (!fs.existsSync(metricsDir)) fs.mkdirSync(metricsDir, { recursive: true });
|
|
1145
|
-
tokenData.cachedAt = new Date().toISOString();
|
|
1146
|
-
fs.writeFileSync(path.join(metricsDir, 'token-summary.json'), JSON.stringify(tokenData), 'utf-8');
|
|
1147
|
-
}
|
|
1148
|
-
} catch (_) { /* ignore cache write failure */ }
|
|
1149
|
-
} catch (e) { /* non-fatal — token tracker not available */ }
|
|
1150
|
-
|
|
1151
|
-
// ── Registry Surfacing (SR-001) ─────────────────────────────────────
|
|
1152
|
-
// Show agent registry summary so users know what's available
|
|
1153
|
-
try {
|
|
1154
|
-
var regPath = path.join(CWD, '.monomind', 'registry.json');
|
|
1155
|
-
if (fs.existsSync(regPath)) {
|
|
1156
|
-
var reg = JSON.parse(fs.readFileSync(regPath, 'utf-8'));
|
|
1157
|
-
var agentCount = (reg.agents || []).length;
|
|
1158
|
-
if (agentCount > 0) {
|
|
1159
|
-
console.log('[REGISTRY] ' + agentCount + ' agents available in registry');
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
} catch (e) { /* non-fatal */ }
|
|
1163
|
-
|
|
1164
|
-
// ── Monomind Control UI Status ────────────────────────────────────────
|
|
1165
|
-
try {
|
|
1166
|
-
var http = require('http');
|
|
1167
|
-
var controlPort = 4242;
|
|
1168
|
-
var req = http.get('http://localhost:' + controlPort + '/', function(res) {
|
|
1169
|
-
if (res.statusCode === 200) {
|
|
1170
|
-
console.log('[CONTROL_UI] UP — http://localhost:' + controlPort);
|
|
1171
|
-
}
|
|
1172
|
-
res.resume();
|
|
1173
|
-
});
|
|
1174
|
-
req.on('error', function() {
|
|
1175
|
-
console.log('[CONTROL_UI] offline — run: npx monomind mcp start');
|
|
1176
|
-
});
|
|
1177
|
-
req.setTimeout(800, function() { req.destroy(); });
|
|
1178
|
-
} catch (e) { /* non-fatal */ }
|
|
1179
|
-
|
|
1180
|
-
// ── Worker Queue Resume (SR-003) ────────────────────────────────────
|
|
1181
|
-
try {
|
|
1182
|
-
var dispatchDir = path.join(CWD, '.monomind', 'worker-dispatch');
|
|
1183
|
-
if (fs.existsSync(dispatchDir)) {
|
|
1184
|
-
var pendingFiles = fs.readdirSync(dispatchDir).filter(function(f) { return f.startsWith('pending-'); });
|
|
1185
|
-
if (pendingFiles.length > 0) {
|
|
1186
|
-
console.log('[WORKER_RESUME] ' + pendingFiles.length + ' worker dispatch(es) pending from prior session');
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
} catch (e) { /* non-fatal */ }
|
|
1190
|
-
},
|
|
1191
|
-
|
|
1192
|
-
'session-end': async () => {
|
|
1193
|
-
// Consolidate intelligence (with timeout — #1530)
|
|
1194
|
-
if (intelligence && intelligence.consolidate) {
|
|
1195
|
-
var consResult = await runWithTimeout(function() { return intelligence.consolidate(); }, 'intelligence.consolidate()');
|
|
1196
|
-
if (consResult && consResult.entries > 0) {
|
|
1197
|
-
var msg = '[INTELLIGENCE] Consolidated: ' + consResult.entries + ' entries, ' + consResult.edges + ' edges';
|
|
1198
|
-
if (consResult.newEntries > 0) msg += ', ' + consResult.newEntries + ' new';
|
|
1199
|
-
msg += ', PageRank recomputed';
|
|
1200
|
-
console.log(msg);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
try {
|
|
1204
|
-
if (session && session.end) {
|
|
1205
|
-
session.end();
|
|
1206
|
-
} else {
|
|
1207
|
-
console.log('[OK] Session ended');
|
|
1208
|
-
}
|
|
1209
|
-
} catch (e) { console.log('[WARN] Session end failed: ' + e.message); }
|
|
1210
|
-
|
|
1211
|
-
// ── Routing Feedback Loop (SE-001) ────────────────────────────────────
|
|
1212
|
-
// Persist routing accuracy feedback so the router improves over sessions
|
|
1213
|
-
try {
|
|
1214
|
-
var feedbackPath = path.join(CWD, '.monomind', 'routing-feedback.jsonl');
|
|
1215
|
-
var lastRoutePath = path.join(CWD, '.monomind', 'last-route.json');
|
|
1216
|
-
if (fs.existsSync(lastRoutePath)) {
|
|
1217
|
-
var lastRoute = JSON.parse(fs.readFileSync(lastRoutePath, 'utf-8'));
|
|
1218
|
-
var feedbackEntry = {
|
|
1219
|
-
timestamp: new Date().toISOString(),
|
|
1220
|
-
suggestedAgent: lastRoute.agent,
|
|
1221
|
-
confidence: lastRoute.confidence,
|
|
1222
|
-
sessionId: hookInput.sessionId || hookInput.session_id || '',
|
|
1223
|
-
// If intelligence gave feedback during session, it's recorded here
|
|
1224
|
-
intelligenceFeedback: (intelligence && intelligence.getSessionStats) ? intelligence.getSessionStats() : null,
|
|
1225
|
-
};
|
|
1226
|
-
fs.appendFileSync(feedbackPath, JSON.stringify(feedbackEntry) + '\n', 'utf-8');
|
|
1227
|
-
// Rotate: keep last 1000 lines to prevent unbounded growth
|
|
1228
|
-
try {
|
|
1229
|
-
var raw = fs.readFileSync(feedbackPath, 'utf-8');
|
|
1230
|
-
var lines = raw.split('\n').filter(Boolean);
|
|
1231
|
-
if (lines.length > 1000) {
|
|
1232
|
-
fs.writeFileSync(feedbackPath, lines.slice(-1000).join('\n') + '\n', 'utf-8');
|
|
1233
|
-
}
|
|
1234
|
-
} catch (e2) { /* rotation is best-effort */ }
|
|
1235
|
-
}
|
|
1236
|
-
} catch (e) { /* non-fatal */ }
|
|
1237
|
-
|
|
1238
|
-
// Memory Palace tombstone writes removed — redundant with raw session JSONL
|
|
1239
|
-
|
|
1240
|
-
// ── Learning Service Auto-Consolidation ─────────────────────────────
|
|
1241
|
-
// Consolidate learned patterns from short-term to long-term storage
|
|
1242
|
-
try {
|
|
1243
|
-
var learningService = await import('file://' + path.join(__dirname, 'learning-service.mjs'));
|
|
1244
|
-
if (learningService && learningService.consolidate) {
|
|
1245
|
-
var lResult = await runWithTimeout(function() { return learningService.consolidate(); }, 'learning.consolidate()');
|
|
1246
|
-
if (lResult && lResult.promoted > 0) {
|
|
1247
|
-
console.log('[LEARNING] Consolidated: ' + lResult.promoted + ' patterns promoted to long-term');
|
|
1248
|
-
}
|
|
1249
|
-
} else if (learningService && learningService.default && learningService.default.consolidate) {
|
|
1250
|
-
var lResult2 = await runWithTimeout(function() { return learningService.default.consolidate(); }, 'learning.consolidate()');
|
|
1251
|
-
if (lResult2 && lResult2.promoted > 0) {
|
|
1252
|
-
console.log('[LEARNING] Consolidated: ' + lResult2.promoted + ' patterns promoted to long-term');
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
} catch (e) { /* non-fatal — learning-service may need better-sqlite3 */ }
|
|
1256
|
-
|
|
1257
|
-
// ── Context Persistence Auto-Archive ─────────────────────────────────
|
|
1258
|
-
// Archive conversation context so it survives compaction and new sessions
|
|
1259
|
-
try {
|
|
1260
|
-
var cpHook = await import('file://' + path.join(__dirname, 'context-persistence-hook.mjs'));
|
|
1261
|
-
if (cpHook && cpHook.archive) {
|
|
1262
|
-
await runWithTimeout(function() { return cpHook.archive(); }, 'context-persistence.archive()');
|
|
1263
|
-
console.log('[CONTEXT_PERSIST] Session transcript archived');
|
|
1264
|
-
} else if (cpHook && cpHook.default && cpHook.default.archive) {
|
|
1265
|
-
await runWithTimeout(function() { return cpHook.default.archive(); }, 'context-persistence.archive()');
|
|
1266
|
-
console.log('[CONTEXT_PERSIST] Session transcript archived');
|
|
1267
|
-
}
|
|
1268
|
-
} catch (e) { /* non-fatal — context-persistence may not export archive() */ }
|
|
1269
|
-
|
|
1270
|
-
// ── Worker Queue Cleanup ─────────────────────────────────────────────
|
|
1271
|
-
// Process and clean up any pending worker dispatch files
|
|
1272
|
-
try {
|
|
1273
|
-
var dispatchDir = path.join(CWD, '.monomind', 'worker-dispatch');
|
|
1274
|
-
if (fs.existsSync(dispatchDir)) {
|
|
1275
|
-
var pending = fs.readdirSync(dispatchDir).filter(function(f) { return f.startsWith('pending-'); });
|
|
1276
|
-
if (pending.length > 0) {
|
|
1277
|
-
console.log('[WORKER_CLEANUP] ' + pending.length + ' worker dispatch(es) pending from this session');
|
|
1278
|
-
}
|
|
1279
|
-
// Move to processed
|
|
1280
|
-
var processedDir = path.join(dispatchDir, 'processed');
|
|
1281
|
-
fs.mkdirSync(processedDir, { recursive: true });
|
|
1282
|
-
pending.forEach(function(f) {
|
|
1283
|
-
try {
|
|
1284
|
-
fs.renameSync(path.join(dispatchDir, f), path.join(processedDir, f));
|
|
1285
|
-
} catch (e) { /* ignore */ }
|
|
1286
|
-
});
|
|
1287
|
-
// Trim processed/ to last 200 files to prevent unbounded growth
|
|
1288
|
-
try {
|
|
1289
|
-
var processedFiles = fs.readdirSync(processedDir)
|
|
1290
|
-
.filter(function(f) { return f.startsWith('pending-'); })
|
|
1291
|
-
.map(function(f) { var fp = path.join(processedDir, f); var mt = 0; try { mt = fs.statSync(fp).mtimeMs; } catch(e2){} return { f: f, mt: mt }; })
|
|
1292
|
-
.sort(function(a, b) { return a.mt - b.mt; });
|
|
1293
|
-
if (processedFiles.length > 200) {
|
|
1294
|
-
processedFiles.slice(0, processedFiles.length - 200).forEach(function(item) {
|
|
1295
|
-
try { fs.unlinkSync(path.join(processedDir, item.f)); } catch (e2) { /* ignore */ }
|
|
1296
|
-
});
|
|
1297
|
-
}
|
|
1298
|
-
} catch (e2) { /* non-fatal */ }
|
|
1299
|
-
}
|
|
1300
|
-
} catch (e) { /* non-fatal */ }
|
|
1301
|
-
},
|
|
1302
|
-
|
|
1303
|
-
'pre-task': async () => {
|
|
1304
|
-
if (session && session.metric) {
|
|
1305
|
-
try { session.metric('tasks'); } catch (e) { /* no active session */ }
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
// ── Task 27: PerRunModelTier — inline complexity scoring ───────────────
|
|
1309
|
-
var taskStr = typeof prompt === 'string' ? prompt : '';
|
|
1310
|
-
if (taskStr) {
|
|
1311
|
-
var score = 50;
|
|
1312
|
-
var lower = taskStr.toLowerCase();
|
|
1313
|
-
var words = taskStr.trim().split(/\s+/).length;
|
|
1314
|
-
if (words < 20) score -= 20;
|
|
1315
|
-
if (words > 100) score += 20;
|
|
1316
|
-
if (words > 200) score += 10;
|
|
1317
|
-
var highKw = ['architecture','distributed','security audit','cve','consensus','fault-tolerant','migrate','refactor across','orchestrat','design system','database schema','performance optim','threat model','encryption','zero-knowledge'];
|
|
1318
|
-
var lowKwRe = /\b(format|list|rename|sort|typo|lint|log|comment|print|echo|delete unused|remove import)\b/i;
|
|
1319
|
-
if (highKw.some(function(k) { return lower.includes(k); })) score += 10;
|
|
1320
|
-
if (lowKwRe.test(lower)) score -= 10;
|
|
1321
|
-
if (/(?:step\s*\d|first[\s,].*then[\s,]|phase\s*\d)/i.test(taskStr)) score += 10;
|
|
1322
|
-
if (/```[\s\S]*?```/.test(taskStr) || /\b[\w.-]+\/[\w./-]+\b/.test(taskStr)) score += 5;
|
|
1323
|
-
score = Math.max(0, Math.min(100, score));
|
|
1324
|
-
var tier = score < 30 ? 'haiku' : score > 70 ? 'opus' : 'sonnet';
|
|
1325
|
-
console.log('[TASK_MODEL_RECOMMENDATION] Use model="' + tier + '" (complexity=' + score + ')');
|
|
1326
|
-
}
|
|
1327
|
-
// Task 06: AutoRetry — signal retry policy only if coordinator path is active
|
|
1328
|
-
if (hookInput.swarmCoordinator || hookInput.coordinator || hookInput.useRetry) {
|
|
1329
|
-
console.log('[AUTO_RETRY_ENABLED] maxAttempts=3 strategy=exponential-backoff backoffMs=1000');
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
if (router && prompt) {
|
|
1333
|
-
var routeFn = router.routeTaskSemantic || router.routeTask;
|
|
1334
|
-
var result = await Promise.resolve(routeFn(prompt));
|
|
1335
|
-
console.log('[INFO] Task routed to: ' + result.agent + ' (confidence: ' + result.confidence + ')');
|
|
1336
|
-
} else {
|
|
1337
|
-
console.log('[OK] Task started');
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
// Task 24: PromptVersioning — resolve prompt variant before agent spawn
|
|
1341
|
-
try {
|
|
1342
|
-
var memMod = await import('@monomind/memory');
|
|
1343
|
-
if (memMod && memMod.PromptVersionStore) {
|
|
1344
|
-
var pvStore = new memMod.PromptVersionStore(path.join(CWD, '.monomind', 'prompt-versions'));
|
|
1345
|
-
var pvMod = await import('file://' + path.join(CWD, 'packages/@monomind/cli/dist/src/agents/prompt-experiment.js'));
|
|
1346
|
-
if (pvMod && pvMod.PromptExperimentRouter) {
|
|
1347
|
-
var pvRouter = new pvMod.PromptExperimentRouter(pvStore);
|
|
1348
|
-
var agentSlug24 = hookInput.agentSlug || hookInput.agentType || hookInput.agent_type || 'unknown';
|
|
1349
|
-
if (agentSlug24 !== 'unknown') {
|
|
1350
|
-
var resolved = pvRouter.resolvePromptForSpawn(agentSlug24);
|
|
1351
|
-
if (resolved.version) {
|
|
1352
|
-
console.log('[PROMPT_VERSION] ' + agentSlug24 + ' v' + resolved.version + (resolved.isCandidate ? ' (experiment candidate)' : ''));
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
} catch (e) { /* not available or no experiment */ }
|
|
1358
|
-
|
|
1359
|
-
// Monograph impact — detect changed files and surface their dependents
|
|
1360
|
-
try {
|
|
1361
|
-
var mgDbPath1 = path.join(CWD, '.monomind', 'monograph.db');
|
|
1362
|
-
if (fs.existsSync(mgDbPath1)) {
|
|
1363
|
-
var execSync1 = require('child_process').execSync;
|
|
1364
|
-
var changedFiles1 = '';
|
|
1365
|
-
try { changedFiles1 = execSync1('git diff --name-only HEAD 2>/dev/null || git diff --name-only 2>/dev/null', { cwd: CWD, timeout: 3000, shell: true }).toString().trim(); } catch(e) {}
|
|
1366
|
-
if (changedFiles1) {
|
|
1367
|
-
var mgMod1 = null;
|
|
1368
|
-
mgMod1 = _requireMonograph();
|
|
1369
|
-
if (mgMod1 && mgMod1.openDb) {
|
|
1370
|
-
var db1 = mgMod1.openDb(mgDbPath1);
|
|
1371
|
-
try {
|
|
1372
|
-
var fileList1 = changedFiles1.split('\n').filter(Boolean).slice(0, 8);
|
|
1373
|
-
var impacted1 = [];
|
|
1374
|
-
for (var fi = 0; fi < fileList1.length; fi++) {
|
|
1375
|
-
var fBase = path.basename(fileList1[fi]);
|
|
1376
|
-
var fNode = db1.prepare("SELECT id, name, label FROM nodes WHERE file_path LIKE ? LIMIT 1").get('%' + fBase);
|
|
1377
|
-
if (fNode) {
|
|
1378
|
-
var fImporters = db1.prepare(
|
|
1379
|
-
'SELECT n2.name FROM edges e JOIN nodes n2 ON n2.id = e.source_id WHERE e.target_id = ? LIMIT 5'
|
|
1380
|
-
).all(fNode.id);
|
|
1381
|
-
var entry = fNode.name + ' (' + fNode.label + ')';
|
|
1382
|
-
if (fImporters.length) entry += ' ← ' + fImporters.map(function(i){ return i.name; }).join(', ');
|
|
1383
|
-
impacted1.push(entry);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
if (impacted1.length > 0) {
|
|
1387
|
-
console.log('[MONOGRAPH_IMPACT] Changed files and their dependents: ' + impacted1.join(' | '));
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
// Effective blast radius — second pass using first impacted node
|
|
1391
|
-
try {
|
|
1392
|
-
if (fileList1.length > 0 && mgMod1.effectiveBlastRadius) {
|
|
1393
|
-
var firstFile1 = path.basename(fileList1[0]);
|
|
1394
|
-
var firstNode1 = db1.prepare("SELECT id, name, label FROM nodes WHERE file_path LIKE ? LIMIT 1").get('%' + firstFile1);
|
|
1395
|
-
if (firstNode1) {
|
|
1396
|
-
var blastResults1 = mgMod1.effectiveBlastRadius(db1, firstNode1.id, { maxDepth: 4 });
|
|
1397
|
-
if (blastResults1 && blastResults1.length > 0) {
|
|
1398
|
-
var bwdCount1 = blastResults1.filter(function(r){ return r.direction === 'backward' || r.direction === 'both'; }).length;
|
|
1399
|
-
var fwdCount1 = blastResults1.filter(function(r){ return r.direction === 'forward' || r.direction === 'both'; }).length;
|
|
1400
|
-
var topBlast1 = blastResults1.slice(0, 8).map(function(r){
|
|
1401
|
-
return '[' + r.direction + ':' + r.hops + '] ' + r.nodeName + ' (' + r.nodeLabel + ')';
|
|
1402
|
-
});
|
|
1403
|
-
console.log('[MONOGRAPH_BLAST_RADIUS] Node: ' + firstNode1.name + ' | forward=' + fwdCount1 + ' backward=' + bwdCount1 + ' | ' + topBlast1.join(', '));
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
} catch(blastErr) { /* non-fatal */ }
|
|
1408
|
-
} finally { if (mgMod1.closeDb) mgMod1.closeDb(db1); }
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
} catch(e) { /* non-fatal */ }
|
|
1413
|
-
|
|
1414
|
-
// Bridge to @monomind/hooks registry — fires Tasks 26 (PromptAssembler) and any other PreTask hooks
|
|
1415
|
-
if (_hooksModule && _hooksModule.executeHooks && _hooksModule.HookEvent) {
|
|
1416
|
-
try {
|
|
1417
|
-
await _hooksModule.executeHooks(_hooksModule.HookEvent.PreTask, {
|
|
1418
|
-
task: typeof prompt === 'string' ? { description: prompt, id: hookInput.taskId || '' } : null,
|
|
1419
|
-
sessionId: hookInput.sessionId || hookInput.session_id || 'default',
|
|
1420
|
-
}, { continueOnError: true, timeout: 2000 });
|
|
1421
|
-
} catch (e) { /* non-fatal */ }
|
|
1422
|
-
}
|
|
1423
|
-
},
|
|
1424
|
-
|
|
1425
|
-
'post-task': async () => {
|
|
1426
|
-
var taskSuccess = hookInput.success !== false && hookInput.status !== 'failed';
|
|
1427
|
-
if (intelligence && intelligence.feedback) {
|
|
1428
|
-
try {
|
|
1429
|
-
intelligence.feedback(true);
|
|
1430
|
-
} catch (e) { /* non-fatal */ }
|
|
1431
|
-
}
|
|
1432
|
-
// Each TeammateIdle/TaskCompleted = one agent done → remove oldest registration (FIFO)
|
|
1433
|
-
const regDir = path.join(CWD, '.monomind', 'agents', 'registrations');
|
|
1434
|
-
try {
|
|
1435
|
-
if (fs.existsSync(regDir)) {
|
|
1436
|
-
const files = fs.readdirSync(regDir).filter(f => f.endsWith('.json'));
|
|
1437
|
-
if (files.length > 0) {
|
|
1438
|
-
// Sort by mtime ascending (oldest first) and remove the oldest one
|
|
1439
|
-
const sorted = files
|
|
1440
|
-
.map(f => ({ f, mtime: (() => { try { return fs.statSync(path.join(regDir, f)).mtimeMs; } catch { return 0; } })() }))
|
|
1441
|
-
.sort((a, b) => a.mtime - b.mtime);
|
|
1442
|
-
try { fs.unlinkSync(path.join(regDir, sorted[0].f)); } catch { /* ignore */ }
|
|
1443
|
-
}
|
|
1444
|
-
// Also purge any stragglers older than 30 min
|
|
1445
|
-
const now = Date.now();
|
|
1446
|
-
for (const f of fs.readdirSync(regDir).filter(f => f.endsWith('.json'))) {
|
|
1447
|
-
try { if (now - fs.statSync(path.join(regDir, f)).mtimeMs > 30 * 60 * 1000) fs.unlinkSync(path.join(regDir, f)); } catch { /* ignore */ }
|
|
1448
|
-
}
|
|
1449
|
-
const remaining = fs.readdirSync(regDir).filter(f => f.endsWith('.json')).length;
|
|
1450
|
-
const _actPath = path.join(CWD, '.monomind', 'metrics', 'swarm-activity.json');
|
|
1451
|
-
let _prevLastActive = 0;
|
|
1452
|
-
try { _prevLastActive = (JSON.parse(fs.readFileSync(_actPath, 'utf-8'))?.swarm?.lastActive) || 0; } catch { /* ignore */ }
|
|
1453
|
-
fs.writeFileSync(_actPath, JSON.stringify({
|
|
1454
|
-
timestamp: new Date().toISOString(),
|
|
1455
|
-
swarm: {
|
|
1456
|
-
active: remaining > 0,
|
|
1457
|
-
agent_count: remaining,
|
|
1458
|
-
coordination_active: remaining > 0,
|
|
1459
|
-
lastActive: Math.max(remaining, _prevLastActive), // preserve peak across completion
|
|
1460
|
-
},
|
|
1461
|
-
}));
|
|
1462
|
-
}
|
|
1463
|
-
} catch (e) { /* non-fatal */ }
|
|
1464
|
-
// Bridge to @monomind/hooks registry — fires Tasks 39 (SpecializationScorer) and any other PostTask hooks
|
|
1465
|
-
if (_hooksModule && _hooksModule.executeHooks && _hooksModule.HookEvent) {
|
|
1466
|
-
try {
|
|
1467
|
-
await _hooksModule.executeHooks(_hooksModule.HookEvent.PostTask, {
|
|
1468
|
-
task: {
|
|
1469
|
-
id: hookInput.taskId || hookInput.task_id || '',
|
|
1470
|
-
status: taskSuccess ? 'completed' : 'failed',
|
|
1471
|
-
agentSlug: hookInput.agentSlug || hookInput.agent_slug || 'unknown',
|
|
1472
|
-
type: hookInput.taskType || hookInput.task_type || 'general',
|
|
1473
|
-
},
|
|
1474
|
-
success: taskSuccess,
|
|
1475
|
-
latencyMs: hookInput.latencyMs || hookInput.latency_ms || 0,
|
|
1476
|
-
qualityScore: hookInput.qualityScore || hookInput.quality_score,
|
|
1477
|
-
}, { continueOnError: true, timeout: 2000 });
|
|
1478
|
-
} catch (e) { /* non-fatal */ }
|
|
1479
|
-
}
|
|
1480
|
-
// Task 35: TerminationConditions — detect halted swarms via halt-signal
|
|
1481
|
-
try {
|
|
1482
|
-
var haltMod = await import('file://' + path.join(CWD, 'packages/@monomind/cli/dist/src/agents/halt-signal.js'));
|
|
1483
|
-
if (haltMod && haltMod.isHalted) {
|
|
1484
|
-
var swarmId35 = hookInput.swarmId || hookInput.swarm_id || 'default';
|
|
1485
|
-
if (haltMod.isHalted(swarmId35)) {
|
|
1486
|
-
console.warn('[HALT_DETECTED] Swarm ' + swarmId35 + ' has an active halt signal — agents should stop');
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
} catch (e) {
|
|
1490
|
-
// Try direct file check
|
|
1491
|
-
try {
|
|
1492
|
-
var haltFile = path.join(CWD, 'data', 'halt-signals.jsonl');
|
|
1493
|
-
if (fs.existsSync(haltFile)) {
|
|
1494
|
-
var haltLines = fs.readFileSync(haltFile, 'utf-8').trim().split('\n').filter(Boolean);
|
|
1495
|
-
if (haltLines.length > 0) {
|
|
1496
|
-
console.warn('[HALT_DETECTED] ' + haltLines.length + ' halt signal(s) present');
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
} catch (e2) { /* non-fatal */ }
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
// Task 37: DeadLetterQueue — enqueue failed tasks when retries exhausted
|
|
1503
|
-
try {
|
|
1504
|
-
if (!taskSuccess) {
|
|
1505
|
-
var dlqMod = await import('file://' + path.join(CWD, 'packages/@monomind/cli/dist/src/dlq/dlq-writer.js'));
|
|
1506
|
-
if (dlqMod && dlqMod.DLQWriter) {
|
|
1507
|
-
var dlqDir = path.join(CWD, '.monomind', 'dlq');
|
|
1508
|
-
var dlqWriter = new dlqMod.DLQWriter(dlqDir);
|
|
1509
|
-
dlqWriter.enqueue({
|
|
1510
|
-
toolName: 'post-task',
|
|
1511
|
-
originalPayload: { taskId: hookInput.taskId || '', agentSlug: hookInput.agentSlug || 'unknown' },
|
|
1512
|
-
deliveryAttempts: [{ attempt: 1, timestamp: new Date().toISOString(), error: hookInput.error || 'task failed' }],
|
|
1513
|
-
agentId: hookInput.agentSlug || hookInput.agent_slug,
|
|
1514
|
-
swarmId: hookInput.swarmId || hookInput.swarm_id,
|
|
1515
|
-
});
|
|
1516
|
-
console.log('[DLQ_ENQUEUED] Failed task ' + (hookInput.taskId || 'unknown') + ' sent to dead-letter queue');
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
} catch (e) { /* non-fatal */ }
|
|
1520
|
-
|
|
1521
|
-
// Memory Palace task drawer writes removed — use auto-memory files for task context
|
|
1522
|
-
|
|
1523
|
-
// ── Worker Auto-Dispatch ──────────────────────────────────────────────
|
|
1524
|
-
// Auto-dispatch background workers based on task outcome
|
|
1525
|
-
try {
|
|
1526
|
-
var taskDesc = (typeof prompt === 'string' ? prompt : hookInput.description || '').toLowerCase();
|
|
1527
|
-
var workersToDispatch = [];
|
|
1528
|
-
|
|
1529
|
-
// Always consolidate memory after any task
|
|
1530
|
-
workersToDispatch.push('consolidate');
|
|
1531
|
-
|
|
1532
|
-
// Security-related task → dispatch audit worker
|
|
1533
|
-
if (/\b(security|auth|vuln|cve|threat|token|permission|crypto)\b/.test(taskDesc)) {
|
|
1534
|
-
workersToDispatch.push('audit');
|
|
1535
|
-
}
|
|
1536
|
-
// Performance-related → dispatch benchmark worker
|
|
1537
|
-
if (/\b(performance|optimiz|benchmark|latency|throughput)\b/.test(taskDesc)) {
|
|
1538
|
-
workersToDispatch.push('benchmark');
|
|
1539
|
-
}
|
|
1540
|
-
// Code changes → dispatch testgaps worker
|
|
1541
|
-
if (/\b(implement|feature|refactor|fix|build|add|create|modify)\b/.test(taskDesc)) {
|
|
1542
|
-
workersToDispatch.push('testgaps');
|
|
1543
|
-
}
|
|
1544
|
-
// Any significant task → dispatch map worker for codebase indexing
|
|
1545
|
-
if (taskDesc.length > 50) {
|
|
1546
|
-
workersToDispatch.push('map');
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
// Dispatch via @monomind/hooks if available, otherwise write dispatch file
|
|
1550
|
-
if (workersToDispatch.length > 0) {
|
|
1551
|
-
var dispatchDir = path.join(CWD, '.monomind', 'worker-dispatch');
|
|
1552
|
-
fs.mkdirSync(dispatchDir, { recursive: true });
|
|
1553
|
-
var dispatchPayload = {
|
|
1554
|
-
workers: workersToDispatch,
|
|
1555
|
-
trigger: 'post-task',
|
|
1556
|
-
taskDesc: taskDesc.substring(0, 100),
|
|
1557
|
-
success: taskSuccess,
|
|
1558
|
-
timestamp: new Date().toISOString(),
|
|
1559
|
-
};
|
|
1560
|
-
fs.writeFileSync(
|
|
1561
|
-
path.join(dispatchDir, 'pending-' + Date.now() + '-' + Math.random().toString(36).slice(2, 7) + '.json'),
|
|
1562
|
-
JSON.stringify(dispatchPayload), 'utf-8'
|
|
1563
|
-
);
|
|
1564
|
-
console.log('[WORKER_DISPATCH] Queued: ' + workersToDispatch.join(', '));
|
|
1565
|
-
}
|
|
1566
|
-
} catch (e) { /* non-fatal */ }
|
|
1567
|
-
|
|
1568
|
-
// ── ADR Auto-Generation ────────────────────────────────────────────────
|
|
1569
|
-
// When adr.autoGenerate is true and task involved architect-level work,
|
|
1570
|
-
// create an ADR stub in the configured directory
|
|
1571
|
-
try {
|
|
1572
|
-
var settingsPath = path.join(CWD, '.claude', 'settings.json');
|
|
1573
|
-
var adrCfg = {};
|
|
1574
|
-
if (fs.existsSync(settingsPath)) {
|
|
1575
|
-
var s = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
|
|
1576
|
-
adrCfg = (s.monomind && s.monomind.adr) || {};
|
|
1577
|
-
}
|
|
1578
|
-
if (adrCfg.autoGenerate) {
|
|
1579
|
-
var taskAgent = hookInput.agentSlug || hookInput.agent_slug || '';
|
|
1580
|
-
var taskDescAdr = (typeof prompt === 'string' ? prompt : hookInput.description || '').toLowerCase();
|
|
1581
|
-
var isArchitectLevel = ['architect', 'system-architect', 'software-architect'].includes(taskAgent)
|
|
1582
|
-
|| /\b(architecture|design decision|adr|trade-?off|migration strategy)\b/.test(taskDescAdr);
|
|
1583
|
-
if (isArchitectLevel && taskDescAdr.length > 30) {
|
|
1584
|
-
var adrDir = path.join(CWD, adrCfg.directory || 'docs/adrs');
|
|
1585
|
-
fs.mkdirSync(adrDir, { recursive: true });
|
|
1586
|
-
var adrNum = (fs.readdirSync(adrDir).filter(function(f) { return f.endsWith('.md'); }).length + 1)
|
|
1587
|
-
.toString().padStart(4, '0');
|
|
1588
|
-
var adrTitle = taskDescAdr.substring(0, 60).replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
1589
|
-
var adrFile = path.join(adrDir, 'ADR-' + adrNum + '-' + adrTitle + '.md');
|
|
1590
|
-
if (!fs.existsSync(adrFile)) {
|
|
1591
|
-
var adrContent = '# ADR-' + adrNum + ': ' + (typeof prompt === 'string' ? prompt.substring(0, 80) : adrTitle) + '\n\n'
|
|
1592
|
-
+ '**Date:** ' + new Date().toISOString().slice(0, 10) + '\n'
|
|
1593
|
-
+ '**Status:** Accepted\n'
|
|
1594
|
-
+ '**Agent:** ' + (taskAgent || 'unknown') + '\n\n'
|
|
1595
|
-
+ '## Context\n\nAuto-generated from task completion.\n\n'
|
|
1596
|
-
+ '## Decision\n\n_Fill in the decision made._\n\n'
|
|
1597
|
-
+ '## Consequences\n\n_Fill in the consequences._\n';
|
|
1598
|
-
fs.writeFileSync(adrFile, adrContent, 'utf-8');
|
|
1599
|
-
console.log('[ADR_GENERATED] ' + path.basename(adrFile));
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
}
|
|
1603
|
-
} catch (e) { /* non-fatal */ }
|
|
1604
|
-
|
|
1605
|
-
console.log('[OK] Task completed');
|
|
1606
|
-
},
|
|
1607
|
-
|
|
1608
|
-
'compact-manual': async () => {
|
|
1609
|
-
// Consolidate intelligence before compaction so patterns survive
|
|
1610
|
-
if (intelligence && intelligence.consolidate) {
|
|
1611
|
-
try { await runWithTimeout(function() { return intelligence.consolidate(); }, 'intelligence.consolidate()'); } catch (e) { /* non-fatal */ }
|
|
1612
|
-
}
|
|
1613
|
-
// Save current routing context for post-compact restore
|
|
1614
|
-
try {
|
|
1615
|
-
var lastRoute = path.join(CWD, '.monomind', 'last-route.json');
|
|
1616
|
-
if (fs.existsSync(lastRoute)) {
|
|
1617
|
-
var route = JSON.parse(fs.readFileSync(lastRoute, 'utf-8'));
|
|
1618
|
-
console.log('[COMPACT_CONTEXT] Last route: ' + route.agent + ' (' + (route.confidence != null ? (route.confidence * 100).toFixed(0) : '?') + '%)');
|
|
1619
|
-
}
|
|
1620
|
-
} catch (e) { /* non-fatal */ }
|
|
1621
|
-
console.log('[COMPACT] Manual compaction — intelligence consolidated, context preserved');
|
|
1622
|
-
},
|
|
1623
|
-
|
|
1624
|
-
'compact-auto': async () => {
|
|
1625
|
-
// Same consolidation for auto-compact
|
|
1626
|
-
if (intelligence && intelligence.consolidate) {
|
|
1627
|
-
try { await runWithTimeout(function() { return intelligence.consolidate(); }, 'intelligence.consolidate()'); } catch (e) { /* non-fatal */ }
|
|
1628
|
-
}
|
|
1629
|
-
try {
|
|
1630
|
-
var lastRoute = path.join(CWD, '.monomind', 'last-route.json');
|
|
1631
|
-
if (fs.existsSync(lastRoute)) {
|
|
1632
|
-
var route = JSON.parse(fs.readFileSync(lastRoute, 'utf-8'));
|
|
1633
|
-
console.log('[COMPACT_CONTEXT] Last route: ' + route.agent + ' (' + (route.confidence != null ? (route.confidence * 100).toFixed(0) : '?') + '%)');
|
|
1634
|
-
}
|
|
1635
|
-
} catch (e) { /* non-fatal */ }
|
|
1636
|
-
console.log('[COMPACT] Auto compaction — intelligence consolidated, context preserved');
|
|
1637
|
-
console.log('GOLDEN RULE: 1 message = all parallel operations');
|
|
1638
|
-
},
|
|
1639
|
-
|
|
1640
|
-
'agent-start': () => {
|
|
1641
|
-
// Called by SubagentStart hook — register this agent so the statusline can count it
|
|
1642
|
-
const regDir = path.join(CWD, '.monomind', 'agents', 'registrations');
|
|
1643
|
-
try {
|
|
1644
|
-
fs.mkdirSync(regDir, { recursive: true });
|
|
1645
|
-
const id = Date.now() + '-' + Math.random().toString(36).slice(2, 6);
|
|
1646
|
-
const regFile = path.join(regDir, 'agent-' + id + '.json');
|
|
1647
|
-
fs.writeFileSync(regFile, JSON.stringify({
|
|
1648
|
-
agentId: id,
|
|
1649
|
-
startedAt: new Date().toISOString(),
|
|
1650
|
-
pid: process.pid,
|
|
1651
|
-
}));
|
|
1652
|
-
// Also refresh swarm-activity.json so it's within the 5-min staleness window
|
|
1653
|
-
const activityDir = path.join(CWD, '.monomind', 'metrics');
|
|
1654
|
-
fs.mkdirSync(activityDir, { recursive: true });
|
|
1655
|
-
const activityPath = path.join(activityDir, 'swarm-activity.json');
|
|
1656
|
-
const active = fs.readdirSync(regDir).filter(f => f.endsWith('.json')).length;
|
|
1657
|
-
// Preserve lastActive (peak) across agent lifecycle so statusline shows non-zero after completion
|
|
1658
|
-
let prevLastActive = 0;
|
|
1659
|
-
try { prevLastActive = (JSON.parse(fs.readFileSync(activityPath, 'utf-8'))?.swarm?.lastActive) || 0; } catch { /* ignore */ }
|
|
1660
|
-
fs.writeFileSync(activityPath, JSON.stringify({
|
|
1661
|
-
timestamp: new Date().toISOString(),
|
|
1662
|
-
swarm: {
|
|
1663
|
-
active: active > 0,
|
|
1664
|
-
agent_count: active,
|
|
1665
|
-
coordination_active: active > 0,
|
|
1666
|
-
lastActive: Math.max(active, prevLastActive),
|
|
1667
|
-
},
|
|
1668
|
-
}));
|
|
1669
|
-
|
|
1670
|
-
// Write last-dispatch.json so the route handler can suppress redundant suggestions
|
|
1671
|
-
// on the next turn when the same type of agent is recommended.
|
|
1672
|
-
const agentType = hookInput.subagent_type || hookInput.agentType || hookInput.agent_type || hookInput.agentSlug || 'unknown';
|
|
1673
|
-
const agentDesc = hookInput.description || hookInput.prompt_description || '';
|
|
1674
|
-
fs.writeFileSync(
|
|
1675
|
-
path.join(CWD, '.monomind', 'last-dispatch.json'),
|
|
1676
|
-
JSON.stringify({
|
|
1677
|
-
agentType: agentType,
|
|
1678
|
-
description: agentDesc.substring(0, 120),
|
|
1679
|
-
dispatchedAt: new Date().toISOString(),
|
|
1680
|
-
}),
|
|
1681
|
-
'utf-8'
|
|
1682
|
-
);
|
|
1683
|
-
} catch (e) { /* non-fatal — never block a subagent from starting */ }
|
|
1684
|
-
console.log('[OK] Agent registered');
|
|
1685
|
-
},
|
|
1686
|
-
|
|
1687
|
-
'status': () => {
|
|
1688
|
-
console.log('[OK] Status check');
|
|
1689
|
-
},
|
|
1690
|
-
|
|
1691
|
-
'stats': async () => {
|
|
1692
|
-
if (intelligence && intelligence.stats) {
|
|
1693
|
-
await Promise.resolve(intelligence.stats(args.includes('--json')));
|
|
1694
|
-
} else {
|
|
1695
|
-
console.log('[WARN] Intelligence module not available. Run session-restore first.');
|
|
1696
|
-
}
|
|
1697
|
-
},
|
|
1698
|
-
};
|
|
1699
|
-
|
|
1700
|
-
if (command && handlers[command]) {
|
|
1701
|
-
try {
|
|
1702
|
-
await Promise.resolve(handlers[command]());
|
|
1703
|
-
} catch (e) {
|
|
1704
|
-
console.log('[WARN] Hook ' + command + ' encountered an error: ' + e.message);
|
|
1705
|
-
}
|
|
1706
|
-
} else if (command) {
|
|
1707
|
-
console.log('[OK] Hook: ' + command);
|
|
1708
|
-
} else {
|
|
1709
|
-
console.log('Usage: hook-handler.cjs <route|pre-bash|post-edit|session-restore|session-end|pre-task|post-task|compact-manual|compact-auto|status|stats>');
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
main().catch(function(e) {
|
|
1714
|
-
console.log('[WARN] Hook handler error: ' + e.message);
|
|
1715
|
-
}).finally(function() {
|
|
1716
|
-
// Ensure clean exit for Claude Code hooks
|
|
1717
|
-
process.exit(0);
|
|
1718
|
-
});
|