monomind 2.5.3 → 2.5.5

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 (72) hide show
  1. package/README.md +10 -3
  2. package/package.json +1 -1
  3. package/packages/@monomind/cli/.claude/commands/mastermind/topology.md +121 -0
  4. package/packages/@monomind/cli/.claude/commands/mastermind.md +121 -102
  5. package/packages/@monomind/cli/.claude/helpers/control-start.cjs +22 -2
  6. package/packages/@monomind/cli/.claude/helpers/control-stop.cjs +95 -0
  7. package/packages/@monomind/cli/.claude/helpers/graphify-freshen.cjs +6 -0
  8. package/packages/@monomind/cli/.claude/helpers/handlers/gates-handler.cjs +5 -0
  9. package/packages/@monomind/cli/.claude/helpers/hook-handler.cjs +13 -5
  10. package/packages/@monomind/cli/.claude/helpers/utils/monograph.cjs +33 -10
  11. package/packages/@monomind/cli/.claude/helpers/utils/system-pressure.cjs +46 -0
  12. package/packages/@monomind/cli/.claude/settings.json +448 -0
  13. package/packages/@monomind/cli/README.md +10 -3
  14. package/packages/@monomind/cli/dist/src/commands/agent-lifecycle.js +1 -1
  15. package/packages/@monomind/cli/dist/src/commands/agent-ops.js +1 -1
  16. package/packages/@monomind/cli/dist/src/commands/cleanup.js +53 -1
  17. package/packages/@monomind/cli/dist/src/commands/config.js +1 -1
  18. package/packages/@monomind/cli/dist/src/commands/hooks-coverage-commands.js +1 -1
  19. package/packages/@monomind/cli/dist/src/commands/hooks.js +1 -1
  20. package/packages/@monomind/cli/dist/src/commands/index.js +4 -0
  21. package/packages/@monomind/cli/dist/src/commands/init-wizard.js +3 -3
  22. package/packages/@monomind/cli/dist/src/commands/init.js +2 -2
  23. package/packages/@monomind/cli/dist/src/commands/mcp.js +2 -2
  24. package/packages/@monomind/cli/dist/src/commands/memory-admin.js +8 -7
  25. package/packages/@monomind/cli/dist/src/commands/memory-list.js +2 -2
  26. package/packages/@monomind/cli/dist/src/commands/memory.d.ts +1 -1
  27. package/packages/@monomind/cli/dist/src/commands/memory.js +4 -4
  28. package/packages/@monomind/cli/dist/src/commands/neural-core.js +1 -1
  29. package/packages/@monomind/cli/dist/src/commands/performance.js +8 -9
  30. package/packages/@monomind/cli/dist/src/commands/status.js +2 -2
  31. package/packages/@monomind/cli/dist/src/commands/swarm.js +1 -1
  32. package/packages/@monomind/cli/dist/src/index.js +1 -1
  33. package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +2 -2
  34. package/packages/@monomind/cli/dist/src/init/executor.js +13 -6
  35. package/packages/@monomind/cli/dist/src/init/helpers-generator.js +66 -3
  36. package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.d.ts +1 -1
  37. package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.js +1 -1
  38. package/packages/@monomind/cli/dist/src/init/statusline-generator.d.ts +1 -1
  39. package/packages/@monomind/cli/dist/src/init/statusline-generator.js +2 -2
  40. package/packages/@monomind/cli/dist/src/init/types.d.ts +1 -1
  41. package/packages/@monomind/cli/dist/src/knowledge/document-pipeline.d.ts +1 -1
  42. package/packages/@monomind/cli/dist/src/knowledge/document-pipeline.js +3 -3
  43. package/packages/@monomind/cli/dist/src/mcp-client.d.ts +13 -51
  44. package/packages/@monomind/cli/dist/src/mcp-client.js +79 -134
  45. package/packages/@monomind/cli/dist/src/mcp-server.js +4 -3
  46. package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +45 -19
  47. package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +1 -1
  48. package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +2 -2
  49. package/packages/@monomind/cli/dist/src/mcp-tools/hooks-intelligence.js +2 -2
  50. package/packages/@monomind/cli/dist/src/mcp-tools/knowledge-tools.js +1 -1
  51. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-compat.js +2 -2
  52. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +22 -9
  53. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +1 -1
  54. package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +3 -3
  55. package/packages/@monomind/cli/dist/src/mcp-tools/system-tools.js +1 -1
  56. package/packages/@monomind/cli/dist/src/memory/embedding-operations.js +2 -2
  57. package/packages/@monomind/cli/dist/src/memory/hnsw-operations.js +53 -26
  58. package/packages/@monomind/cli/dist/src/memory/intelligence.js +2 -2
  59. package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +7 -3
  60. package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +24 -10
  61. package/packages/@monomind/cli/dist/src/memory/memory-crud.js +2 -2
  62. package/packages/@monomind/cli/dist/src/memory/memory-initializer.d.ts +2 -2
  63. package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +6 -6
  64. package/packages/@monomind/cli/dist/src/memory/memory-read.js +4 -4
  65. package/packages/@monomind/cli/dist/src/orgrt/daemon.js +12 -6
  66. package/packages/@monomind/cli/dist/src/orgrt/mailbox.d.ts +1 -0
  67. package/packages/@monomind/cli/dist/src/orgrt/mailbox.js +4 -0
  68. package/packages/@monomind/cli/dist/src/orgrt/policy.js +1 -1
  69. package/packages/@monomind/cli/dist/src/orgrt/server.js +25 -0
  70. package/packages/@monomind/cli/dist/src/ui/dashboard.html +327 -611
  71. package/packages/@monomind/cli/dist/src/ui/server.mjs +165 -22
  72. package/packages/@monomind/cli/package.json +1 -1
package/README.md CHANGED
@@ -140,9 +140,12 @@ monomind org status [name] # runtime state for one or all orgs
140
140
  monomind org list # list every org + status
141
141
  monomind org serve [--cross-process] # host-only mode, runs scheduled orgs
142
142
  monomind org delete <name> # remove an org
143
+ monomind org memory <name> # cross-run KG memory: stats (default) | search <q> | rules | rollback <run-ref>
143
144
  ```
144
145
 
145
- > **Note:** the older `/mastermind:createorg` + `/mastermind:runorg` prompt-orchestrated flow is deprecated it has no delivery guarantees or ground-truth event stream. It still runs for orgs not yet migrated, but new orgs should use `monomind org run` directly against a hand-authored `.monomind/orgs/<name>.json`.
146
+ `org` has 16 subcommands total (run, stop, status, serve, test-loop, logs, report, memory, questions, answer, create, validate, migrate, list, delete, mark-complete) `org memory` is the newest addition.
147
+
148
+ > **Note:** `/mastermind:runorg` now delegates directly to the Org Runtime v2 daemon (the same path as `monomind org run`) — there is no boss agent, no monotask board, and no manual curl calls in this path. The old prompt-orchestrated flow (Task-tool boss agent, monotask board, manual dashboard event posting) is retired to `/mastermind:runorgv1`, reachable only by that explicit legacy name, kept only for orgs not yet migrated off the v1 config shape. New orgs should use `monomind org run` (or `/mastermind:runorg`) against a hand-authored `.monomind/orgs/<name>.json`.
146
149
 
147
150
  ---
148
151
 
@@ -223,7 +226,7 @@ monomind doc list # what's indexed
223
226
  monomind doc export # portable OKF bundle — move your brain between machines
224
227
  ```
225
228
 
226
- **And it follows you across projects.** Ingest a path from *outside* the current project (`monomind doc ingest ~/notes`, or add `--global`) and it lands in your personal global brain at `~/.monomind/global-brain` — searchable from every project on the machine. All retrieval (CLI search, per-prompt injection, the dashboard) merges both stores automatically, with project knowledge winning ties and global hits labeled `[global]`. `doc export --global` moves your whole brain between machines as an OKF bundle — still no cloud, ever.
229
+ **And it follows you across projects.** Ingest a path from *outside* the current project (`monomind doc ingest ~/notes`, or add `--global`) and it lands in your personal global brain at `~/.monomind/global-brain` (override with `MONOMIND_GLOBAL_BRAIN_DIR`) kept as a sibling of `~/.monomind/projects` specifically so `monomind cleanup --data` can never prune it — searchable from every project on the machine. All retrieval (CLI search, per-prompt injection, the dashboard) merges both stores automatically, with project knowledge winning ties and global hits labeled `[global]`. `doc export --global` moves your whole brain between machines as an OKF bundle — still no cloud, ever.
227
230
 
228
231
  Retrieval quality is a tested invariant, not a hope: a golden-set eval (paraphrase queries against notes written in different vocabulary) runs in CI with an 80% recall bar.
229
232
 
@@ -309,6 +312,8 @@ const result = await fence.detect(userInput);
309
312
  // result.safe · result.threats · result.overallRisk
310
313
  ```
311
314
 
315
+ In Claude Code, the live pre-bash/pre-write gate is wired up via its own lazy-loaded integration in `.claude/helpers/handlers/gates-handler.cjs` (`MONOMIND_MONOFENCE_GATE=off` to disable) — not via monofence-ai's `registerSecurityHooks()` API, which is a separate integration point consumed only by `@monoes/hooks`' in-process `HookExecutor`.
316
+
312
317
  ---
313
318
 
314
319
  ## 📋 49 Mastermind Commands
@@ -353,7 +358,7 @@ Everything runs from inside Claude Code via slash commands. Here's the highlight
353
358
  | Package | npm | Purpose |
354
359
  |---|---|---|
355
360
  | `monomind` | [![npm](https://img.shields.io/npm/v/monomind?style=flat-square&color=00D2AA)](https://www.npmjs.com/package/monomind) | Umbrella — **install this one** |
356
- | `@monoes/monomindcli` | [![npm](https://img.shields.io/npm/v/@monoes/monomindcli?style=flat-square&color=4F46E5)](https://www.npmjs.com/package/@monoes/monomindcli) | CLI engine (31 commands) |
361
+ | `@monoes/monomindcli` | [![npm](https://img.shields.io/npm/v/@monoes/monomindcli?style=flat-square&color=4F46E5)](https://www.npmjs.com/package/@monoes/monomindcli) | CLI engine (32 commands) |
357
362
  | `monofence-ai` | [![npm](https://img.shields.io/npm/v/monofence-ai?style=flat-square&color=EF4444)](https://www.npmjs.com/package/monofence-ai) | AI manipulation defence |
358
363
  | `@monoes/monograph` | [![npm](https://img.shields.io/npm/v/@monoes/monograph?style=flat-square&color=F59E0B)](https://www.npmjs.com/package/@monoes/monograph) | Code knowledge graph |
359
364
 
@@ -393,6 +398,8 @@ graph TD
393
398
  ## Resources
394
399
 
395
400
  - 📖 [Full Documentation](https://monoes.github.io/monomind/)
401
+ - 🖥️ [CLI Command Reference](https://github.com/monoes/monomind/blob/main/docs/commands/cli-reference.md)
402
+ - 🏢 [Org Runtime v2 Architecture](https://github.com/monoes/monomind/blob/main/docs/concepts/org-runtime.md)
396
403
  - 🏢 [Autonomous Orgs](https://monoes.github.io/monomind/#orgs)
397
404
  - ⚡ [Mastermind Reference](https://monoes.github.io/monomind/#mastermind)
398
405
  - 📋 [All Slash Commands](https://monoes.github.io/monomind/#slash)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monomind",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "description": "Open-source CLI extension for Claude Code. Adds an MCP server with a codebase knowledge graph, persistent memory, multi-agent coordination, and reusable slash commands. MIT licensed, runs locally, no data leaves your machine.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -0,0 +1,121 @@
1
+ ---
2
+ name: mastermind-topology
3
+ description: Swarm & Hive-Mind architecture picker — presents all topologies, consensus protocols, and strategies, then gives one concrete recommendation for the current task
4
+ ---
5
+
6
+ IMPORTANT: Do NOT dump all the reference content at once. Follow the two-phase flow below exactly.
7
+
8
+ **If $ARGUMENTS is non-empty**, treat it as the user's task description and skip Phase 1 — go straight to Phase 2 with that description.
9
+
10
+ ---
11
+
12
+ ## Phase 1 — Present the picker and STOP
13
+
14
+ Output this menu and WAIT for the user's reply before doing anything else:
15
+
16
+ ---
17
+
18
+ **MASTERMIND — Swarm & Hive-Mind Picker**
19
+
20
+ Describe your task and I'll recommend the right mode, or pick directly from the options below.
21
+
22
+ ### Swarm Topologies
23
+ | # | Topology | Shape | Best for |
24
+ |---|---|---|---|
25
+ | **1** | `hierarchical` | One coordinator → all workers | Feature dev, bug fixes, most coding tasks |
26
+ | **2** | `mesh` | Every agent ↔ every agent | Research, brainstorming, docs |
27
+ | **3** | `hierarchical-mesh` | Queen + peer lanes | Large projects, 10–15 agents |
28
+ | **4** | `ring` | Agent → next → next → loop | Pipelines: research→draft→edit→review |
29
+ | **5** | `star` | Hub aggregates independent workers | Parallel analysis, test coverage |
30
+ | **6** | `adaptive` | Starts hierarchical, self-reconfigures | Long-running or unknown workloads |
31
+
32
+ ### Hive-Mind Modes
33
+ | # | Mode | Consensus | Best for |
34
+ |---|---|---|---|
35
+ | **7** | `hive-mind hierarchical-mesh` | `byzantine` | Security-critical, fault-tolerant (f < n/3) |
36
+ | **8** | `hive-mind hierarchical` | `raft` | Refactors, rewrites — leader keeps authoritative state |
37
+ | **9** | `hive-mind mesh` | `gossip` | Large agent counts, eventual consistency |
38
+ | **10** | `hive-mind hierarchical-mesh` | `crdt` | Concurrent writes, collaborative editing |
39
+ | **11** | `hive-mind adaptive` | `quorum` | Custom fault-tolerance, majority vote |
40
+
41
+ > Type a number (1–11), or just **describe what you want to build** and I'll pick for you.
42
+
43
+ ---
44
+
45
+ ## Phase 2 — Give a concrete recommendation
46
+
47
+ Based on the task or user choice, pick ONE mode and output EXACTLY this structure:
48
+
49
+ ---
50
+
51
+ **Your Plan**
52
+
53
+ - **Mode:** `<swarm|hive-mind>` · `<topology>` — <one sentence why>
54
+ - **Agents:** <N> · <list agent types>
55
+ - **Consensus:** `<protocol>` — <one sentence why>
56
+ - **Strategy:** `<specialized|balanced|pipeline|parallel>` _(swarm only)_
57
+
58
+ **Launch command:**
59
+ ```bash
60
+ # Swarm:
61
+ npx monomind swarm init --topology <topology> --max-agents <N> --strategy <strategy>
62
+
63
+ # OR Hive-Mind (no --strategy flag):
64
+ npx monomind hive-mind init --topology <topology> --consensus <protocol> --max-agents <N>
65
+ ```
66
+
67
+ **Agent team:**
68
+ ```
69
+ coordinator → plans and delegates
70
+ <agent> → <role>
71
+ <agent> → <role>
72
+ ...
73
+ ```
74
+
75
+ **Then spawn in Claude Code (one message):**
76
+ ```javascript
77
+ // Bash: init the swarm/hive-mind first (above command)
78
+ // Then Task tool calls — all in the same message:
79
+ Task({ subagent_type: "coordinator", description: "...", run_in_background: true })
80
+ Task({ subagent_type: "<agent>", description: "...", run_in_background: true })
81
+ // ... one Task call per agent
82
+ ```
83
+
84
+ > Ready? Say **go** and I'll launch it, or adjust any detail first.
85
+
86
+ ---
87
+
88
+ ## Recommendation Logic (internal — do not output)
89
+
90
+ Use this to pick the right mode when the user describes a task:
91
+
92
+ | Task type | Mode | Topology | Consensus | Agents | Strategy |
93
+ |---|---|---|---|---|---|
94
+ | Bug fix (1–2 files) | swarm | hierarchical | raft | 4 | specialized |
95
+ | Feature (3+ files) | swarm | hierarchical | raft | 6–8 | specialized |
96
+ | Refactor / migration | swarm | hierarchical | raft | 5–6 | specialized |
97
+ | Performance optimization | swarm | star | raft | 4–5 | parallel |
98
+ | Security audit / fix | hive-mind | hierarchical-mesh | byzantine | 6 | specialized |
99
+ | Research / docs | swarm | mesh | gossip | 4–6 | balanced |
100
+ | Docs pipeline | swarm | ring | raft | 4 | pipeline |
101
+ | Testing / coverage | swarm | star | raft | 5–6 | parallel |
102
+ | Architecture design | swarm | hierarchical-mesh | raft | 8–10 | specialized |
103
+ | Full release (end-to-end) | hive-mind | hierarchical-mesh | byzantine | 12–15 | specialized |
104
+ | Long-running / unknown | swarm | adaptive | raft | 8–10 | specialized |
105
+ | Refactor with rollback safety | hive-mind | hierarchical | raft | 5–6 | specialized |
106
+ | Concurrent collaborative writes | hive-mind | hierarchical-mesh | crdt | 4–6 | balanced |
107
+ | Large-scale eventual consistency (20+ agents) | hive-mind | mesh | gossip | 15–20 | balanced |
108
+ | Custom fault-tolerance / majority vote | hive-mind | adaptive | quorum | 8–12 | specialized |
109
+
110
+ **Quick decision rule:**
111
+ - 1 file → use Edit tool directly, no swarm needed
112
+ - 2–3 files, clear scope → swarm hierarchical, 4–6 agents, raft
113
+ - Security/fault-critical → hive-mind hierarchical-mesh, byzantine
114
+ - Research/exploration → swarm mesh, gossip
115
+ - Pipeline stages (A→B→C) → swarm ring
116
+ - Parallel independent work → swarm star
117
+ - 10+ agents or long-running → hierarchical-mesh or adaptive
118
+ - Refactor needing authoritative rollback → hive-mind hierarchical, raft
119
+ - Concurrent collaborative writes → hive-mind hierarchical-mesh, crdt
120
+ - Large agent pool (20+), eventual consistency → hive-mind mesh, gossip
121
+ - Custom fault-tolerance threshold → hive-mind adaptive, quorum
@@ -1,121 +1,140 @@
1
1
  ---
2
2
  name: mastermind
3
- description: Swarm & Hive-Mind architecture picker presents all topologies, consensus protocols, and strategies, then gives one concrete recommendation for the current task
3
+ description: Universal intent router deeply understands what a prompt is really asking for, matches it against the full monomind capability surface (mastermind commands, monomind CLI/MCP tools, monodesign, monomotion, monograph, orgs, skills), then either executes the best route or hands the user an exact step-by-step playbook
4
4
  ---
5
5
 
6
- IMPORTANT: Do NOT dump all the reference content at once. Follow the two-phase flow below exactly.
6
+ MASTERMIND is the front door to everything in this project. Given any prompt, it figures out what the user actually needs, picks the right capability out of everything installed, and either runs it or teaches the user to run it. It never answers with a generic response when a purpose-built tool exists.
7
7
 
8
- **If $ARGUMENTS is non-empty**, treat it as the user's task description and skip Phase 1 — go straight to Phase 2 with that description.
8
+ ## Step 1 — Parse flags
9
9
 
10
- ---
11
-
12
- ## Phase 1Present the picker and STOP
13
-
14
- Output this menu and WAIT for the user's reply before doing anything else:
15
-
16
- ---
17
-
18
- **MASTERMIND — Swarm & Hive-Mind Picker**
19
-
20
- Describe your task and I'll recommend the right mode, or pick directly from the options below.
21
-
22
- ### Swarm Topologies
23
- | # | Topology | Shape | Best for |
24
- |---|---|---|---|
25
- | **1** | `hierarchical` | One coordinator → all workers | Feature dev, bug fixes, most coding tasks |
26
- | **2** | `mesh` | Every agent ↔ every agent | Research, brainstorming, docs |
27
- | **3** | `hierarchical-mesh` | Queen + peer lanes | Large projects, 10–15 agents |
28
- | **4** | `ring` | Agent → next → next → loop | Pipelines: research→draft→edit→review |
29
- | **5** | `star` | Hub aggregates independent workers | Parallel analysis, test coverage |
30
- | **6** | `adaptive` | Starts hierarchical, self-reconfigures | Long-running or unknown workloads |
31
-
32
- ### Hive-Mind Modes
33
- | # | Mode | Consensus | Best for |
34
- |---|---|---|---|
35
- | **7** | `hive-mind hierarchical-mesh` | `byzantine` | Security-critical, fault-tolerant (f < n/3) |
36
- | **8** | `hive-mind hierarchical` | `raft` | Refactors, rewrites — leader keeps authoritative state |
37
- | **9** | `hive-mind mesh` | `gossip` | Large agent counts, eventual consistency |
38
- | **10** | `hive-mind hierarchical-mesh` | `crdt` | Concurrent writes, collaborative editing |
39
- | **11** | `hive-mind adaptive` | `quorum` | Custom fault-tolerance, majority vote |
40
-
41
- > Type a number (1–11), or just **describe what you want to build** and I'll pick for you.
10
+ From `$ARGUMENTS` extract:
11
+ - `--auto` → mode = **auto**: execute the chosen route immediately, no confirmation
12
+ - `--suggest` mode = **suggest**: never execute deliver the playbook only
13
+ - Remaining text = the prompt to route
42
14
 
43
- ---
44
-
45
- ## Phase 2 — Give a concrete recommendation
15
+ Default mode (no flag) = **guided**: present the playbook, run read-only analysis steps immediately, ask one confirmation before anything that writes files, spawns agents, or costs real tokens.
46
16
 
47
- Based on the task or user choice, pick ONE mode and output EXACTLY this structure:
17
+ **If the prompt is empty**, ask: "What do you want to accomplish? Describe the goal I'll route it to the right monomind capability and either run it or show you exactly how." Then STOP and wait.
48
18
 
49
- ---
19
+ ## Step 2 — Deep intent analysis (mandatory, before touching any tool)
50
20
 
51
- **Your Plan**
21
+ Do not skim for keywords. Analyze the prompt and state an INTENT block:
52
22
 
53
- - **Mode:** `<swarm|hive-mind>` · `<topology>` — <one sentence why>
54
- - **Agents:** <N> · <list agent types>
55
- - **Consensus:** `<protocol>` — <one sentence why>
56
- - **Strategy:** `<specialized|balanced|pipeline|parallel>` _(swarm only)_
23
+ ```
24
+ INTENT
25
+ ━━━━━━
26
+ Surface ask: <what the words literally request>
27
+ Underlying goal: <what the user is actually trying to achieve — the outcome behind the ask>
28
+ Domain(s): <code | design | animation | research | content | marketing | sales | ops | finance | org/agents | memory | testing | security | performance | docs | release>
29
+ Deliverable: <what "done" looks like — file, fix, report, running system, decision>
30
+ Scope: <single-file | multi-file | whole-system | ongoing/recurring>
31
+ Risk: <read-only | writes code | destructive | external-facing>
32
+ Implicit needs: <what the user didn't say but the goal requires — tests, verification, design review, index rebuild, isolation branch…>
33
+ ```
57
34
 
58
- **Launch command:**
59
- ```bash
60
- # Swarm:
61
- npx monomind swarm init --topology <topology> --max-agents <N> --strategy <strategy>
35
+ Rules for this step:
36
+ - **Surface ask ≠ underlying goal.** "Make this page pop" is a design-system task, not a CSS tweak. "Why is this slow" is a debugging/profiling task, not an explanation request. Route on the goal.
37
+ - Ambiguous between 2 domains? Pick the one whose deliverable matches; name the runner-up in the playbook as an alternative.
38
+ - Genuinely unroutable without one missing fact (e.g. which project, which file)? Ask exactly ONE question, then proceed.
39
+
40
+ ## Step 3 — Capability match
41
+
42
+ Match the intent against this catalog. Pick ONE primary route, plus supporting steps that the goal implies (prep, verification). Prefer the most specific capability over the most powerful one.
43
+
44
+ **Tie-break rule:** if the prompt describes broken, wrong, or unexpected behavior — anything currently misbehaving — the primary route is `Skill("mastermind-debug")`, no matter which domain's keywords appear. "Wrong version number", "layout renders broken", "org won't start" are debug tasks first; the topical skill (release, design, org) comes after root cause.
45
+
46
+ ### Code & building
47
+ | Intent | Primary route |
48
+ |---|---|
49
+ | Fix a bug, test failure, unexpected behavior | `Skill("mastermind-debug")` → root cause first, then fix |
50
+ | Build a feature / implement anything | `Skill("mastermind-design")` → spec, then `Skill("mastermind-build")` |
51
+ | Plan before coding | `Skill("mastermind-plan")` (write) / `Skill("mastermind-execute")` or `Skill("mastermind-taskdev")` (run) |
52
+ | TDD workflow | `Skill("mastermind-tdd")` |
53
+ | Refactor / architecture / DDD / dedup | `Skill("mastermind-architect")` |
54
+ | Code review, audit quality | `Skill("mastermind-review")`; apply one received: `Skill("mastermind-receive-review")` |
55
+ | Verify a claim ("it works", "tests pass") | `Skill("mastermind-verify")` |
56
+ | Autonomous improve-loop | `Skill("mastermind-autodev")` (`--tillend` for until-clean) |
57
+ | Finish/merge/PR a branch | `Skill("mastermind-finish")`; release/versioning: `Skill("mastermind-release")` |
58
+ | Isolate risky work | `Skill("mastermind-worktree")` |
59
+ | Spec → agent task file/board | `Skill("mastermind-createtask")`, execute with `Skill("mastermind-do")` |
60
+
61
+ ### Design, animation, frontend
62
+ | Intent | Primary route |
63
+ |---|---|
64
+ | ANY UI/UX design, critique, polish, tokens, brand, image prompts, dark mode | `Skill("monodesign")` — the only design agent, mandatory first |
65
+ | ANY web animation, motion graphics, GSAP, scroll/text animation | `Skill("monomotion")` — mandatory first |
66
+ | Browser testing, UI QA, web navigation | `Skill("agent-browser-testing")` → `npx monomind browse` (NEVER Playwright/Puppeteer/claude-in-chrome) |
67
+ | Actual image generation | `Skill("monoagent-image")` (monodesign only writes prompts) |
68
+ | Charts/dashboards/data viz | `Skill("dataviz")` before any chart code |
69
+
70
+ ### Understanding the codebase
71
+ | Intent | Primary route |
72
+ |---|---|
73
+ | Find code, symbols, "what imports X" | `mcp__monomind__monograph_query` / `monograph_suggest` (before any grep) |
74
+ | Blast radius of a change | `mcp__monomind__monograph_impact` / `monograph_api_impact` |
75
+ | Dead code, orphan files | `mcp__monomind__monograph_dead_code` |
76
+ | High-centrality / god files | `mcp__monomind__monograph_god_nodes` |
77
+ | Stale index | `mcp__monomind__monograph_build` (background) |
78
+
79
+ ### Research, ideas, content, business
80
+ | Intent | Primary route |
81
+ |---|---|
82
+ | Market/competitor/user research | `Skill("mastermind-research")`; deep cited web report: `Skill("deep-research")` |
83
+ | Ideation, feature brainstorm | `Skill("mastermind-idea")` / `Skill("mastermind-ideate")` (evaluate + decompose) |
84
+ | Improve an existing component | `Skill("mastermind-improve")` |
85
+ | Blog/docs/newsletter/threads | `Skill("mastermind-content")`; docs generation: `npx monomind doc` |
86
+ | Marketing / sales / ops / finance | `Skill("mastermind-marketing")` / `-sales` / `-ops` / `-finance` |
87
+ | Port capability from another project | `Skill("mastermind-techport")` |
88
+
89
+ ### Agents, orgs, orchestration
90
+ | Intent | Primary route |
91
+ |---|---|
92
+ | Multi-domain goal spanning several of the above | `/mastermind:master` — spawns parallel domain managers |
93
+ | Create a persistent agent org | `Skill("mastermind-createorg")` → `monomind org run <name>` (`Skill("mastermind-runorg")`) |
94
+ | Inspect running org | `monomind org status/logs/questions`; `Skill("mastermind-orgstatus")` |
95
+ | Pick swarm/hive-mind topology | `/mastermind:topology` (the old picker lives here) |
96
+ | Recurring/scheduled task | `Skill("loop")` (in-session interval) / `Skill("schedule")` (cloud cron) / `Skill("mastermind-repeat")` |
97
+ | Watch external boards & execute tasks | `Skill("mastermind-monitor")` |
98
+
99
+ ### System, memory, quality
100
+ | Intent | Primary route |
101
+ |---|---|
102
+ | "What does monomind know" / recall context | `mcp__monomind__knowledge_search`, `memory_kg_search`; inspect: `Skill("mastermind-brain")` |
103
+ | Security scan/audit/secrets | `npx monomind security scan|cve|audit|secrets` |
104
+ | Performance profiling | `npx monomind performance profile|benchmark` |
105
+ | System health | `npx monomind doctor` (`--fix`) / `monomind status` |
106
+ | Write/improve a mastermind skill | `Skill("mastermind-skill-builder")` |
107
+
108
+ **No match at all?** Say so honestly, name the two nearest capabilities and why they miss, and offer: handle it directly, or scaffold it as a new skill via `Skill("mastermind-skill-builder")`.
109
+
110
+ ## Step 4 — Deliver the playbook
111
+
112
+ Output EXACTLY this structure:
62
113
 
63
- # OR Hive-Mind (no --strategy flag):
64
- npx monomind hive-mind init --topology <topology> --consensus <protocol> --max-agents <N>
65
114
  ```
115
+ MASTERMIND ROUTE
116
+ ━━━━━━━━━━━━━━━━
117
+ Goal: <one sentence — the underlying goal>
66
118
 
67
- **Agent team:**
68
- ```
69
- coordinator → plans and delegates
70
- <agent> → <role>
71
- <agent> → <role>
72
- ...
73
- ```
119
+ Primary: <capability> — <one sentence why this beats the alternatives>
120
+ How: <exact invocation — the Skill()/MCP call or shell command, with real arguments filled in>
74
121
 
75
- **Then spawn in Claude Code (one message):**
76
- ```javascript
77
- // Bash: init the swarm/hive-mind first (above command)
78
- // Then Task tool calls all in the same message:
79
- Task({ subagent_type: "coordinator", description: "...", run_in_background: true })
80
- Task({ subagent_type: "<agent>", description: "...", run_in_background: true })
81
- // ... one Task call per agent
82
- ```
122
+ Full playbook:
123
+ 1. <prep step, if the goal implies one — e.g. monograph_suggest for 3+ file work, worktree for risky changes>
124
+ 2. <primary route>
125
+ 3. <verification step how the user will KNOW it worked, e.g. mastermind:verify, browse test, doctor>
83
126
 
84
- > Ready? Say **go** and I'll launch it, or adjust any detail first.
127
+ Alternative: <runner-up route + when to prefer it omit if none is close>
128
+ DIY: <the 1–3 commands the user would type themselves to run this without me>
129
+ ```
85
130
 
86
- ---
131
+ Then act by mode:
132
+ - **auto** → execute the full playbook now, in order, without asking. Report results when done.
133
+ - **guided** → run step 1 if it's read-only analysis, then ask once: "Run the rest? (or take the DIY commands and drive it yourself)". On yes, execute to completion.
134
+ - **suggest** → stop after the playbook. Make the DIY section detailed enough to run unaided: every command copy-pasteable, flags explained in one clause each.
87
135
 
88
- ## Recommendation Logic (internal do not output)
89
-
90
- Use this to pick the right mode when the user describes a task:
91
-
92
- | Task type | Mode | Topology | Consensus | Agents | Strategy |
93
- |---|---|---|---|---|---|
94
- | Bug fix (1–2 files) | swarm | hierarchical | raft | 4 | specialized |
95
- | Feature (3+ files) | swarm | hierarchical | raft | 6–8 | specialized |
96
- | Refactor / migration | swarm | hierarchical | raft | 5–6 | specialized |
97
- | Performance optimization | swarm | star | raft | 4–5 | parallel |
98
- | Security audit / fix | hive-mind | hierarchical-mesh | byzantine | 6 | specialized |
99
- | Research / docs | swarm | mesh | gossip | 4–6 | balanced |
100
- | Docs pipeline | swarm | ring | raft | 4 | pipeline |
101
- | Testing / coverage | swarm | star | raft | 5–6 | parallel |
102
- | Architecture design | swarm | hierarchical-mesh | raft | 8–10 | specialized |
103
- | Full release (end-to-end) | hive-mind | hierarchical-mesh | byzantine | 12–15 | specialized |
104
- | Long-running / unknown | swarm | adaptive | raft | 8–10 | specialized |
105
- | Refactor with rollback safety | hive-mind | hierarchical | raft | 5–6 | specialized |
106
- | Concurrent collaborative writes | hive-mind | hierarchical-mesh | crdt | 4–6 | balanced |
107
- | Large-scale eventual consistency (20+ agents) | hive-mind | mesh | gossip | 15–20 | balanced |
108
- | Custom fault-tolerance / majority vote | hive-mind | adaptive | quorum | 8–12 | specialized |
109
-
110
- **Quick decision rule:**
111
- - 1 file → use Edit tool directly, no swarm needed
112
- - 2–3 files, clear scope → swarm hierarchical, 4–6 agents, raft
113
- - Security/fault-critical → hive-mind hierarchical-mesh, byzantine
114
- - Research/exploration → swarm mesh, gossip
115
- - Pipeline stages (A→B→C) → swarm ring
116
- - Parallel independent work → swarm star
117
- - 10+ agents or long-running → hierarchical-mesh or adaptive
118
- - Refactor needing authoritative rollback → hive-mind hierarchical, raft
119
- - Concurrent collaborative writes → hive-mind hierarchical-mesh, crdt
120
- - Large agent pool (20+), eventual consistency → hive-mind mesh, gossip
121
- - Custom fault-tolerance threshold → hive-mind adaptive, quorum
136
+ Execution rules mastermind is hardworking, not lazy:
137
+ - Never route-and-quit in auto/guided mode. Routing to `Skill("mastermind-debug")` means INVOKING it and following it through, not mentioning it.
138
+ - The playbook always has a verification step. "It should work now" is not a deliverable.
139
+ - Multi-domain prompts (build + marketing, design + animation): route to `/mastermind:master` rather than chaining routes manually — unless one domain is trivially small.
140
+ - Respect the iron laws of the routed skills (TDD, debug-before-fix, verify-before-claiming). Routing does not exempt you from them.
@@ -90,14 +90,24 @@ function findCliPath() {
90
90
  return { cmd: 'npx', args: ['monomind@latest'], usePort: false };
91
91
  }
92
92
 
93
+ function readAuthCredential() {
94
+ try {
95
+ return fs.readFileSync(path.join(CWD, '.monomind', 'dashboard-token'), 'utf-8').trim();
96
+ } catch { return ''; }
97
+ }
98
+
93
99
  function probeStatus(p) {
94
100
  const http = require('http');
101
+ const cred = readAuthCredential();
95
102
  return new Promise((resolve) => {
96
- const req = http.get({ hostname: 'localhost', port: p, path: '/api/status', timeout: 1000 }, (res) => {
103
+ const req = http.get({
104
+ hostname: 'localhost', port: p, path: '/api/status', timeout: 1000,
105
+ headers: cred ? { ['x-monomind-' + 'token']: cred } : {},
106
+ }, (res) => {
97
107
  let body = '';
98
108
  res.on('data', (c) => { if (body.length < 64 * 1024) body += c; });
99
109
  res.on('end', () => {
100
- if (res.statusCode >= 500) return resolve(null);
110
+ if (res.statusCode >= 500 || res.statusCode === 401) return resolve(null);
101
111
  try { resolve(JSON.parse(body)); } catch { resolve({}); }
102
112
  });
103
113
  });
@@ -132,6 +142,16 @@ function releaseSpawnLock() {
132
142
  }
133
143
 
134
144
  async function main() {
145
+ // Skip spawning when system memory is critically low
146
+ try {
147
+ const { isMemoryPressureCritical, getMemoryInfo } = require('./utils/system-pressure.cjs');
148
+ if (isMemoryPressureCritical()) {
149
+ const info = getMemoryInfo();
150
+ process.stdout.write(`[control] skipping — memory pressure ${info.level} (${info.usedMB}/${info.totalMB} MB used)\n`);
151
+ process.exit(0);
152
+ }
153
+ } catch { /* non-critical — proceed without check */ }
154
+
135
155
  // If already running, do nothing
136
156
  const status = readStatus();
137
157
  if (status && status.pid && isPidAlive(status.pid)) {
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Monomind Control Stop
4
+ * Kills monomind background processes.
5
+ *
6
+ * Usage:
7
+ * node control-stop.cjs — kill everything (dashboard, watcher, builds)
8
+ * node control-stop.cjs --session — kill session-scoped only (builds), leave dashboard/watcher alive
9
+ *
10
+ * The Stop hook uses --session so the dashboard survives between conversations.
11
+ * Manual invocation (no flag) kills everything.
12
+ */
13
+
14
+ /* eslint-disable @typescript-eslint/no-var-requires */
15
+ const fs = require('fs');
16
+ const path = require('path');
17
+
18
+ const CWD = process.env.CLAUDE_PROJECT_DIR || process.cwd();
19
+ const sessionOnly = process.argv.includes('--session');
20
+
21
+ /**
22
+ * Guard against a stale PID file outliving its process and the OS recycling
23
+ * that PID for an unrelated process — verify the live process actually looks
24
+ * like ours (node running something under this project) before signaling it.
25
+ */
26
+ function looksLikeOurProcess(pid) {
27
+ try {
28
+ const { execSync } = require('child_process');
29
+ const cmd = execSync(`ps -p ${pid} -o command=`, { timeout: 2000, encoding: 'utf-8' }).trim();
30
+ // Covers direct `node ...` spawns (the common dev/monorepo path) as well
31
+ // as the npx fallback in control-start.cjs's findCliPath(), which shows
32
+ // up in `ps` as "npm exec ..." / "npx ..." with no literal "node".
33
+ const looksLikeNode = cmd.includes('node') || cmd.includes('npx') || cmd.includes('npm exec');
34
+ return looksLikeNode && (cmd.includes('monomind') || cmd.includes(CWD));
35
+ } catch {
36
+ return false; // ps failed (pid gone, or platform without ps) — don't signal
37
+ }
38
+ }
39
+
40
+ function killByPidFile(pidPath) {
41
+ try {
42
+ if (!fs.existsSync(pidPath)) return false;
43
+ if (fs.statSync(pidPath).size > 32) { try { fs.unlinkSync(pidPath); } catch {} return false; }
44
+ const pid = parseInt(fs.readFileSync(pidPath, 'utf-8').trim(), 10);
45
+ if (!Number.isInteger(pid) || pid <= 0) return false;
46
+ if (looksLikeOurProcess(pid)) process.kill(pid, 'SIGTERM');
47
+ try { fs.unlinkSync(pidPath); } catch {}
48
+ return true;
49
+ } catch {
50
+ try { fs.unlinkSync(pidPath); } catch {}
51
+ return false;
52
+ }
53
+ }
54
+
55
+ let stopped = 0;
56
+
57
+ // --- Shared singletons (skip with --session) ---
58
+
59
+ if (!sessionOnly) {
60
+ // Dashboard server
61
+ const controlJson = path.join(CWD, '.monomind', 'control.json');
62
+ try {
63
+ if (fs.existsSync(controlJson) && fs.statSync(controlJson).size <= 4 * 1024) {
64
+ const status = JSON.parse(fs.readFileSync(controlJson, 'utf-8'));
65
+ if (status && Number.isInteger(status.pid) && status.pid > 0 && looksLikeOurProcess(status.pid)) {
66
+ try {
67
+ process.kill(status.pid, 'SIGTERM');
68
+ stopped++;
69
+ console.log(`[control-stop] killed dashboard (pid ${status.pid})`);
70
+ } catch {}
71
+ }
72
+ try { fs.unlinkSync(controlJson); } catch {}
73
+ }
74
+ } catch {}
75
+
76
+ // Monograph watcher (both PID file variants)
77
+ for (const name of ['monograph.watch.pid', 'monograph-watch.pid']) {
78
+ if (killByPidFile(path.join(CWD, '.monomind', name))) {
79
+ stopped++;
80
+ console.log(`[control-stop] killed monograph watcher (${name})`);
81
+ }
82
+ }
83
+ }
84
+
85
+ // --- Session-scoped processes (always killed) ---
86
+
87
+ // Monograph background build
88
+ if (killByPidFile(path.join(CWD, '.monomind', 'graph', 'build.pid'))) {
89
+ stopped++;
90
+ console.log('[control-stop] killed monograph build');
91
+ }
92
+
93
+ if (stopped === 0) {
94
+ console.log(`[control-stop] no ${sessionOnly ? 'session ' : ''}processes found`);
95
+ }
@@ -131,6 +131,7 @@ try {
131
131
  } catch (_) {}
132
132
  } finally {
133
133
  try { unlinkSync(${JSON.stringify(lockPath)}); } catch {}
134
+ try { unlinkSync(${JSON.stringify(path.join(graphDir, 'build.pid'))}); } catch {}
134
135
  }`;
135
136
  const child = spawn(process.execPath, ['--input-type=module', '--eval', script], {
136
137
  detached: true,
@@ -139,4 +140,9 @@ const child = spawn(process.execPath, ['--input-type=module', '--eval', script],
139
140
  });
140
141
  child.unref();
141
142
 
143
+ // Track PID so control-stop.cjs can kill it on session exit
144
+ try {
145
+ fs.writeFileSync(path.join(graphDir, 'build.pid'), String(child.pid), 'utf-8');
146
+ } catch { /* best-effort */ }
147
+
142
148
  console.log('[graph] background build started for ' + projectDir);
@@ -107,8 +107,13 @@ function _withTimeout(promise, ms) {
107
107
  /**
108
108
  * Scan `input` with monofence-ai's threat detector, bounded by a timeout.
109
109
  * Returns null (never throws) when monofence is unavailable, times out, or errors.
110
+ * MONOMIND_MONOFENCE_GATE=off disables this scan entirely (mirrors
111
+ * MONOMIND_GRAPH_GATE=off) — e.g. when its heuristics misfire on ordinary
112
+ * markdown headings (observed a false-positive high-confidence block on
113
+ * plain release-note prose during v2.5.3).
110
114
  */
111
115
  async function monofenceScan(input) {
116
+ if (String(process.env.MONOMIND_MONOFENCE_GATE || '').toLowerCase() === 'off') return null;
112
117
  if (!input || typeof input !== 'string') return null;
113
118
  var mod = await _withTimeout(_loadMonofence(), MONOFENCE_TIMEOUT_MS);
114
119
  if (!mod || typeof mod.getMonoDefence !== 'function') return null;