monomind 1.18.13 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/.claude/agents/core/researcher.md +29 -24
  2. package/.claude/agents/github/code-review-swarm.md +1 -1
  3. package/.claude/agents/github/github-modes.md +1 -1
  4. package/.claude/agents/github/issue-tracker.md +1 -1
  5. package/.claude/agents/github/multi-repo-swarm.md +1 -1
  6. package/.claude/agents/github/pr-manager.md +1 -1
  7. package/.claude/agents/github/project-board-sync.md +1 -1
  8. package/.claude/agents/github/release-manager.md +1 -1
  9. package/.claude/agents/github/repo-architect.md +1 -1
  10. package/.claude/agents/github/swarm-issue.md +1 -1
  11. package/.claude/agents/github/swarm-pr.md +1 -1
  12. package/.claude/agents/github/sync-coordinator.md +1 -1
  13. package/.claude/agents/github/workflow-automation.md +1 -1
  14. package/.claude/agents/goal/goal-planner.md +1 -1
  15. package/.claude/agents/specialized/specialized-workflow-architect.md +11 -14
  16. package/.claude/agents/testing/production-validator.md +8 -7
  17. package/.claude/agents/testing/testing-evidence-collector.md +3 -1
  18. package/.claude/commands/mastermind/_repeat.md +22 -3
  19. package/.claude/commands/mastermind/architect.md +1 -1
  20. package/.claude/commands/mastermind/autodev.md +1 -1
  21. package/.claude/commands/mastermind/build.md +1 -1
  22. package/.claude/commands/mastermind/code-review.md +5 -5
  23. package/.claude/commands/mastermind/debug.md +1 -1
  24. package/.claude/commands/mastermind/help.md +2 -2
  25. package/.claude/commands/mastermind/idea.md +1 -1
  26. package/.claude/commands/mastermind/improve.md +1 -1
  27. package/.claude/commands/mastermind/okf-export.md +14 -0
  28. package/.claude/commands/mastermind/okf-import.md +15 -0
  29. package/.claude/commands/mastermind/plan.md +1 -1
  30. package/.claude/commands/mastermind/research.md +1 -1
  31. package/.claude/commands/mastermind/review.md +12 -1
  32. package/.claude/commands/mastermind/runorg.md +1 -1
  33. package/.claude/commands/mastermind/taskdev.md +1 -1
  34. package/.claude/commands/mastermind/tdd.md +1 -1
  35. package/.claude/commands/mastermind/verify.md +1 -1
  36. package/.claude/helpers/graphify-freshen.cjs +16 -20
  37. package/.claude/helpers/handlers/agent-start-handler.cjs +11 -36
  38. package/.claude/helpers/handlers/capture-handler.cjs +110 -0
  39. package/.claude/helpers/handlers/route-handler.cjs +180 -256
  40. package/.claude/helpers/handlers/session-handler.cjs +139 -142
  41. package/.claude/helpers/handlers/session-restore-handler.cjs +15 -10
  42. package/.claude/helpers/handlers/task-handler.cjs +8 -155
  43. package/.claude/helpers/hook-handler.cjs +89 -5
  44. package/.claude/helpers/intelligence.cjs +164 -15
  45. package/.claude/helpers/learning-service.mjs +1 -0
  46. package/.claude/helpers/mastermind-activate.cjs +33 -51
  47. package/.claude/helpers/monolean-activate.cjs +13 -3
  48. package/.claude/helpers/monolean-propagate.cjs +7 -3
  49. package/.claude/helpers/router.cjs +47 -9
  50. package/.claude/helpers/utils/monograph.cjs +37 -20
  51. package/.claude/settings.json +0 -20
  52. package/.claude/skills/mastermind-skills/_repeat.md +29 -4
  53. package/.claude/skills/mastermind-skills/architect.md +5 -6
  54. package/.claude/skills/mastermind-skills/autodev.md +8 -5
  55. package/.claude/skills/mastermind-skills/review.md +25 -11
  56. package/.claude/skills/mastermind-skills/techport.md +37 -3
  57. package/.claude/skills/monodesign/document.md +9 -6
  58. package/.claude/skills/monodesign/extract.md +1 -1
  59. package/.claude/skills/monodesign/reference/document.md +1 -1
  60. package/.claude/skills/monodesign/reference/live.md +1 -1
  61. package/.claude/skills/monolean/SKILL.md +1 -1
  62. package/package.json +1 -1
  63. package/packages/@monomind/cli/.claude/agents/core/researcher.md +29 -24
  64. package/packages/@monomind/cli/.claude/agents/github/code-review-swarm.md +1 -1
  65. package/packages/@monomind/cli/.claude/agents/github/github-modes.md +1 -1
  66. package/packages/@monomind/cli/.claude/agents/github/issue-tracker.md +1 -1
  67. package/packages/@monomind/cli/.claude/agents/github/multi-repo-swarm.md +1 -1
  68. package/packages/@monomind/cli/.claude/agents/github/pr-manager.md +1 -1
  69. package/packages/@monomind/cli/.claude/agents/github/project-board-sync.md +1 -1
  70. package/packages/@monomind/cli/.claude/agents/github/release-manager.md +1 -1
  71. package/packages/@monomind/cli/.claude/agents/github/repo-architect.md +1 -1
  72. package/packages/@monomind/cli/.claude/agents/github/swarm-issue.md +1 -1
  73. package/packages/@monomind/cli/.claude/agents/github/swarm-pr.md +1 -1
  74. package/packages/@monomind/cli/.claude/agents/github/sync-coordinator.md +1 -1
  75. package/packages/@monomind/cli/.claude/agents/github/workflow-automation.md +1 -1
  76. package/packages/@monomind/cli/.claude/agents/goal/goal-planner.md +1 -1
  77. package/packages/@monomind/cli/.claude/agents/specialized/specialized-workflow-architect.md +11 -14
  78. package/packages/@monomind/cli/.claude/agents/testing/production-validator.md +8 -7
  79. package/packages/@monomind/cli/.claude/agents/testing/testing-evidence-collector.md +3 -1
  80. package/packages/@monomind/cli/.claude/commands/mastermind/_repeat.md +22 -3
  81. package/packages/@monomind/cli/.claude/commands/mastermind/architect.md +1 -1
  82. package/packages/@monomind/cli/.claude/commands/mastermind/autodev.md +1 -1
  83. package/packages/@monomind/cli/.claude/commands/mastermind/build.md +1 -1
  84. package/packages/@monomind/cli/.claude/commands/mastermind/code-review.md +5 -5
  85. package/packages/@monomind/cli/.claude/commands/mastermind/debug.md +1 -1
  86. package/packages/@monomind/cli/.claude/commands/mastermind/help.md +2 -2
  87. package/packages/@monomind/cli/.claude/commands/mastermind/idea.md +1 -1
  88. package/packages/@monomind/cli/.claude/commands/mastermind/improve.md +1 -1
  89. package/packages/@monomind/cli/.claude/commands/mastermind/okf-export.md +14 -0
  90. package/packages/@monomind/cli/.claude/commands/mastermind/okf-import.md +15 -0
  91. package/packages/@monomind/cli/.claude/commands/mastermind/plan.md +1 -1
  92. package/packages/@monomind/cli/.claude/commands/mastermind/research.md +1 -1
  93. package/packages/@monomind/cli/.claude/commands/mastermind/review.md +12 -1
  94. package/packages/@monomind/cli/.claude/commands/mastermind/runorg.md +1 -1
  95. package/packages/@monomind/cli/.claude/commands/mastermind/taskdev.md +1 -1
  96. package/packages/@monomind/cli/.claude/commands/mastermind/tdd.md +1 -1
  97. package/packages/@monomind/cli/.claude/commands/mastermind/verify.md +1 -1
  98. package/packages/@monomind/cli/.claude/helpers/graphify-freshen.cjs +16 -20
  99. package/packages/@monomind/cli/.claude/helpers/handlers/agent-start-handler.cjs +11 -36
  100. package/packages/@monomind/cli/.claude/helpers/handlers/capture-handler.cjs +110 -0
  101. package/packages/@monomind/cli/.claude/helpers/handlers/route-handler.cjs +180 -256
  102. package/packages/@monomind/cli/.claude/helpers/handlers/session-handler.cjs +139 -142
  103. package/packages/@monomind/cli/.claude/helpers/handlers/session-restore-handler.cjs +15 -10
  104. package/packages/@monomind/cli/.claude/helpers/handlers/task-handler.cjs +8 -155
  105. package/packages/@monomind/cli/.claude/helpers/hook-handler.cjs +89 -5
  106. package/packages/@monomind/cli/.claude/helpers/intelligence.cjs +164 -15
  107. package/packages/@monomind/cli/.claude/helpers/learning-service.mjs +1 -0
  108. package/packages/@monomind/cli/.claude/helpers/mastermind-activate.cjs +33 -51
  109. package/packages/@monomind/cli/.claude/helpers/monolean-activate.cjs +13 -3
  110. package/packages/@monomind/cli/.claude/helpers/monolean-propagate.cjs +7 -3
  111. package/packages/@monomind/cli/.claude/helpers/router.cjs +47 -9
  112. package/packages/@monomind/cli/.claude/helpers/utils/monograph.cjs +37 -20
  113. package/packages/@monomind/cli/.claude/skills/mastermind-skills/_repeat.md +29 -4
  114. package/packages/@monomind/cli/.claude/skills/mastermind-skills/architect.md +5 -6
  115. package/packages/@monomind/cli/.claude/skills/mastermind-skills/autodev.md +8 -5
  116. package/packages/@monomind/cli/.claude/skills/mastermind-skills/review.md +25 -11
  117. package/packages/@monomind/cli/.claude/skills/mastermind-skills/techport.md +37 -3
  118. package/packages/@monomind/cli/.claude/skills/monodesign/document.md +9 -6
  119. package/packages/@monomind/cli/.claude/skills/monodesign/extract.md +1 -1
  120. package/packages/@monomind/cli/.claude/skills/monodesign/reference/document.md +1 -1
  121. package/packages/@monomind/cli/.claude/skills/monodesign/reference/live.md +1 -1
  122. package/packages/@monomind/cli/.claude/skills/monolean/SKILL.md +1 -1
  123. package/packages/@monomind/cli/bin/mcp-server.js +11 -1
  124. package/packages/@monomind/cli/dist/src/commands/agent-ops.d.ts +1 -2
  125. package/packages/@monomind/cli/dist/src/commands/agent-ops.js +1 -59
  126. package/packages/@monomind/cli/dist/src/commands/agent.js +2 -3
  127. package/packages/@monomind/cli/dist/src/commands/analyze-diff.js +1 -1
  128. package/packages/@monomind/cli/dist/src/commands/browse-action.js +94 -2
  129. package/packages/@monomind/cli/dist/src/commands/completions.js +11 -56
  130. package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.d.ts +1 -1
  131. package/packages/@monomind/cli/dist/src/commands/doctor-project-checks.js +1 -1
  132. package/packages/@monomind/cli/dist/src/commands/hive-mind-helpers.js +2 -2
  133. package/packages/@monomind/cli/dist/src/commands/hive-mind-ops.d.ts +1 -3
  134. package/packages/@monomind/cli/dist/src/commands/hive-mind-ops.js +2 -116
  135. package/packages/@monomind/cli/dist/src/commands/hive-mind.js +2 -5
  136. package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.js +8 -7
  137. package/packages/@monomind/cli/dist/src/commands/hooks-coverage-gaps.js +1 -1
  138. package/packages/@monomind/cli/dist/src/commands/hooks-coverage-routing.js +2 -2
  139. package/packages/@monomind/cli/dist/src/commands/hooks-extended-commands.d.ts +0 -3
  140. package/packages/@monomind/cli/dist/src/commands/hooks-extended-commands.js +0 -307
  141. package/packages/@monomind/cli/dist/src/commands/hooks.js +1 -12
  142. package/packages/@monomind/cli/dist/src/commands/index.d.ts +3 -51
  143. package/packages/@monomind/cli/dist/src/commands/index.js +36 -184
  144. package/packages/@monomind/cli/dist/src/commands/init-wizard.js +2 -4
  145. package/packages/@monomind/cli/dist/src/commands/mcp.js +32 -4
  146. package/packages/@monomind/cli/dist/src/commands/memory-admin.d.ts +1 -2
  147. package/packages/@monomind/cli/dist/src/commands/memory-admin.js +1 -118
  148. package/packages/@monomind/cli/dist/src/commands/memory-transfer.d.ts +1 -2
  149. package/packages/@monomind/cli/dist/src/commands/memory-transfer.js +5 -171
  150. package/packages/@monomind/cli/dist/src/commands/memory.js +3 -6
  151. package/packages/@monomind/cli/dist/src/commands/neural-core.d.ts +3 -1
  152. package/packages/@monomind/cli/dist/src/commands/neural-core.js +145 -6
  153. package/packages/@monomind/cli/dist/src/commands/neural-optimize.js +4 -4
  154. package/packages/@monomind/cli/dist/src/commands/neural-registry.d.ts +1 -1
  155. package/packages/@monomind/cli/dist/src/commands/neural-registry.js +4 -4
  156. package/packages/@monomind/cli/dist/src/commands/neural.d.ts +1 -1
  157. package/packages/@monomind/cli/dist/src/commands/neural.js +6 -6
  158. package/packages/@monomind/cli/dist/src/commands/performance.js +68 -58
  159. package/packages/@monomind/cli/dist/src/commands/providers.js +2 -131
  160. package/packages/@monomind/cli/dist/src/commands/security-misc.d.ts +0 -1
  161. package/packages/@monomind/cli/dist/src/commands/security-misc.js +69 -45
  162. package/packages/@monomind/cli/dist/src/commands/security.js +2 -4
  163. package/packages/@monomind/cli/dist/src/commands/session.js +1 -285
  164. package/packages/@monomind/cli/dist/src/commands/start.js +2 -41
  165. package/packages/@monomind/cli/dist/src/commands/status.js +18 -29
  166. package/packages/@monomind/cli/dist/src/commands/swarm.js +1 -1
  167. package/packages/@monomind/cli/dist/src/commands/task.js +2 -49
  168. package/packages/@monomind/cli/dist/src/commands/workflow.js +2 -104
  169. package/packages/@monomind/cli/dist/src/index.js +7 -0
  170. package/packages/@monomind/cli/dist/src/init/executor.js +3 -14
  171. package/packages/@monomind/cli/dist/src/init/helpers-generator.js +2 -22
  172. package/packages/@monomind/cli/dist/src/init/settings-generator.js +0 -1
  173. package/packages/@monomind/cli/dist/src/init/types.d.ts +1 -3
  174. package/packages/@monomind/cli/dist/src/init/types.js +0 -2
  175. package/packages/@monomind/cli/dist/src/mcp-client.js +0 -6
  176. package/packages/@monomind/cli/dist/src/mcp-server.js +16 -0
  177. package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +0 -17
  178. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/causal-infer.d.ts +5 -5
  179. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/causal-infer.js +32 -46
  180. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/consensus-verify.d.ts +2 -3
  181. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/consensus-verify.js +22 -20
  182. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/memory-gate.d.ts +3 -2
  183. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/memory-gate.js +32 -19
  184. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/quantum-topology.d.ts +4 -4
  185. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/quantum-topology.js +11 -17
  186. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/spectral-analyze.d.ts +2 -3
  187. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/spectral-analyze.js +51 -32
  188. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/types.d.ts +5 -9
  189. package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +2 -2
  190. package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +25 -3
  191. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-routing.d.ts +0 -3
  192. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-routing.js +45 -159
  193. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +1 -4
  194. package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +0 -2
  195. package/packages/@monomind/cli/dist/src/mcp-tools/index.js +0 -3
  196. package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.js +24 -0
  197. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +452 -7
  198. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +4 -10
  199. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +28 -54
  200. package/packages/@monomind/cli/dist/src/mcp-tools/performance-tools.js +5 -17
  201. package/packages/@monomind/cli/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.js +2 -2
  202. package/packages/@monomind/cli/dist/src/mcp-tools/quality/security-compliance/detect-secrets.d.ts +4 -4
  203. package/packages/@monomind/cli/dist/src/mcp-tools/quality-tools.d.ts +7 -2
  204. package/packages/@monomind/cli/dist/src/mcp-tools/quality-tools.js +7 -257
  205. package/packages/@monomind/cli/dist/src/memory/intelligence.d.ts +7 -8
  206. package/packages/@monomind/cli/dist/src/memory/intelligence.js +15 -16
  207. package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +1 -0
  208. package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +37 -0
  209. package/packages/@monomind/cli/dist/src/services/worker-daemon.d.ts +3 -21
  210. package/packages/@monomind/cli/dist/src/services/worker-daemon.js +13 -80
  211. package/packages/@monomind/cli/dist/src/suggest.js +0 -5
  212. package/packages/@monomind/cli/package.json +1 -1
  213. package/packages/@monomind/guidance/README.md +49 -1153
  214. package/packages/@monomind/guidance/package.json +1 -74
  215. package/.claude/helpers/auto-memory-hook.mjs +0 -503
  216. package/packages/@monomind/cli/.claude/helpers/auto-memory-hook.mjs +0 -503
  217. package/packages/@monomind/cli/dist/src/commands/deployment.d.ts +0 -10
  218. package/packages/@monomind/cli/dist/src/commands/deployment.js +0 -706
@@ -2,7 +2,7 @@
2
2
  name: swarm-issue
3
3
  description: |
4
4
  GitHub issue-based swarm coordination agent that transforms issues into intelligent multi-agent tasks with automatic decomposition and progress tracking
5
- tools: mcp__github__get_issue, mcp__github__create_issue, mcp__github__update_issue, mcp__github__list_issues, mcp__github__create_issue_comment, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__task_orchestrate, mcp__monomind__memory_usage, TodoWrite, TodoRead, Bash, Grep, Read, Write
5
+ tools: mcp__github__get_issue, mcp__github__create_issue, mcp__github__update_issue, mcp__github__list_issues, mcp__github__create_issue_comment, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__memory_usage, TodoWrite, TodoRead, Bash, Grep, Read, Write
6
6
  ---
7
7
 
8
8
  # Swarm Issue - Issue-Based Swarm Coordination
@@ -2,7 +2,7 @@
2
2
  name: swarm-pr
3
3
  description: |
4
4
  Pull request swarm management agent that coordinates multi-agent code review, validation, and integration workflows with automated PR lifecycle management
5
- tools: mcp__github__get_pull_request, mcp__github__create_pull_request, mcp__github__update_pull_request, mcp__github__list_pull_requests, mcp__github__create_pr_comment, mcp__github__get_pr_diff, mcp__github__merge_pull_request, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__task_orchestrate, mcp__monomind__memory_usage, mcp__monomind__coordination_sync, TodoWrite, TodoRead, Bash, Grep, Read, Write, Edit
5
+ tools: mcp__github__get_pull_request, mcp__github__create_pull_request, mcp__github__update_pull_request, mcp__github__list_pull_requests, mcp__github__create_pr_comment, mcp__github__get_pr_diff, mcp__github__merge_pull_request, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__memory_usage, mcp__monomind__coordination_sync, TodoWrite, TodoRead, Bash, Grep, Read, Write, Edit
6
6
  ---
7
7
 
8
8
  # Swarm PR - Managing Swarms through Pull Requests
@@ -2,7 +2,7 @@
2
2
  name: sync-coordinator
3
3
  description: |
4
4
  Multi-repository synchronization coordinator that manages version alignment, dependency synchronization, and cross-package integration with intelligent swarm orchestration
5
- tools: mcp__github__push_files, mcp__github__create_or_update_file, mcp__github__get_file_contents, mcp__github__create_pull_request, mcp__github__search_repositories, mcp__github__list_repositories, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__task_orchestrate, mcp__monomind__memory_store, mcp__monomind__coordination_sync, mcp__monomind__load_balance, TodoWrite, TodoRead, Bash, Read, Write, Edit, MultiEdit
5
+ tools: mcp__github__push_files, mcp__github__create_or_update_file, mcp__github__get_file_contents, mcp__github__create_pull_request, mcp__github__search_repositories, mcp__github__list_repositories, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__memory_store, mcp__monomind__coordination_sync, mcp__monomind__load_balance, TodoWrite, TodoRead, Bash, Read, Write, Edit, MultiEdit
6
6
  ---
7
7
 
8
8
  # GitHub Sync Coordinator
@@ -2,7 +2,7 @@
2
2
  name: workflow-automation
3
3
  description: |
4
4
  GitHub Actions workflow automation agent that creates intelligent, self-organizing CI/CD pipelines with adaptive multi-agent coordination and automated optimization
5
- tools: mcp__github__create_workflow, mcp__github__update_workflow, mcp__github__list_workflows, mcp__github__get_workflow_runs, mcp__github__create_workflow_dispatch, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__task_orchestrate, mcp__monomind__memory_usage, mcp__monomind__performance_report, mcp__monomind__bottleneck_analyze, mcp__monomind__workflow_create, mcp__monomind__automation_setup, TodoWrite, TodoRead, Bash, Read, Write, Edit, Grep
5
+ tools: mcp__github__create_workflow, mcp__github__update_workflow, mcp__github__list_workflows, mcp__github__get_workflow_runs, mcp__github__create_workflow_dispatch, mcp__monomind__swarm_init, mcp__monomind__agent_spawn, mcp__monomind__memory_usage, mcp__monomind__performance_report, mcp__monomind__bottleneck_analyze, mcp__monomind__workflow_create, mcp__monomind__automation_setup, TodoWrite, TodoRead, Bash, Read, Write, Edit, Grep
6
6
  ---
7
7
 
8
8
  # Workflow Automation - GitHub Actions Integration
@@ -87,7 +87,7 @@ Advanced action definitions with tool groups:
87
87
  Action: analyze_codebase
88
88
  Preconditions: {repository_accessible: true}
89
89
  Effects: {code_analyzed: true, metrics_available: true}
90
- Tools: [grep, ast_parser, complexity_analyzer]
90
+ Tools: [monograph_query, monograph_suggest, grep (fallback), ast_parser, complexity_analyzer]
91
91
  Execution: hybrid (LLM for insights, code for metrics)
92
92
  Cost: 2
93
93
  Fallback: manual_review if tools unavailable
@@ -440,27 +440,24 @@ Use this when joining a new project or auditing an existing system:
440
440
 
441
441
  ### Step 0: Discovery Pass (always first)
442
442
 
443
- Before designing anything, discover what already exists:
443
+ Before designing anything, discover what already exists. **Use monograph first** — fall back to grep only if monograph returns 0 results or the DB is not built.
444
+
445
+ ```
446
+ # PREFERRED: monograph-based discovery
447
+ monograph_query({ query: "route handler" }) # find all route entry points
448
+ monograph_query({ query: "worker job consumer" }) # find background processors
449
+ monograph_query({ query: "state transition status" })# find state machines
450
+ monograph_route_map({}) # list all HTTP routes with handlers
451
+ monograph_suggest({ task: "workflow entry points, workers, state machines, cron jobs" })
452
+ ```
444
453
 
445
454
  ```bash
446
- # Find all workflow entry points (adapt patterns to your framework)
455
+ # FALLBACK (only if monograph returns 0 results):
447
456
  grep -rn "router\.\(post\|put\|delete\|get\|patch\)" src/routes/ --include="*.ts" --include="*.js"
448
457
  grep -rn "@app\.\(route\|get\|post\|put\|delete\)" src/ --include="*.py"
449
- grep -rn "HandleFunc\|Handle(" cmd/ pkg/ --include="*.go"
450
-
451
- # Find all background workers / job processors
452
458
  find src/ -type f -name "*worker*" -o -name "*job*" -o -name "*consumer*" -o -name "*processor*"
453
-
454
- # Find all state transitions in the codebase
455
459
  grep -rn "status.*=\|\.status\s*=\|state.*=\|\.state\s*=" src/ --include="*.ts" --include="*.py" --include="*.go" | grep -v "test\|spec\|mock"
456
-
457
- # Find all database migrations
458
460
  find . -path "*/migrations/*" -type f | head -30
459
-
460
- # Find all infrastructure resources
461
- find . -name "*.tf" -o -name "docker-compose*.yml" -o -name "*.yaml" | xargs grep -l "resource\|service:" 2>/dev/null
462
-
463
- # Find all scheduled / cron jobs
464
461
  grep -rn "cron\|schedule\|setInterval\|@Scheduled" src/ --include="*.ts" --include="*.py" --include="*.go" --include="*.java"
465
462
  ```
466
463
 
@@ -245,17 +245,18 @@ describe('Performance Validation', () => {
245
245
 
246
246
  ### 1. Code Quality Validation
247
247
 
248
+ **Preferred: monograph-based code quality scan:**
249
+ ```
250
+ monograph_query({ query: "mock fake stub" }) # find mock implementations in prod code
251
+ monograph_query({ query: "TODO FIXME" }) # find unfinished work in critical paths
252
+ monograph_query({ query: "console log warn error" }) # find console statements
253
+ ```
254
+
255
+ **Fallback (if monograph returns 0 results or DB not built):**
248
256
  ```bash
249
- # No mock implementations in production code
250
257
  grep -r "mock\|fake\|stub" src/ --exclude-dir=__tests__ --exclude="*.test.*" --exclude="*.spec.*"
251
-
252
- # No TODO/FIXME in critical paths
253
258
  grep -r "TODO\|FIXME" src/ --exclude-dir=__tests__
254
-
255
- # No hardcoded test data
256
259
  grep -r "test@\|example\|localhost" src/ --exclude-dir=__tests__
257
-
258
- # No console.log statements
259
260
  grep -r "console\." src/ --exclude-dir=__tests__
260
261
  ```
261
262
 
@@ -47,7 +47,9 @@ You are **EvidenceQA**, a skeptical QA specialist who requires visual proof for
47
47
  # 2. Check what's actually built
48
48
  ls -la resources/views/ || ls -la *.html
49
49
 
50
- # 3. Reality check for claimed features
50
+ # 3. Reality check for claimed features (monograph-first, grep fallback)
51
+ # Preferred: monograph_query({ query: "luxury premium glass morphism" })
52
+ # Fallback:
51
53
  grep -r "luxury\|premium\|glass\|morphism" . --include="*.html" --include="*.css" --include="*.blade.php" || echo "NO PREMIUM FEATURES FOUND"
52
54
 
53
55
  # 4. Review comprehensive test results
@@ -326,12 +326,31 @@ RECENT_HIL=$(find . -maxdepth 3 \( -name "humaninloop*.md" -o -name "humaninloop
326
326
 
327
327
  After each run in tillend mode, evaluate whether this run produced **zero findings and zero actions**. The loop stops only when a complete round finds nothing new and makes no changes — not when the AI predicts there is nothing left.
328
328
 
329
- **You (the AI running the loop) must now assess your own output from this run.** Answer these two questions:
329
+ <EXTREMELY-IMPORTANT>
330
+ **Anti-premature-stop rules:**
331
+ - "I think the work is done" is NOT a reason to stop. Only the checks below decide.
332
+ - "There's nothing more to find" is a PREDICTION, not an observation. Predictions do not stop loops.
333
+ - You MUST run the git verification command below. If git shows changes, the round is non-empty. Period.
334
+ - Only a round where git shows NO changes AND you confirm zero findings AND zero actions qualifies as empty.
335
+ </EXTREMELY-IMPORTANT>
336
+
337
+ **Step 4a — Machine verification (REQUIRED — run this command before any self-assessment):**
338
+
339
+ ```bash
340
+ GIT_CHANGES=$(git diff --stat HEAD 2>/dev/null; git diff --cached --stat 2>/dev/null; git status --porcelain 2>/dev/null | grep -v '^\?\?' | head -20)
341
+ echo "GIT_CHANGES_DURING_RUN: ${GIT_CHANGES:-NONE}"
342
+ ```
343
+
344
+ If `GIT_CHANGES` is non-empty, files were modified — `TILLEND_EMPTY=false` regardless of self-assessment. Skip directly to "Otherwise" below.
345
+
346
+ **Step 4b — Self-assessment (only if git shows no changes):**
347
+
348
+ Only if `GIT_CHANGES` was empty, answer these two questions about this run:
330
349
 
331
350
  1. **Were any findings produced?** — issues found, problems detected, items identified, things flagged, errors reported, tasks discovered, security vulnerabilities found, etc.
332
- 2. **Were any actions taken?** — files edited, code fixed, tasks created, cards moved, commits made, content written, configs changed, etc.
351
+ 2. **Were any actions taken?** — tasks created, content written, configs changed anything not captured by git diff.
333
352
 
334
- **Set `TILLEND_EMPTY=true` only if BOTH answers are "no" zero findings AND zero actions this round.**
353
+ **Set `TILLEND_EMPTY=true` only if git shows no changes AND BOTH answers are "no".**
335
354
 
336
355
  **Important:** If this round found things AND fixed them all, `TILLEND_EMPTY=false`. The loop must run once more to verify the fixes didn't introduce new issues. A "clean" prediction after a productive round is not enough — only an actually empty round stops the loop.
337
356
 
@@ -49,4 +49,4 @@ curl -s -X POST "${CTRL_URL}/api/mastermind/event" \
49
49
  -d '{"type":"session:complete","session":"<sessionId>","domain":"architect","status":"<status>","domains":["architect"],"ts":'"$(date +%s)"'000}' || true
50
50
  ```
51
51
 
52
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
52
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -25,4 +25,4 @@ Invoke `Skill("mastermind-skills:autodev")` passing: brain_context, count, newfe
25
25
 
26
26
  After skill returns: follow _protocol.md Brain Write Procedure for domain `autodev`.
27
27
 
28
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
28
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:build")` passing: brain_context, prompt, projec
20
20
 
21
21
  After skill returns: follow _protocol.md Brain Write Procedure for domain `build`.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -66,10 +66,10 @@ Based on `STACK`, determine which specialist agents to run beyond the always-on
66
66
  - `Security Engineer` — injection, auth gaps, secrets exposure, CVE-prone patterns, OWASP Top 10
67
67
  - `Reality Checker` — evidence-based assessment: does the code actually do what it claims?
68
68
 
69
- **Run conditionally** — detect by running these checks and adding the agent if exit 0:
70
- - `Accessibility Auditor` — `find . -maxdepth 5 \( -name "*.html" -o -name "*.jsx" -o -name "*.tsx" \) -not -path "*/node_modules/*" | head -1 | grep -q .`
71
- - `API Tester` — `find . -maxdepth 5 \( -name "*.route.*" -o -name "openapi.yml" -o -name "openapi.json" -o -name "swagger.*" \) -not -path "*/node_modules/*" | head -1 | grep -q . || grep -rqEl "express\(|fastify|hono|koa|router\." --include="*.ts" --include="*.js" . 2>/dev/null`
72
- - `Database Optimizer` — `find . -maxdepth 5 \( -name "*.sql" -o -name "*migration*" -o -name "*schema*" \) -not -path "*/node_modules/*" | head -1 | grep -q . || grep -rqEl "prisma|typeorm|sequelize|drizzle|knex" --include="*.ts" --include="*.js" . 2>/dev/null`
69
+ **Run conditionally** — use `monograph_query` first to detect stack; fall back to find/grep if monograph returns 0 results:
70
+ - `Accessibility Auditor` — `monograph_query({ query: "html jsx tsx component" })` or `find . -maxdepth 5 \( -name "*.html" -o -name "*.jsx" -o -name "*.tsx" \) -not -path "*/node_modules/*" | head -1 | grep -q .`
71
+ - `API Tester` — `monograph_query({ query: "express fastify hono koa router route openapi swagger" })` or `find . -maxdepth 5 \( -name "*.route.*" -o -name "openapi.yml" -o -name "openapi.json" -o -name "swagger.*" \) -not -path "*/node_modules/*" | head -1 | grep -q . || grep -rqEl "express\(|fastify|hono|koa|router\." --include="*.ts" --include="*.js" . 2>/dev/null`
72
+ - `Database Optimizer` — `monograph_query({ query: "prisma typeorm sequelize drizzle knex sql migration schema" })` or `find . -maxdepth 5 \( -name "*.sql" -o -name "*migration*" -o -name "*schema*" \) -not -path "*/node_modules/*" | head -1 | grep -q . || grep -rqEl "prisma|typeorm|sequelize|drizzle|knex" --include="*.ts" --include="*.js" . 2>/dev/null`
73
73
  - `SRE` — `find . -maxdepth 3 \( -name "Dockerfile" -o -name "docker-compose*" -o -name "*.yml" -path "*/.github/workflows/*" \) | head -1 | grep -q .`
74
74
  - `Mobile App Builder` — `find . -maxdepth 3 \( -name "*.swift" -o -name "*.kt" \) | head -1 | grep -q . || grep -q "react-native" package.json 2>/dev/null`
75
75
 
@@ -311,4 +311,4 @@ If `ALL_HIL` is empty, omit the HIL section and congratulate:
311
311
 
312
312
  To repeat this command on a schedule, wrap it with `/mastermind:repeat` or use `--repeat N` / `--tillend` directly.
313
313
 
314
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
314
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -16,4 +16,4 @@ Invoke `Skill("mastermind-skills:debug")` passing: brain_context, problem_descri
16
16
 
17
17
  After skill returns: follow `_protocol.md` Brain Write Procedure for domain `debug`.
18
18
 
19
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
19
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -97,8 +97,8 @@ mcp__monomind__memory_store({ key: "...", value: "...", namespace: "..." })
97
97
  mcp__monomind__memory_search({ query: "...", namespace: "..." })
98
98
 
99
99
  // Knowledge graph
100
- mcp__monomind__graphify_suggest({ task: "..." })
101
- mcp__monomind__graphify_query({ query: "..." })
100
+ mcp__monomind__monograph_suggest({ task: "..." })
101
+ mcp__monomind__monograph_query({ query: "..." })
102
102
 
103
103
  // Swarm
104
104
  mcp__monomind__swarm_init({ topology: "hierarchical", maxAgents: 8, strategy: "specialized" })
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:idea")` passing: brain_context, prompt, project
20
20
 
21
21
  After skill returns: follow _protocol.md Brain Write Procedure for domain `idea`.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -339,4 +339,4 @@ Skill("mastermind-skills:do", "--monotask --space $SPACE_ID --board $TASK_BOARD_
339
339
 
340
340
  To repeat this command on a schedule, wrap it with `/mastermind:repeat` or use `--repeat N` / `--tillend` directly.
341
341
 
342
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
342
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -0,0 +1,14 @@
1
+ <!-- Export the Second Brain knowledge base as a portable OKF (Open Knowledge Format) bundle. -->
2
+
3
+ Parse `$ARGUMENTS` for:
4
+ - `--output <dir>` or `-o <dir>` → output directory (default: `.monomind/knowledge-export`)
5
+ - `--scope <name>` or `-s <name>` → knowledge scope (default: `shared`)
6
+ - Remaining positional arg → treated as output directory
7
+
8
+ Run the export:
9
+
10
+ ```bash
11
+ npx monomind doc export -o "<output_dir>" -s "<scope>"
12
+ ```
13
+
14
+ After completion, report what was exported and where. If 0 documents exported, suggest `monomind doc ingest <path>` first.
@@ -0,0 +1,15 @@
1
+ <!-- Import an OKF (Open Knowledge Format) bundle into the Second Brain knowledge base. -->
2
+
3
+ Parse `$ARGUMENTS` for:
4
+ - `--scope <name>` or `-s <name>` → knowledge scope (default: `shared`)
5
+ - Remaining positional arg → bundle directory path (REQUIRED)
6
+
7
+ If no bundle directory provided, ask: "Which directory contains the OKF bundle to import?"
8
+
9
+ Run the import:
10
+
11
+ ```bash
12
+ npx monomind doc ingest "<bundle_dir>" -s "<scope>"
13
+ ```
14
+
15
+ After completion, report files processed, chunks indexed, and any errors. If the bundle directory doesn't exist or contains no `.md` files, say so.
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:plan")` passing: brain_context, params, project
20
20
 
21
21
  After skill returns: follow `_protocol.md` Brain Write Procedure.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:research")` passing: brain_context, prompt, pro
20
20
 
21
21
  After skill returns: follow _protocol.md Brain Write Procedure for domain `research`.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -18,6 +18,17 @@ Default mode for this command: **auto** (unless `--confirm` flag present or inta
18
18
 
19
19
  Invoke `Skill("mastermind-skills:review")` passing: brain_context, prompt, project_name, board_id (create if needed), mode.
20
20
 
21
+ **After review findings are collected — AUTO-FIX STEP (mode = auto only):**
22
+
23
+ When `mode = auto` (the default): if the review produced any fixable findings (code issues, bugs, style problems, security vulnerabilities with clear fixes), apply the fixes immediately in this same run. Do not ask the user whether to fix — auto mode means fix without asking. Specifically:
24
+ 1. For each fixable finding, edit the file directly to resolve it.
25
+ 2. After all fixes are applied, output a summary: `[review] Auto-fixed N issues. Remaining M issues require manual intervention.`
26
+ 3. Non-fixable findings (architectural concerns, design questions, trade-off decisions) are reported but not acted on.
27
+
28
+ When `mode = confirm`: present findings and ask the user which to fix. This is the ONLY mode where asking is appropriate.
29
+
30
+ **When `--tillend` is active:** auto-fix is especially critical. Without it, the loop finds the same unfixed issues every round and either loops forever or the AI falsely declares an empty round. The tillend contract is: find → fix → verify (next round) → stop when clean.
31
+
21
32
  After skill returns: follow _protocol.md Brain Write Procedure for domain `review`.
22
33
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
34
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -133,7 +133,7 @@ curl -s -X POST "${CTRL_URL}/api/mastermind/event" \
133
133
  Follow _protocol.md Brain Write Procedure for domain `ops`.
134
134
 
135
135
 
136
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
136
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
137
137
 
138
138
  After the REPEAT POSTAMBLE completes, if a loop was started or continued (LOOP_ID is set), write the org name into the loop state file so the dashboard can detect running status:
139
139
  ```bash
@@ -20,4 +20,4 @@ Invoke `Skill("mastermind-skills:taskdev")` passing: brain_context, plan_file, p
20
20
 
21
21
  After skill returns: follow `_protocol.md` Brain Write Procedure.
22
22
 
23
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
23
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -16,4 +16,4 @@ Invoke `Skill("mastermind-skills:tdd")` passing: brain_context, feature_or_bug,
16
16
 
17
17
  After skill returns: follow `_protocol.md` Brain Write Procedure for domain `tdd`.
18
18
 
19
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
19
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -16,4 +16,4 @@ Invoke `Skill("mastermind-skills:verify")` passing: brain_context, claim_or_task
16
16
 
17
17
  After skill returns: follow `_protocol.md` Brain Write Procedure for domain `verify`.
18
18
 
19
- Invoke `Skill("mastermind-skills:_repeat")` now to execute the REPEAT POSTAMBLE. This is a required tool call do not skip it.
19
+ **MANDATORY — invoke `Skill("mastermind-skills:_repeat")` now.** This is required regardless of how the skill above completed, regardless of whether you think the work is done, regardless of whether you plan to end your response. For `--repeat N`: the count is non-negotiable — all N runs must happen. For `--tillend`: only a verified empty round (confirmed by git diff) stops the loop. Do not end your response without invoking this skill.
@@ -70,27 +70,23 @@ if (!entryPoint) {
70
70
  const dbPath = path.join(projectDir, '.monomind', 'monograph.db');
71
71
  if (fs.existsSync(dbPath)) {
72
72
  try {
73
- const mod = (() => {
74
- try { return require(path.join(projectDir, 'packages', '@monomind', 'monograph', 'dist', 'src', 'index.js')); } catch {}
75
- try { return require('@monoes/monograph'); } catch {}
76
- return null;
77
- })();
78
- if (mod && mod.openDb) {
79
- const db = mod.openDb(dbPath);
80
- try {
81
- const row = db.prepare("SELECT value FROM index_meta WHERE key='last_commit_hash'").get();
82
- if (row && row.value) {
83
- const { execSync } = require('child_process');
84
- const behind = parseInt(execSync('git rev-list --count ' + row.value + '..HEAD 2>/dev/null', {
85
- cwd: projectDir, encoding: 'utf-8', timeout: 2000
86
- }).trim(), 10) || 0;
87
- if (behind === 0) {
88
- console.log('[graph] index is fresh — skipping rebuild');
89
- process.exit(0);
90
- }
73
+ const Database = require(require.resolve('better-sqlite3', { paths: [path.dirname(entryPoint)] }));
74
+ const db = new Database(dbPath, { readonly: true, timeout: 5000 });
75
+ try {
76
+ const row = db.prepare("SELECT value FROM index_meta WHERE key='last_commit_hash'").get();
77
+ if (row && row.value && /^[0-9a-f]{7,40}$/i.test(row.value)) {
78
+ const { execFileSync } = require('child_process');
79
+ const out = execFileSync('git', ['rev-list', '--count', row.value + '..HEAD'], {
80
+ cwd: projectDir, encoding: 'utf-8', timeout: 2000, stdio: ['pipe', 'pipe', 'pipe']
81
+ }).trim();
82
+ const behind = parseInt(out, 10);
83
+ if (behind === 0) {
84
+ console.log('[graph] index is fresh skipping rebuild');
85
+ db.close();
86
+ process.exit(0);
91
87
  }
92
- } finally { mod.closeDb(db); }
93
- }
88
+ }
89
+ } finally { try { db.close(); } catch {} }
94
90
  } catch { /* can't check — proceed with build */ }
95
91
  }
96
92
 
@@ -65,44 +65,19 @@ module.exports = {
65
65
  );
66
66
  } catch (e) { /* non-fatal — never block a subagent from starting */ }
67
67
 
68
- // Subagent context inheritance — inject graph god nodes + parent's last
69
- // pre-resolved suggestions so the spawned agent inherits spatial map.
68
+ // monolean: compact single-line graph context instead of multi-line map.
69
+ // Subagents get task-relevant files only god nodes are noise for a focused task.
70
70
  try {
71
- var subDb = _openMonographDb();
72
- if (subDb) {
73
- try {
74
- var godRows = subDb.prepare(
75
- "SELECT n.name, n.label, n.file_path AS file, " +
76
- "(SELECT COUNT(*) FROM edges WHERE source_id=n.id OR target_id=n.id) AS deg " +
77
- "FROM nodes n " +
78
- "WHERE n.label NOT IN ('Concept') AND n.file_path IS NOT NULL AND n.file_path != '' " +
79
- "ORDER BY deg DESC LIMIT 5"
80
- ).all();
81
- if (godRows.length > 0) {
82
- console.log('[MONOGRAPH_SUBAGENT_CTX] Graph map inherited from parent:');
83
- for (var gi = 0; gi < godRows.length; gi++) {
84
- var gr = godRows[gi];
85
- console.log(' · ' + gr.name + ' [' + gr.label + '] — ' + (gr.file || '') + ' (deg ' + gr.deg + ')');
86
- }
87
- try {
88
- var subAgentDesc = hookInput.description || hookInput.prompt_description || '';
89
- if (subAgentDesc && subAgentDesc.length > 8) {
90
- var subHints = getMonographSuggestions(subAgentDesc, 3);
91
- if (subHints.length > 0) {
92
- console.log(' Top files for this subagent task:');
93
- for (var si2 = 0; si2 < subHints.length; si2++) {
94
- var sh = subHints[si2];
95
- console.log(' · ' + sh.name + ' [' + sh.label + '] — ' + (sh.file || ''));
96
- }
97
- }
98
- }
99
- } catch (_) {}
100
- console.log(' Use mcp__monomind__monograph_suggest / monograph_query in this subagent before grepping.');
101
- }
102
- } catch (e) { /* non-fatal */ }
71
+ var subAgentDesc = hookInput.description || hookInput.prompt_description || '';
72
+ if (subAgentDesc && subAgentDesc.length > 8) {
73
+ var subHints = getMonographSuggestions(subAgentDesc, 3);
74
+ if (subHints.length > 0) {
75
+ var parts = subHints.map(function(s) {
76
+ return s.name + ' [' + s.label + '] ' + (s.file || '');
77
+ });
78
+ console.log('[MONOGRAPH] Top files: ' + parts.join(' · '));
79
+ }
103
80
  }
104
81
  } catch (e) { /* non-fatal */ }
105
-
106
- console.log('[OK] Agent registered');
107
82
  },
108
83
  };
@@ -370,6 +370,84 @@ async function handleSubagentStop(hookInput) {
370
370
  ts: Date.now(),
371
371
  }) + '\n');
372
372
  }
373
+
374
+ // ── Wire captured interaction into EpisodicStore ────
375
+ try {
376
+ var episodicPath = path.join(CWD, '.monomind', 'episodic', 'episodes.jsonl');
377
+ var episodicDir = path.dirname(episodicPath);
378
+ if (!fs.existsSync(episodicDir)) fs.mkdirSync(episodicDir, { recursive: true });
379
+
380
+ // Append a lightweight episode entry directly (avoid importing @monomind/memory)
381
+ var episodeEntry = {
382
+ episodeId: require('crypto').randomUUID(),
383
+ sessionId: session || '',
384
+ runIds: [runId || 'unknown'],
385
+ summary: [
386
+ '[agent:' + (agentType || 'unknown') + ']',
387
+ summary ? summary.slice(0, 500) : '',
388
+ totalTin ? '[memory:write] tokens_in=' + totalTin : '',
389
+ totalTout ? '[memory:write] tokens_out=' + totalTout : ''
390
+ ].filter(Boolean).join('\n'),
391
+ startedAt: snap.ts || Date.now(),
392
+ endedAt: Date.now(),
393
+ agentSlugs: [agentType || 'unknown'],
394
+ taskTypes: [agentType || 'unknown'],
395
+ tokenEstimate: Math.ceil(((summary || '').length) / 4)
396
+ };
397
+ fs.appendFileSync(episodicPath, JSON.stringify(episodeEntry) + '\n', 'utf-8');
398
+ } catch (e) { /* non-fatal */ }
399
+
400
+ // ── Record agent interaction in Monograph SQLite ────────────────────────────
401
+ try {
402
+ var mgDbPath = path.join(CWD, '.monomind', 'monograph.db');
403
+ if (fs.existsSync(mgDbPath)) {
404
+ var monographMod = null;
405
+ var mgCandidates = [
406
+ path.join(CWD, 'node_modules/.pnpm/node_modules/@monoes/monograph'),
407
+ path.join(CWD, 'packages/node_modules/.pnpm/node_modules/@monoes/monograph'),
408
+ path.join(CWD, 'node_modules/@monoes/monograph'),
409
+ ];
410
+ for (var mi = 0; mi < mgCandidates.length; mi++) {
411
+ try { if (fs.existsSync(mgCandidates[mi])) { monographMod = require(mgCandidates[mi]); break; } } catch (e2) {}
412
+ }
413
+ if (!monographMod) { try { monographMod = require('@monoes/monograph'); } catch (e2) {} }
414
+ if (monographMod && monographMod.openDb) {
415
+ var mgDb = monographMod.openDb(mgDbPath);
416
+ try {
417
+ mgDb.prepare(
418
+ 'INSERT OR IGNORE INTO agent_interactions ' +
419
+ '(id, session_id, org_name, agent_type, parent_agent, prompt_summary, result_summary, tokens_in, tokens_out, cost_usd, success, duration_ms, timestamp) ' +
420
+ 'VALUES (@id, @session_id, @org_name, @agent_type, @parent_agent, @prompt_summary, @result_summary, @tokens_in, @tokens_out, @cost_usd, @success, @duration_ms, @timestamp)'
421
+ ).run({
422
+ id: require('crypto').randomUUID(),
423
+ session_id: session || '',
424
+ org_name: org || null,
425
+ agent_type: agentType || 'unknown',
426
+ parent_agent: null,
427
+ prompt_summary: agentDesc ? agentDesc.slice(0, 500) : null,
428
+ result_summary: summary ? summary.slice(0, 1000) : null,
429
+ tokens_in: totalTin || 0,
430
+ tokens_out: totalTout || 0,
431
+ cost_usd: costUsd || 0,
432
+ success: (function() {
433
+ // Determine success from result summary — errors/failures/exceptions indicate failure
434
+ if (summary) {
435
+ var sumLower = summary.toLowerCase();
436
+ if (sumLower.includes('error') || sumLower.includes('failed') || sumLower.includes('exception') || sumLower.includes('fatal')) {
437
+ return 0;
438
+ }
439
+ }
440
+ return 1;
441
+ })(),
442
+ duration_ms: snap.ts ? (Date.now() - snap.ts) : 0,
443
+ timestamp: Date.now(),
444
+ });
445
+ } finally {
446
+ if (monographMod.closeDb) monographMod.closeDb(mgDb);
447
+ }
448
+ }
449
+ }
450
+ } catch (e) { /* non-fatal — monograph may not be available */ }
373
451
  }
374
452
 
375
453
  // ─── Phase 3: PreToolUse accumulator (Issue 9) ────────────────────────────────
@@ -424,6 +502,38 @@ async function handlePostTool(hookInput) {
424
502
 
425
503
  const isBash = toolName === 'bash' || toolName === 'shell';
426
504
  const isEdit = toolName === 'edit' || toolName === 'write' || toolName === 'multiedit';
505
+ const isMemoryStore = toolName.includes('memory_store') || toolName.includes('memory_pattern');
506
+ const isMemorySearch = toolName.includes('memory_search') || toolName.includes('memory_retrieve');
507
+
508
+ // Track real memory ops (writes stats to session file)
509
+ if (isMemoryStore || isMemorySearch) {
510
+ try {
511
+ var sessionId = process.env.CLAUDE_SESSION_ID || '';
512
+ var statsPath = path.join(CWD, '.monomind', 'memory-ops-' + sessionId.slice(0, 16) + '.json');
513
+ var stats = { writes: 0, searches: 0, redundantWrites: 0, emptySearches: 0 };
514
+ try { stats = JSON.parse(fs.readFileSync(statsPath, 'utf-8')); } catch {}
515
+ if (isMemoryStore) {
516
+ stats.writes++;
517
+ // Detect duplicate: response contains "already exists" or "duplicate"
518
+ var respStr = JSON.stringify(toolResponse).toLowerCase();
519
+ if (respStr.includes('duplicate') || respStr.includes('already exists') || respStr.includes('skip')) {
520
+ stats.redundantWrites++;
521
+ }
522
+ }
523
+ if (isMemorySearch) {
524
+ stats.searches++;
525
+ // Detect empty results
526
+ var results = toolResponse.results || toolResponse.entries || toolResponse.data;
527
+ if (Array.isArray(results) && results.length === 0) {
528
+ stats.emptySearches++;
529
+ } else if (toolResponse.count === 0 || toolResponse.total === 0) {
530
+ stats.emptySearches++;
531
+ }
532
+ }
533
+ fs.mkdirSync(path.dirname(statsPath), { recursive: true });
534
+ fs.writeFileSync(statsPath, JSON.stringify(stats), 'utf-8');
535
+ } catch (e) { /* non-fatal */ }
536
+ }
427
537
 
428
538
  if (!isBash && !isEdit) return;
429
539