hivemind-context-governance 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +282 -52
  3. package/agents/hivemind-brownfield-orchestrator.md +18 -0
  4. package/bin/hivemind-tools.cjs +29 -9
  5. package/commands/hivemind-compact.md +2 -1
  6. package/commands/hivemind-scan.md +54 -36
  7. package/commands/hivemind-status.md +3 -2
  8. package/dist/cli/init.d.ts +4 -1
  9. package/dist/cli/init.d.ts.map +1 -1
  10. package/dist/cli/init.js +68 -34
  11. package/dist/cli/init.js.map +1 -1
  12. package/dist/cli/interactive-init.d.ts +2 -0
  13. package/dist/cli/interactive-init.d.ts.map +1 -1
  14. package/dist/cli/interactive-init.js +47 -14
  15. package/dist/cli/interactive-init.js.map +1 -1
  16. package/dist/cli/scan.d.ts +8 -0
  17. package/dist/cli/scan.d.ts.map +1 -0
  18. package/dist/cli/scan.js +15 -0
  19. package/dist/cli/scan.js.map +1 -0
  20. package/dist/cli/sync-assets.d.ts +34 -0
  21. package/dist/cli/sync-assets.d.ts.map +1 -0
  22. package/dist/cli/sync-assets.js +235 -0
  23. package/dist/cli/sync-assets.js.map +1 -0
  24. package/dist/cli.js +51 -8
  25. package/dist/cli.js.map +1 -1
  26. package/dist/dashboard/server.d.ts +2 -2
  27. package/dist/dashboard/server.d.ts.map +1 -1
  28. package/dist/dashboard/server.js +32 -11
  29. package/dist/dashboard/server.js.map +1 -1
  30. package/dist/hooks/compaction.d.ts +2 -0
  31. package/dist/hooks/compaction.d.ts.map +1 -1
  32. package/dist/hooks/compaction.js +5 -6
  33. package/dist/hooks/compaction.js.map +1 -1
  34. package/dist/hooks/event-handler.d.ts +17 -0
  35. package/dist/hooks/event-handler.d.ts.map +1 -1
  36. package/dist/hooks/event-handler.js +65 -10
  37. package/dist/hooks/event-handler.js.map +1 -1
  38. package/dist/hooks/messages-transform.d.ts +28 -0
  39. package/dist/hooks/messages-transform.d.ts.map +1 -0
  40. package/dist/hooks/messages-transform.js +214 -0
  41. package/dist/hooks/messages-transform.js.map +1 -0
  42. package/dist/hooks/session-lifecycle-helpers.d.ts +22 -0
  43. package/dist/hooks/session-lifecycle-helpers.d.ts.map +1 -0
  44. package/dist/hooks/session-lifecycle-helpers.js +314 -0
  45. package/dist/hooks/session-lifecycle-helpers.js.map +1 -0
  46. package/dist/hooks/session-lifecycle.d.ts +2 -1
  47. package/dist/hooks/session-lifecycle.d.ts.map +1 -1
  48. package/dist/hooks/session-lifecycle.js +93 -268
  49. package/dist/hooks/session-lifecycle.js.map +1 -1
  50. package/dist/hooks/soft-governance.d.ts +9 -2
  51. package/dist/hooks/soft-governance.d.ts.map +1 -1
  52. package/dist/hooks/soft-governance.js +176 -17
  53. package/dist/hooks/soft-governance.js.map +1 -1
  54. package/dist/hooks/tool-gate.d.ts +7 -17
  55. package/dist/hooks/tool-gate.d.ts.map +1 -1
  56. package/dist/hooks/tool-gate.js +75 -76
  57. package/dist/hooks/tool-gate.js.map +1 -1
  58. package/dist/index.d.ts +3 -3
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +14 -9
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/anchors.d.ts.map +1 -1
  63. package/dist/lib/anchors.js +3 -2
  64. package/dist/lib/anchors.js.map +1 -1
  65. package/dist/lib/auto-commit.d.ts +18 -0
  66. package/dist/lib/auto-commit.d.ts.map +1 -0
  67. package/dist/lib/auto-commit.js +74 -0
  68. package/dist/lib/auto-commit.js.map +1 -0
  69. package/dist/lib/detection.d.ts +0 -6
  70. package/dist/lib/detection.d.ts.map +1 -1
  71. package/dist/lib/detection.js +26 -48
  72. package/dist/lib/detection.js.map +1 -1
  73. package/dist/lib/hierarchy-tree.d.ts +10 -1
  74. package/dist/lib/hierarchy-tree.d.ts.map +1 -1
  75. package/dist/lib/hierarchy-tree.js +64 -13
  76. package/dist/lib/hierarchy-tree.js.map +1 -1
  77. package/dist/lib/index.d.ts +3 -0
  78. package/dist/lib/index.d.ts.map +1 -1
  79. package/dist/lib/index.js +3 -0
  80. package/dist/lib/index.js.map +1 -1
  81. package/dist/lib/logging.d.ts.map +1 -1
  82. package/dist/lib/logging.js +12 -2
  83. package/dist/lib/logging.js.map +1 -1
  84. package/dist/lib/manifest.d.ts +169 -0
  85. package/dist/lib/manifest.d.ts.map +1 -0
  86. package/dist/lib/manifest.js +285 -0
  87. package/dist/lib/manifest.js.map +1 -0
  88. package/dist/lib/mems.d.ts.map +1 -1
  89. package/dist/lib/mems.js +3 -2
  90. package/dist/lib/mems.js.map +1 -1
  91. package/dist/lib/migrate.d.ts +14 -0
  92. package/dist/lib/migrate.d.ts.map +1 -0
  93. package/dist/lib/migrate.js +267 -0
  94. package/dist/lib/migrate.js.map +1 -0
  95. package/dist/lib/paths.d.ts +163 -0
  96. package/dist/lib/paths.d.ts.map +1 -0
  97. package/dist/lib/paths.js +311 -0
  98. package/dist/lib/paths.js.map +1 -0
  99. package/dist/lib/persistence.d.ts +4 -4
  100. package/dist/lib/persistence.d.ts.map +1 -1
  101. package/dist/lib/persistence.js +285 -57
  102. package/dist/lib/persistence.js.map +1 -1
  103. package/dist/lib/planning-fs.d.ts +32 -21
  104. package/dist/lib/planning-fs.d.ts.map +1 -1
  105. package/dist/lib/planning-fs.js +358 -88
  106. package/dist/lib/planning-fs.js.map +1 -1
  107. package/dist/lib/project-scan.d.ts +22 -0
  108. package/dist/lib/project-scan.d.ts.map +1 -0
  109. package/dist/lib/project-scan.js +141 -0
  110. package/dist/lib/project-scan.js.map +1 -0
  111. package/dist/lib/session-boundary.d.ts +29 -0
  112. package/dist/lib/session-boundary.d.ts.map +1 -0
  113. package/dist/lib/session-boundary.js +57 -0
  114. package/dist/lib/session-boundary.js.map +1 -0
  115. package/dist/lib/session-export.d.ts +15 -2
  116. package/dist/lib/session-export.d.ts.map +1 -1
  117. package/dist/lib/session-export.js +60 -0
  118. package/dist/lib/session-export.js.map +1 -1
  119. package/dist/lib/toast-throttle.d.ts +58 -0
  120. package/dist/lib/toast-throttle.d.ts.map +1 -0
  121. package/dist/lib/toast-throttle.js +124 -0
  122. package/dist/lib/toast-throttle.js.map +1 -0
  123. package/dist/lib/tool-activation.d.ts +1 -1
  124. package/dist/lib/tool-activation.js +5 -5
  125. package/dist/lib/tool-activation.js.map +1 -1
  126. package/dist/schemas/config.d.ts +20 -6
  127. package/dist/schemas/config.d.ts.map +1 -1
  128. package/dist/schemas/config.js +46 -5
  129. package/dist/schemas/config.js.map +1 -1
  130. package/dist/schemas/manifest.d.ts +19 -0
  131. package/dist/schemas/manifest.d.ts.map +1 -0
  132. package/dist/schemas/manifest.js +7 -0
  133. package/dist/schemas/manifest.js.map +1 -0
  134. package/dist/tools/compact-session.d.ts.map +1 -1
  135. package/dist/tools/compact-session.js +51 -17
  136. package/dist/tools/compact-session.js.map +1 -1
  137. package/dist/tools/declare-intent.d.ts +0 -1
  138. package/dist/tools/declare-intent.d.ts.map +1 -1
  139. package/dist/tools/declare-intent.js +14 -41
  140. package/dist/tools/declare-intent.js.map +1 -1
  141. package/dist/tools/export-cycle.d.ts.map +1 -1
  142. package/dist/tools/export-cycle.js +13 -0
  143. package/dist/tools/export-cycle.js.map +1 -1
  144. package/dist/tools/hierarchy.d.ts +9 -19
  145. package/dist/tools/hierarchy.d.ts.map +1 -1
  146. package/dist/tools/hierarchy.js +108 -94
  147. package/dist/tools/hierarchy.js.map +1 -1
  148. package/dist/tools/hivemind-anchor.d.ts +16 -0
  149. package/dist/tools/hivemind-anchor.d.ts.map +1 -0
  150. package/dist/tools/hivemind-anchor.js +180 -0
  151. package/dist/tools/hivemind-anchor.js.map +1 -0
  152. package/dist/tools/hivemind-cycle.d.ts +15 -0
  153. package/dist/tools/hivemind-cycle.d.ts.map +1 -0
  154. package/dist/tools/hivemind-cycle.js +228 -0
  155. package/dist/tools/hivemind-cycle.js.map +1 -0
  156. package/dist/tools/hivemind-hierarchy.d.ts +16 -0
  157. package/dist/tools/hivemind-hierarchy.d.ts.map +1 -0
  158. package/dist/tools/hivemind-hierarchy.js +224 -0
  159. package/dist/tools/hivemind-hierarchy.js.map +1 -0
  160. package/dist/tools/hivemind-inspect.d.ts +15 -0
  161. package/dist/tools/hivemind-inspect.d.ts.map +1 -0
  162. package/dist/tools/hivemind-inspect.js +390 -0
  163. package/dist/tools/hivemind-inspect.js.map +1 -0
  164. package/dist/tools/hivemind-memory.d.ts +15 -0
  165. package/dist/tools/hivemind-memory.d.ts.map +1 -0
  166. package/dist/tools/hivemind-memory.js +217 -0
  167. package/dist/tools/hivemind-memory.js.map +1 -0
  168. package/dist/tools/hivemind-session.d.ts +15 -0
  169. package/dist/tools/hivemind-session.d.ts.map +1 -0
  170. package/dist/tools/hivemind-session.js +541 -0
  171. package/dist/tools/hivemind-session.js.map +1 -0
  172. package/dist/tools/index.d.ts +6 -13
  173. package/dist/tools/index.d.ts.map +1 -1
  174. package/dist/tools/index.js +6 -13
  175. package/dist/tools/index.js.map +1 -1
  176. package/dist/tools/map-context.d.ts.map +1 -1
  177. package/dist/tools/map-context.js +22 -39
  178. package/dist/tools/map-context.js.map +1 -1
  179. package/dist/tools/recall-mems.d.ts +6 -4
  180. package/dist/tools/recall-mems.d.ts.map +1 -1
  181. package/dist/tools/recall-mems.js +70 -10
  182. package/dist/tools/recall-mems.js.map +1 -1
  183. package/dist/tools/save-anchor.d.ts +7 -2
  184. package/dist/tools/save-anchor.d.ts.map +1 -1
  185. package/dist/tools/save-anchor.js +67 -8
  186. package/dist/tools/save-anchor.js.map +1 -1
  187. package/dist/tools/scan-hierarchy.d.ts +0 -6
  188. package/dist/tools/scan-hierarchy.d.ts.map +1 -1
  189. package/dist/tools/scan-hierarchy.js +347 -58
  190. package/dist/tools/scan-hierarchy.js.map +1 -1
  191. package/dist/tools/self-rate.js +2 -2
  192. package/dist/tools/self-rate.js.map +1 -1
  193. package/dist/tools/think-back.d.ts.map +1 -1
  194. package/dist/tools/think-back.js +17 -2
  195. package/dist/tools/think-back.js.map +1 -1
  196. package/dist/utils/string.d.ts +8 -0
  197. package/dist/utils/string.d.ts.map +1 -0
  198. package/dist/utils/string.js +35 -0
  199. package/dist/utils/string.js.map +1 -0
  200. package/package.json +10 -5
  201. package/prompts/hivemind-brownfield-remediation.md +14 -0
  202. package/references/hivemind-brownfield-checklist.md +17 -0
  203. package/skills/context-integrity/SKILL.md +3 -3
  204. package/skills/session-lifecycle/SKILL.md +1 -1
  205. package/templates/hivemind-brownfield-session.md +26 -0
  206. package/workflows/hivemind-brownfield-bootstrap.yaml +23 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+ - `experimental.chat.messages.transform` hook with stop-checklist injection and continuity context enrichment (`<anchor-context>`, `<focus>`)
12
+ - Session boundary manager (`src/lib/session-boundary.ts`) with lifecycle warning integration and checklist-boundary recommendation
13
+ - Non-disruptive SDK session rollover after compaction (`client.session.create`) with non-fatal fallback behavior
14
+ - Task manifest persistence for `todo.updated` events into `.hivemind/state/tasks.json`
15
+ - Optional `auto_commit` governance flow for file-changing tools (`write`, `edit`, `bash`) with new auto-commit helpers
16
+
10
17
  ### Fixed
11
18
  - `export_cycle` now synchronizes flat `brain.hierarchy` projection after tree mutations, eliminating hierarchy/tree desync after subagent exports
12
19
  - `declare_intent` no longer overwrites per-session files with legacy active template content; legacy `active.md` is updated separately for backward compatibility
@@ -24,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
31
 
25
32
  ### Documentation
26
33
  - `README.md` fully rewritten: coherent install-to-runtime flow, upgrade guidance, troubleshooting, and expanded Vietnamese section focused on practical onboarding
34
+ - `README.md` refreshed for Phase B: hook count/tool catalog accuracy, merged tool names, and new governance capabilities
27
35
 
28
36
  ## [2.6.0] - 2026-02-12
29
37
 
package/README.md CHANGED
@@ -5,11 +5,13 @@
5
5
  HiveMind is an [OpenCode](https://opencode.ai) plugin that prevents AI agents from drifting, forgetting, and losing coherence during long coding sessions. It enforces a simple backbone — *declare what you're doing, track as you go, archive when done* — and connects every piece into one unified system.
6
6
 
7
7
  ```
8
- 14 tools · 5 hooks · 5 skills · 3 slash commands · interactive CLI · Ink TUI dashboard · EN/VI
8
+ 10 tools · 6 hooks · 5 skills · 3 slash commands · interactive CLI · Ink TUI dashboard · EN/VI
9
9
  ```
10
10
 
11
11
  [![npm version](https://img.shields.io/npm/v/hivemind-context-governance)](https://www.npmjs.com/package/hivemind-context-governance)
12
12
 
13
+ **Found this useful?** [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-support-orange?logo=buy-me-a-coffee&logoColor=white)](https://buymeacoffee.com/shynlee04l)
14
+
13
15
  ---
14
16
 
15
17
  ## The Problem
@@ -27,19 +29,25 @@ Without governance, long AI sessions decay:
27
29
 
28
30
  ---
29
31
 
30
- ## Quick Start
32
+ ## Quick Start
31
33
 
32
- ### 1. Install
34
+ ### One Command - That's It
33
35
 
34
36
  ```bash
35
- npm install hivemind-context-governance
37
+ npx hivemind-context-governance init --mode assisted
36
38
  ```
37
39
 
38
- ### 2. Initialize (Interactive Wizard)
40
+ **What happens (guaranteed):**
41
+ 1. Downloads from npm automatically (no manual install needed)
42
+ 2. Creates `.hivemind/` directory with brain.json, config.json
43
+ 3. Registers plugin in `opencode.json` (so OpenCode auto-loads it)
44
+ 4. Syncs commands/skills into `.opencode/`
45
+ 5. Creates session template files
46
+ 6. Opens a session in `OPEN` mode (assisted) or `LOCKED` mode (strict)
39
47
 
40
- ```bash
41
- npx hivemind-context-governance
42
- ```
48
+ **Works on any machine, any project. No exceptions.**
49
+
50
+ ### Verify Installation (Optional)
43
51
 
44
52
  The wizard walks you through step by step:
45
53
 
@@ -60,21 +68,52 @@ The wizard walks you through step by step:
60
68
  │ ○ guided — Suggestions only
61
69
  │ ● assisted — Balanced automation (recommended)
62
70
  │ ○ full — Maximum automation
63
- │ ○ retard — Maximum handholding, skeptical of everything
71
+ │ ○ coach — Maximum handholding, skeptical of everything
64
72
 
65
73
  ◆ Configuration saved! .hivemind/ created.
66
74
  ```
67
75
 
68
- ### 3. Non-Interactive Alternative
76
+ ### Non-Interactive Alternative
69
77
 
70
78
  ```bash
71
79
  npx hivemind-context-governance init --mode strict --lang vi --automation full
72
80
  ```
73
81
 
74
- ### 4. Open OpenCode
82
+ This does **exactly the same** as the interactive wizard:
83
+ - Creates `.hivemind/` structure
84
+ - Registers plugin in `opencode.json`
85
+ - Syncs OpenCode assets
86
+ - Initializes brain state with your chosen settings
87
+
88
+ ### Verify Installation
89
+
90
+ After running `init`, verify everything is set up:
91
+
92
+ ```bash
93
+ npx hivemind-context-governance status
94
+ ```
95
+
96
+ Or manually check `opencode.json` contains:
97
+ ```json
98
+ {
99
+ "plugin": ["hivemind-context-governance"]
100
+ }
101
+ ```
102
+
103
+ ### Open OpenCode
75
104
 
76
105
  That's it. The plugin auto-activates. The AI agent gets governance context injected into every turn.
77
106
 
107
+ **Important:** If you run `init` again on an existing project, it will:
108
+ - Keep your existing `.hivemind/` state
109
+ - Refresh OpenCode assets
110
+ - Ensure plugin is still registered in `opencode.json`
111
+
112
+ **How it works:**
113
+ - `init` automatically registers `hivemind-context-governance` in `opencode.json`'s `plugin` array
114
+ - OpenCode reads this on startup and auto-loads the plugin
115
+ - If you manually edit `opencode.json`, make sure `plugin` is an array containing `"hivemind-context-governance"`
116
+
78
117
  ---
79
118
 
80
119
  ## How It Works
@@ -97,15 +136,16 @@ Trajectory (Level 1) — "Build authentication system"
97
136
 
98
137
  ### Under the Hood
99
138
 
100
- HiveMind fires **5 hooks automatically** on every turn:
139
+ HiveMind fires **6 hooks automatically** on every turn:
101
140
 
102
141
  | Hook | When | What It Does |
103
142
  |------|------|-------------|
104
- | `system.transform` | Every LLM turn | Injects `<hivemind>` block with hierarchy, drift, warnings |
143
+ | `experimental.chat.system.transform` | Every LLM turn | Injects `<hivemind>` block with hierarchy, drift, warnings |
144
+ | `experimental.chat.messages.transform` | Before LLM response | Injects stop-checklist and continuity context (`<anchor-context>`, `<focus>`) |
105
145
  | `tool.execute.before` | Before any tool | Governance gate — warns on writes without intent |
106
146
  | `tool.execute.after` | After any tool | Tracks metrics, detects violations, captures cycles |
107
147
  | `session.compacting` | On context compaction | Preserves hierarchy + metrics across compaction |
108
- | `event` | On session events | Reacts to idle, file edits, compaction events |
148
+ | `event` | On session events | Reacts to idle/file edits/compaction and persists `todo.updated` into task manifest |
109
149
 
110
150
  ### Data Flow
111
151
 
@@ -142,11 +182,11 @@ HiveMind fires **5 hooks automatically** on every turn:
142
182
  | `guided` | Suggestions only, never auto-acts |
143
183
  | `assisted` | Balanced automation *(default)* |
144
184
  | `full` | Maximum automation, minimal prompting |
145
- | `retard` | Maximum handholding — strict governance, skeptical output, strongest discipline |
185
+ | `coach` | Maximum handholding — strict governance, skeptical output, strongest discipline |
146
186
 
147
187
  ---
148
188
 
149
- ## Tools Reference (14)
189
+ ## Tools Reference (10)
150
190
 
151
191
  ### Core Lifecycle (3 tools)
152
192
 
@@ -170,22 +210,19 @@ compact_session({ summary: "Auth middleware complete" })
170
210
  // → Archived. 15 turns, 4 files. Session reset.
171
211
  ```
172
212
 
173
- ### Awareness & Correction (4 tools)
213
+ ### Awareness & Correction (2 tools)
174
214
 
175
215
  | Tool | Agent Thought | What It Does |
176
216
  |------|--------------|-------------|
177
217
  | `scan_hierarchy` | *"Quick status check"* | Shows session state, metrics, anchors |
178
218
  | `think_back` | *"I feel lost"* | Deep refocus with plan review + chain analysis |
179
- | `check_drift` | *"Am I still on track?"* | Verifies alignment with trajectory |
180
- | `self_rate` | *"How am I doing?"* | Rate performance 1-10 for drift detection |
181
219
 
182
- ### Persistent Memory (3 tools)
220
+ ### Persistent Memory (2 tools)
183
221
 
184
222
  | Tool | Agent Thought | What It Does |
185
223
  |------|--------------|-------------|
186
224
  | `save_mem` | *"This is worth remembering"* | Store decisions/patterns to persistent memory |
187
- | `list_shelves` | *"What do I know?"* | Browse Mems Brain by shelf |
188
- | `recall_mems` | *"I've seen this before"* | Search past decisions by keyword |
225
+ | `recall_mems` | *"I've seen this before"* | Search or list Mems Brain by keyword/shelf |
189
226
 
190
227
  ### Immutable Facts (1 tool)
191
228
 
@@ -193,12 +230,11 @@ compact_session({ summary: "Auth middleware complete" })
193
230
  |------|--------------|-------------|
194
231
  | `save_anchor` | *"This must not be forgotten"* | Persist constraints that survive compaction + chaos |
195
232
 
196
- ### Hierarchy Tree (2 tools)
233
+ ### Hierarchy Tree (1 tool)
197
234
 
198
235
  | Tool | Agent Thought | What It Does |
199
236
  |------|--------------|-------------|
200
- | `hierarchy_prune` | *"Clean up finished work"* | Remove completed branches from tree |
201
- | `hierarchy_migrate` | *"Upgrade the tree"* | Migrate flat hierarchy → navigable tree |
237
+ | `hierarchy_manage` | *"Clean up or migrate the tree"* | Unified `prune` and `migrate` operations |
202
238
 
203
239
  ### Delegation Intelligence (1 tool)
204
240
 
@@ -214,10 +250,15 @@ HiveMind ships 3 OpenCode slash commands that work immediately after install:
214
250
 
215
251
  | Command | Purpose |
216
252
  |---------|---------|
217
- | `/hivemind-scan` | Project reconnaissance — scans structure, detects stack, identifies stale artifacts |
253
+ | `/hivemind-scan` | Brownfield reconnaissance — analyze, recommend, orchestrate baseline context |
218
254
  | `/hivemind-status` | Full governance status — session, hierarchy, metrics, mems, config |
219
255
  | `/hivemind-compact` | Guided session archival with pre-compact checklist |
220
256
 
257
+ `/hivemind-scan` runs a practical sequence with `scan_hierarchy` actions:
258
+ 1. `action: "analyze"` — detect framework mode (`gsd/spec-kit/both/none`) + BMAD signals
259
+ 2. `action: "recommend"` — generate remediation runbook
260
+ 3. `action: "orchestrate"` — persist non-destructive baseline anchors + memory
261
+
221
262
  ---
222
263
 
223
264
  ## Skills (5 Behavioral Governance Skills)
@@ -239,6 +280,8 @@ Skills teach the agent *how* to use governance effectively:
239
280
  ```bash
240
281
  npx hivemind-context-governance # Interactive setup wizard
241
282
  npx hivemind-context-governance init # Same (or use flags)
283
+ npx hivemind-context-governance scan # Brownfield scan wrapper
284
+ npx hivemind-context-governance sync-assets # Sync packaged OpenCode assets to .opencode
242
285
  npx hivemind-context-governance status # Show session state
243
286
  npx hivemind-context-governance settings # Show configuration
244
287
  npx hivemind-context-governance dashboard # Launch live TUI dashboard
@@ -252,12 +295,68 @@ npx hivemind-context-governance help # Show help
252
295
  |------|--------|---------|
253
296
  | `--mode` | `permissive` · `assisted` · `strict` | `assisted` |
254
297
  | `--lang` | `en` · `vi` | `en` |
255
- | `--automation` | `manual` · `guided` · `assisted` · `full` · `retard` | `assisted` |
298
+ | `--automation` | `manual` · `guided` · `assisted` · `full` · `coach` | `assisted` |
256
299
  | `--expert` | `beginner` · `intermediate` · `advanced` · `expert` | `intermediate` |
257
300
  | `--style` | `explanatory` · `outline` · `skeptical` · `architecture` · `minimal` | `explanatory` |
258
301
  | `--code-review` | *(flag)* | off |
259
302
  | `--tdd` | *(flag)* | off |
303
+ | `--target` | `project` · `global` · `both` *(for init/sync-assets)* | `project` |
304
+ | `--overwrite` | *(flag, for sync-assets)* | off |
260
305
  | `--force` | *(flag)* — removes existing .hivemind/ before re-init | off |
306
+ | `--action` | `status` · `analyze` · `recommend` · `orchestrate` *(for scan)* | `analyze` |
307
+ | `--json` | *(flag, for scan)* | off |
308
+ | `--include-drift` | *(flag, for scan status)* | off |
309
+
310
+ ### OpenCode Asset Sync
311
+
312
+ HiveMind can sync packaged OpenCode assets (`commands`, `skills`, and optional ecosystem groups) into OpenCode paths.
313
+
314
+ ```bash
315
+ # Default: project-local .opencode/
316
+ npx hivemind-context-governance sync-assets
317
+
318
+ # Global OpenCode config path (~/.config/opencode or platform equivalent)
319
+ npx hivemind-context-governance sync-assets --target global
320
+
321
+ # Sync both project and global targets
322
+ npx hivemind-context-governance sync-assets --target both
323
+
324
+ # Replace existing files (default behavior is no-clobber)
325
+ npx hivemind-context-governance sync-assets --overwrite
326
+ ```
327
+
328
+ `init` also performs asset sync automatically. Re-running `init` on an existing project refreshes missing assets without resetting `.hivemind` state.
329
+
330
+ Packaged optional ecosystem assets now include starter files for:
331
+ - `agents`
332
+ - `workflows`
333
+ - `templates`
334
+ - `prompts`
335
+ - `references`
336
+
337
+ These are synced into `.opencode/` (or global OpenCode config path) alongside commands and skills.
338
+
339
+ ### Existing User Upgrade (No Re-init Required)
340
+
341
+ ```bash
342
+ npm install hivemind-context-governance@latest
343
+ npx hivemind-context-governance sync-assets --target project
344
+ ```
345
+
346
+ Use `--target both` if you want project-local and global OpenCode paths updated together.
347
+
348
+ ### Brownfield Scan via CLI
349
+
350
+ ```bash
351
+ # Analyze framework + stack + artifact risks
352
+ npx hivemind-context-governance scan --action analyze --json
353
+
354
+ # Generate remediation sequence
355
+ npx hivemind-context-governance scan --action recommend
356
+
357
+ # Persist safe baseline anchors + memory
358
+ npx hivemind-context-governance scan --action orchestrate --json
359
+ ```
261
360
 
262
361
  ### Dashboard (Optional TUI)
263
362
 
@@ -282,6 +381,31 @@ When OpenCode loads HiveMind **before** `hivemind init` was run:
282
381
 
283
382
  This prevents the "agent starts coding immediately without understanding the project" failure mode.
284
383
 
384
+ ## Brownfield Runbook (\"Please scan my project and refactor it\")
385
+
386
+ Recommended execution order:
387
+
388
+ 1. Analyze:
389
+ ```ts
390
+ scan_hierarchy({ action: "analyze", json: true })
391
+ ```
392
+ 2. Recommend:
393
+ ```ts
394
+ scan_hierarchy({ action: "recommend" })
395
+ ```
396
+ 3. Orchestrate baseline:
397
+ ```ts
398
+ scan_hierarchy({ action: "orchestrate", json: true })
399
+ ```
400
+ 4. Lock execution focus:
401
+ ```ts
402
+ declare_intent({ mode: "exploration", focus: "Brownfield stabilization" })
403
+ map_context({ level: "tactic", content: "Context purification and framework resolution" })
404
+ map_context({ level: "action", content: "Execute safe cleanup checkpoints" })
405
+ ```
406
+
407
+ This sequence ensures framework detection, context purification, baseline persistence, and drift-safe execution before large refactors.
408
+
285
409
  ---
286
410
 
287
411
  ## `.hivemind/` Directory Structure
@@ -335,13 +459,36 @@ npx hivemind-context-governance init --force
335
459
 
336
460
  ## Troubleshooting
337
461
 
462
+ ### "Plugin not loading" or "Setup guidance keeps appearing"
463
+
464
+ **Cause:** The plugin was never registered in `opencode.json`.
465
+
466
+ **Fix:** Run the init command **once**:
467
+ ```bash
468
+ npx hivemind-context-governance init --mode assisted
469
+ ```
470
+
471
+ This does **all** of the following:
472
+ - Creates `.hivemind/` directory structure
473
+ - Registers plugin in `opencode.json` (so OpenCode auto-loads it)
474
+ - Syncs commands/skills into `.opencode/`
475
+ - Initializes brain state
476
+
477
+ **Important:** If you run `init` again on an existing project:
478
+ - It keeps your existing `.hivemind/` state ✅
479
+ - It refreshes OpenCode assets ✅
480
+ - It ensures plugin is still registered ✅
481
+
482
+ ### Other Issues
483
+
338
484
  | Symptom | Cause | Fix |
339
485
  |---------|-------|-----|
340
- | Setup guidance keeps appearing | `.hivemind/config.json` missing | Run `npx hivemind-context-governance` |
486
+ | Setup guidance keeps appearing | `.hivemind/config.json` missing | Run `npx hivemind-context-governance init --mode assisted` |
341
487
  | Framework conflict warning | Both `.planning/` and `.spec-kit/` exist | Select one framework via locked menu |
342
488
  | Dashboard won't start | Optional deps not installed | `npm install ink react` |
343
489
  | Session feels stale after idle | Auto-archive rotated state | Use `scan_hierarchy` + `think_back` |
344
490
  | Want fresh start | Old config causing issues | `npx hivemind-context-governance purge` then re-init |
491
+ | "Plugin already registered" message | Normal behavior on upgrade | No action needed |
345
492
 
346
493
  ---
347
494
 
@@ -350,7 +497,7 @@ npx hivemind-context-governance init --force
350
497
  ```bash
351
498
  npm run build # Full build (clean + compile + chmod)
352
499
  npm run typecheck # TypeScript type checking
353
- npm test # Run all 41 test files (705+ assertions)
500
+ npm test # Run all test files (700+ assertions)
354
501
  npm run dev # Watch mode
355
502
  ```
356
503
 
@@ -368,6 +515,8 @@ MIT
368
515
 
369
516
  > *Phần này không phải bản dịch — mà được viết riêng cho người dùng Việt Nam, với giải thích kỹ hơn về cách hoạt động và lý do tại sao.*
370
517
 
518
+ **Cảm thấy hữu ích?** [![Mời cà phê](https://img.shields.io/badge/Mời%20cà%20phê-ủng%20hộ-orange?logo=buy-me-a-coffee&logoColor=white)](https://buymeacoffee.com/shynlee04l)
519
+
371
520
  ## HiveMind Là Gì?
372
521
 
373
522
  Hãy tưởng tượng bạn thuê một lập trình viên AI rất giỏi, nhưng anh ta có một vấn đề: **mỗi 30 phút anh ta quên hết mọi thứ đang làm**.
@@ -420,40 +569,104 @@ Khi xong việc, `compact_session` sẽ:
420
569
 
421
570
  ## Cài Đặt Từ Đầu Đến Cuối
422
571
 
423
- ### Bước 1: Cài Package
572
+ ### Một Lệnh - Xong Ngay
424
573
 
425
574
  ```bash
426
- npm install hivemind-context-governance
575
+ npx hivemind-context-governance init --mode assisted
427
576
  ```
428
577
 
429
- ### Bước 2: Chạy Wizard Cấu Hình
578
+ **Điều sẽ xảy ra (đảm bảo):**
579
+ 1. Tự động tải từ npm (không cần cài thủ công)
580
+ 2. Tạo thư mục `.hivemind/` với brain.json, config.json
581
+ 3. Đăng ký plugin trong `opencode.json` (để OpenCode tự động load)
582
+ 4. Đồng bộ commands/skills vào `.opencode/`
583
+ 5. Tạo các file session template
584
+ 6. Mở session ở chế độ `OPEN` (assisted) hoặc `LOCKED` (strict)
430
585
 
431
- ```bash
432
- npx hivemind-context-governance
586
+ **Hoạt động trên mọi máy, mọi project. Không ngoại lệ.**
587
+
588
+ ### Xác Nhận Cài Đặt (Tùy Chọn)
589
+
590
+ Wizard sẽ hướng dẫn bạn từng bước:
591
+
592
+ ```
593
+ ◆ Welcome to HiveMind Context Governance!
594
+
595
+ ◆ Select governance mode:
596
+ │ ○ strict — Session starts LOCKED. Must declare intent before writes.
597
+ │ ● assisted — Session starts OPEN. Guidance without blocking. (recommended)
598
+ │ ○ permissive — Always OPEN. Silent tracking only.
599
+
600
+ ◆ Select language:
601
+ │ ○ English
602
+ │ ● Tiếng Việt
603
+
604
+ ◆ Select automation level:
605
+ │ ○ manual — No automation, you control everything
606
+ │ ○ guided — Suggestions only
607
+ │ ● assisted — Balanced automation (recommended)
608
+ │ ○ full — Maximum automation
609
+ │ ○ coach — Maximum handholding, skeptical of everything
610
+
611
+ ◆ Configuration saved! .hivemind/ created.
433
612
  ```
434
613
 
435
- Wizard sẽ hỏi bạn từng bước:
614
+ ### Cài Đặt Không Tương Tác
615
+
616
+ ```bash
617
+ npx hivemind-context-governance init --mode strict --lang vi --automation full
618
+ ```
436
619
 
437
- 1. **Chế độ quản trị**:
438
- - `strict` = Nghiêm ngặt (agent phải khai báo trước khi làm bất cứ gì)
439
- - `assisted` = Hỗ trợ (khuyên nhủ nhưng không chặn) ← **khuyến nghị cho người mới**
440
- - `permissive` = Tự do (chỉ theo dõi, không can thiệp)
620
+ Lệnh này làm **đúng như** wizard tương tác:
621
+ - Tạo cấu trúc `.hivemind/`
622
+ - Đăng plugin trong `opencode.json`
623
+ - Đồng bộ OpenCode assets
624
+ - Khởi tạo brain state với cài đặt đã chọn
441
625
 
442
- 2. **Ngôn ngữ**: Chọn `vi` để nhận cảnh báo bằng tiếng Việt
626
+ ### Mở OpenCode
443
627
 
444
- 3. **Mức tự động hóa**: Từ `manual` (tự tay) đến `retard` (giám sát tối đa)
628
+ Xong. Plugin tự động hoạt động. AI agent sẽ nhận governance context được inject vào mỗi turn.
445
629
 
446
- 4. **Hành vi agent**: Mức chuyên gia, phong cách output, ràng buộc
630
+ ### Xác Nhận Cài Đặt (Tùy Chọn)
447
631
 
448
- ### Bước 3: Mở OpenCode
632
+ ```bash
633
+ npx hivemind-context-governance status
634
+ ```
449
635
 
450
- Plugin tự động hoạt động. Không cần thêm bước nào.
636
+ Hoặc kiểm tra thủ công `opencode.json` chứa:
637
+ ```json
638
+ {
639
+ "plugin": ["hivemind-context-governance"]
640
+ }
641
+ ```
451
642
 
452
- ### Bước 4: Sử Dụng Slash Command
643
+ ### Sử Dụng Slash Command
453
644
 
454
645
  Gõ `/hivemind-scan` trong OpenCode để quét dự án và tạo bản đồ cơ sở trước khi bắt đầu code.
455
646
 
456
- ## 14 Công Cụ — Giải Thích Chi Tiết
647
+ Hoặc dùng CLI trực tiếp:
648
+
649
+ ```bash
650
+ npx hivemind-context-governance scan --action analyze --json
651
+ npx hivemind-context-governance scan --action recommend
652
+ npx hivemind-context-governance scan --action orchestrate --json
653
+ ```
654
+
655
+ ## Runbook Brownfield (Tiếng Việt)
656
+
657
+ Khi người dùng nói: *\"Hãy quét dự án và refactor\"*, chạy theo thứ tự:
658
+
659
+ 1. `scan_hierarchy({ action: "analyze", json: true })`
660
+ 2. `scan_hierarchy({ action: "recommend" })`
661
+ 3. `scan_hierarchy({ action: "orchestrate", json: true })`
662
+ 4. `declare_intent(...)` + `map_context(...)` để khóa focus trước khi sửa code
663
+
664
+ Mục tiêu:
665
+ - Phát hiện framework (`gsd/spec-kit/both/none`) và tín hiệu BMAD
666
+ - Cô lập artifact cũ/stale có nguy cơ nhiễm context
667
+ - Lưu baseline anchors + memory trước khi refactor diện rộng
668
+
669
+ ## 10 Công Cụ — Giải Thích Chi Tiết
457
670
 
458
671
  ### Nhóm 1: Vòng Đời Session
459
672
 
@@ -469,15 +682,13 @@ Gõ `/hivemind-scan` trong OpenCode để quét dự án và tạo bản đồ c
469
682
  |---------|-------------|---------------------|
470
683
  | `scan_hierarchy` | Muốn xem nhanh trạng thái | Nắm bắt tình hình trong 1 giây |
471
684
  | `think_back` | Cảm thấy lạc | Hồi phục context sâu sau compaction |
472
- | `check_drift` | Trước khi kết luận xong | Kiểm tra đúng hướng với mục tiêu ban đầu không |
473
- | `self_rate` | Tự đánh giá | Chấm điểm 1-10 để phát hiện vấn đề sớm |
685
+ | `scan_hierarchy` (`include_drift`) | Trước khi kết luận xong | Kiểm tra độ lệch hướng theo trajectory/tactic/action |
474
686
 
475
687
  ### Nhóm 3: Bộ Nhớ Dài Hạn
476
688
 
477
689
  | Công Cụ | Khi Nào Dùng | Tại Sao Quan Trọng |
478
690
  |---------|-------------|---------------------|
479
691
  | `save_mem` | Học được bài học quan trọng | Quyết định, pattern, lỗi — tồn tại vĩnh viễn |
480
- | `list_shelves` | Muốn xem có gì trong bộ nhớ | Tổng quan kho tri thức |
481
692
  | `recall_mems` | Gặp vấn đề quen thuộc | Tìm giải pháp từ quá khứ |
482
693
  | `save_anchor` | Sự thật bất biến | Port number, schema, API endpoint — không bao giờ quên |
483
694
 
@@ -485,8 +696,7 @@ Gõ `/hivemind-scan` trong OpenCode để quét dự án và tạo bản đồ c
485
696
 
486
697
  | Công Cụ | Khi Nào Dùng | Tại Sao Quan Trọng |
487
698
  |---------|-------------|---------------------|
488
- | `hierarchy_prune` | Cây quá nhiều nhánh đã xong | Giữ cây gọn gàng |
489
- | `hierarchy_migrate` | Nâng cấp từ bản cũ | Chuyển đổi hierarchy phẳng → cây |
699
+ | `hierarchy_manage` | Cây nhiều nhánh hoặc cần nâng cấp | Gộp cả prune migrate trong một công cụ |
490
700
  | `export_cycle` | Subagent vừa trả kết quả | Không export = mất intelligence từ subagent |
491
701
 
492
702
  ## Lần Đầu Mở OpenCode (Quan Trọng!)
@@ -547,6 +757,16 @@ npx hivemind-context-governance init --force
547
757
  5. **Kết thúc bằng `compact_session`** — Lưu trữ có cấu trúc, session sau vào lại không bị "reset trí nhớ"
548
758
  6. **Dùng `/hivemind-scan` khi mới vào project** — Hiểu project trước khi code
549
759
 
760
+ ## Về Tác Giả
761
+
762
+ HiveMind được xây dựng bởi [shynlee04](https://github.com/shynlee04) — một lập trình viên đã quá mệt mỏi với việc AI agent quên mất đang làm gì giữa chừng phiên code. Sau quá nhiều lần tự hỏi "khoan đã, tại sao mình lại quyết định kiến trúc này nhỉ?", ý tưởng về một hệ thống quản trị context đã ra đời.
763
+
764
+ Khi không bận xây dựng công cụ để AI "trung thực" hơn, mình thường làm việc với full-stack applications, mày mò developer tooling, và ủng hộ phong cách phát triển có sự hỗ trợ của AI mà thực sự hiệu quả.
765
+
766
+ **Cảm thấy hữu ích?** [Mời mình ly cà phê ☕](https://buymeacoffee.com/shynlee04l) — nó tiếp thêm năng lượng cho những đêm code muộn để tạo ra những công cụ như thế này.
767
+
768
+ ---
769
+
550
770
  > *Nếu bạn coi HiveMind như "bộ điều phối context" thay vì "một bộ tool phụ", chất lượng session sẽ khác biệt rõ rệt.*
551
771
 
552
772
  ---
@@ -561,7 +781,7 @@ npx hivemind-context-governance init --force
561
781
  │ │ │ │
562
782
  │ │ ┌─────────┐ ┌──────────┐ ┌──────────┐ │ │
563
783
  │ │ │ Hooks │ │ Tools │ │ Events │ │ │
564
- │ │ │ (5) │ │ (14) │ │ handler │ │ │
784
+ │ │ │ (6) │ │ (10) │ │ handler │ │ │
565
785
  │ │ └────┬────┘ └────┬─────┘ └────┬─────┘ │ │
566
786
  │ │ │ │ │ │ │
567
787
  │ │ ▼ ▼ ▼ │ │
@@ -586,4 +806,14 @@ npx hivemind-context-governance init --force
586
806
 
587
807
  ---
588
808
 
809
+ ## About
810
+
811
+ HiveMind is built by [shynlee04](https://github.com/shynlee04), a developer who got tired of AI agents forgetting what they were doing halfway through coding sessions. After one too many "wait, why did we decide this architecture again?" moments, the idea for a context governance system was born.
812
+
813
+ When not building tools to keep AI honest, you'll find me working on full-stack applications, tinkering with developer tooling, and advocating for AI-assisted development that actually works.
814
+
815
+ **Found this useful?** [Buy me a coffee ☕](https://buymeacoffee.com/shynlee04l) — it fuels the late-night coding sessions that make tools like this possible.
816
+
817
+ ---
818
+
589
819
  *Built for developers who believe AI agents should be accountable, not just capable.*
@@ -0,0 +1,18 @@
1
+ ---
2
+ name: hivemind-brownfield-orchestrator
3
+ description: Run a safe brownfield stabilization sequence before broad refactors.
4
+ model: default
5
+ ---
6
+
7
+ You are a hidden orchestration agent for brownfield projects.
8
+
9
+ Workflow:
10
+ 1. Run `scan_hierarchy` with `{ action: "analyze", json: true }`.
11
+ 2. If framework conflict is detected, return recommendations first and stop destructive changes.
12
+ 3. Run `scan_hierarchy` with `{ action: "orchestrate", json: true }` to persist baseline anchors and memory.
13
+ 4. Return a concise execution order using `declare_intent` and `map_context`.
14
+
15
+ Rules:
16
+ - Never edit code in this phase.
17
+ - Prioritize artifact purification and framework conflict resolution.
18
+ - Require evidence outputs before claiming readiness.
@@ -158,8 +158,21 @@ function validateHierarchyChain(tree) {
158
158
  function getHiveMindPaths(dir) {
159
159
  const hivemindDir = path.join(dir, '.hivemind');
160
160
  const sessionsDir = path.join(hivemindDir, 'sessions');
161
+ const activeDir = path.join(sessionsDir, 'active');
161
162
  const archiveDir = path.join(sessionsDir, 'archive');
162
163
  const templatesDir = path.join(hivemindDir, 'templates');
164
+ const docsDir = path.join(hivemindDir, 'docs');
165
+
166
+ // Bridge: detect v2.0.0 structure (state/) vs legacy flat
167
+ const stateDir = path.join(hivemindDir, 'state');
168
+ const memoryDir = path.join(hivemindDir, 'memory');
169
+ const isNew = exists(stateDir) && exists(path.join(hivemindDir, 'manifest.json'));
170
+ const isLegacy = exists(path.join(hivemindDir, 'brain.json')) && !exists(stateDir);
171
+ // Fresh install or new structure → use state/ paths; legacy → flat paths
172
+ const brainPath = (isNew || !isLegacy) ? path.join(stateDir, 'brain.json') : path.join(hivemindDir, 'brain.json');
173
+ const hierarchyPath = (isNew || !isLegacy) ? path.join(stateDir, 'hierarchy.json') : path.join(hivemindDir, 'hierarchy.json');
174
+ const anchorsPath = (isNew || !isLegacy) ? path.join(stateDir, 'anchors.json') : path.join(hivemindDir, 'anchors.json');
175
+ const memsPath = (isNew || !isLegacy) ? path.join(memoryDir, 'mems.json') : path.join(hivemindDir, 'mems.json');
163
176
 
164
177
  // OpenCode config — check both .json and .jsonc
165
178
  let opencodeConfigPath = path.join(dir, 'opencode.json');
@@ -187,18 +200,19 @@ function getHiveMindPaths(dir) {
187
200
  return {
188
201
  project: dir,
189
202
  hivemind: hivemindDir,
190
- brain: path.join(hivemindDir, 'brain.json'),
203
+ brain: brainPath,
191
204
  config: path.join(hivemindDir, 'config.json'),
192
- hierarchy: path.join(hivemindDir, 'hierarchy.json'),
205
+ hierarchy: hierarchyPath,
206
+ anchors: anchorsPath,
207
+ mems: memsPath,
193
208
  manifest: path.join(sessionsDir, 'manifest.json'),
194
- indexMd: path.join(sessionsDir, 'index.md'),
209
+ indexMd: path.join(hivemindDir, 'INDEX.md'),
195
210
  activeMd: path.join(sessionsDir, 'active.md'),
211
+ activeDir,
196
212
  archive: archiveDir,
197
213
  templates: templatesDir,
198
214
  sessionTemplate: path.join(templatesDir, 'session.md'),
199
- commandments: path.join(hivemindDir, '10-commandments.md'),
200
- anchors: path.join(hivemindDir, 'anchors.json'),
201
- mems: path.join(hivemindDir, 'mems.json'),
215
+ commandments: path.join(docsDir, '10-commandments.md'),
202
216
  sessions: sessionsDir,
203
217
  opencode: { path: opencodeConfigPath, type: opencodeConfigType },
204
218
  globalOpencode: { path: globalOpencodeConfig, type: globalConfigType },
@@ -260,8 +274,8 @@ function cmdVerifyInstall(args) {
260
274
  const coreFiles = [
261
275
  ['brain.json', paths.brain],
262
276
  ['config.json', paths.config],
263
- ['index.md', paths.indexMd],
264
- ['active.md', paths.activeMd],
277
+ ['INDEX.md', paths.indexMd],
278
+ ['active-session', exists(paths.activeDir) ? paths.activeDir : paths.activeMd],
265
279
  ['10-commandments.md', paths.commandments],
266
280
  ];
267
281
 
@@ -656,7 +670,13 @@ function cmdEcosystemCheck(args) {
656
670
  }
657
671
 
658
672
  // 2. INIT: .hivemind/ exists with core files
659
- const coreFiles = [paths.brain, paths.config, paths.indexMd, paths.activeMd, paths.commandments];
673
+ const coreFiles = [
674
+ paths.brain,
675
+ paths.config,
676
+ paths.indexMd,
677
+ exists(paths.activeDir) ? paths.activeDir : paths.activeMd,
678
+ paths.commandments,
679
+ ];
660
680
  const existingCore = coreFiles.filter(f => exists(f));
661
681
  if (existingCore.length === coreFiles.length) {
662
682
  chain.push({ step: 'init', status: 'pass', detail: `${existingCore.length}/${coreFiles.length} files` });