hivemind-context-governance 1.3.0 → 2.5.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.
- package/CHANGELOG.md +167 -0
- package/README.md +200 -159
- package/bin/hivemind-tools.cjs +1340 -0
- package/dist/cli/init.d.ts +10 -2
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +173 -25
- package/dist/cli/init.js.map +1 -1
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -1
- package/dist/hooks/compaction.d.ts +8 -1
- package/dist/hooks/compaction.d.ts.map +1 -1
- package/dist/hooks/compaction.js +78 -14
- package/dist/hooks/compaction.js.map +1 -1
- package/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +3 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/session-lifecycle.d.ts +17 -7
- package/dist/hooks/session-lifecycle.d.ts.map +1 -1
- package/dist/hooks/session-lifecycle.js +292 -42
- package/dist/hooks/session-lifecycle.js.map +1 -1
- package/dist/hooks/soft-governance.d.ts +38 -0
- package/dist/hooks/soft-governance.d.ts.map +1 -0
- package/dist/hooks/soft-governance.js +184 -0
- package/dist/hooks/soft-governance.js.map +1 -0
- package/dist/hooks/tool-gate.d.ts +20 -3
- package/dist/hooks/tool-gate.d.ts.map +1 -1
- package/dist/hooks/tool-gate.js +62 -40
- package/dist/hooks/tool-gate.js.map +1 -1
- package/dist/index.d.ts +30 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -135
- package/dist/index.js.map +1 -1
- package/dist/lib/anchors.d.ts +16 -0
- package/dist/lib/anchors.d.ts.map +1 -0
- package/dist/lib/anchors.js +48 -0
- package/dist/lib/anchors.js.map +1 -0
- package/dist/lib/chain-analysis.d.ts +29 -0
- package/dist/lib/chain-analysis.d.ts.map +1 -0
- package/dist/lib/chain-analysis.js +59 -0
- package/dist/lib/chain-analysis.js.map +1 -0
- package/dist/lib/commit-advisor.d.ts +17 -0
- package/dist/lib/commit-advisor.d.ts.map +1 -0
- package/dist/lib/commit-advisor.js +21 -0
- package/dist/lib/commit-advisor.js.map +1 -0
- package/dist/lib/complexity.d.ts +5 -14
- package/dist/lib/complexity.d.ts.map +1 -1
- package/dist/lib/complexity.js +4 -24
- package/dist/lib/complexity.js.map +1 -1
- package/dist/lib/detection.d.ts +184 -0
- package/dist/lib/detection.d.ts.map +1 -0
- package/dist/lib/detection.js +498 -0
- package/dist/lib/detection.js.map +1 -0
- package/dist/lib/hierarchy-tree.d.ts +290 -0
- package/dist/lib/hierarchy-tree.d.ts.map +1 -0
- package/dist/lib/hierarchy-tree.js +633 -0
- package/dist/lib/hierarchy-tree.js.map +1 -0
- package/dist/lib/index.d.ts +10 -2
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +11 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/long-session.d.ts +16 -0
- package/dist/lib/long-session.d.ts.map +1 -0
- package/dist/lib/long-session.js +15 -0
- package/dist/lib/long-session.js.map +1 -0
- package/dist/lib/mems.d.ts +25 -0
- package/dist/lib/mems.d.ts.map +1 -0
- package/dist/lib/mems.js +84 -0
- package/dist/lib/mems.js.map +1 -0
- package/dist/lib/persistence.d.ts.map +1 -1
- package/dist/lib/persistence.js +37 -5
- package/dist/lib/persistence.js.map +1 -1
- package/dist/lib/planning-fs.d.ts +140 -1
- package/dist/lib/planning-fs.d.ts.map +1 -1
- package/dist/lib/planning-fs.js +377 -15
- package/dist/lib/planning-fs.js.map +1 -1
- package/dist/lib/sentiment.d.ts +3 -19
- package/dist/lib/sentiment.d.ts.map +1 -1
- package/dist/lib/sentiment.js +4 -153
- package/dist/lib/sentiment.js.map +1 -1
- package/dist/lib/session-export.d.ts +33 -0
- package/dist/lib/session-export.d.ts.map +1 -0
- package/dist/lib/session-export.js +74 -0
- package/dist/lib/session-export.js.map +1 -0
- package/dist/lib/staleness.d.ts +12 -0
- package/dist/lib/staleness.d.ts.map +1 -0
- package/dist/lib/staleness.js +17 -0
- package/dist/lib/staleness.js.map +1 -0
- package/dist/lib/tool-activation.d.ts +23 -0
- package/dist/lib/tool-activation.d.ts.map +1 -0
- package/dist/lib/tool-activation.js +71 -0
- package/dist/lib/tool-activation.js.map +1 -0
- package/dist/schemas/brain-state.d.ts +62 -4
- package/dist/schemas/brain-state.d.ts.map +1 -1
- package/dist/schemas/brain-state.js +77 -21
- package/dist/schemas/brain-state.js.map +1 -1
- package/dist/schemas/config.d.ts +11 -0
- package/dist/schemas/config.d.ts.map +1 -1
- package/dist/schemas/config.js +12 -1
- package/dist/schemas/config.js.map +1 -1
- package/dist/schemas/hierarchy.d.ts +0 -7
- package/dist/schemas/hierarchy.d.ts.map +1 -1
- package/dist/schemas/hierarchy.js +2 -8
- package/dist/schemas/hierarchy.js.map +1 -1
- package/dist/tools/check-drift.d.ts +7 -0
- package/dist/tools/check-drift.d.ts.map +1 -0
- package/dist/tools/check-drift.js +80 -0
- package/dist/tools/check-drift.js.map +1 -0
- package/dist/tools/compact-session.d.ts +45 -0
- package/dist/tools/compact-session.d.ts.map +1 -1
- package/dist/tools/compact-session.js +253 -14
- package/dist/tools/compact-session.js.map +1 -1
- package/dist/tools/declare-intent.d.ts +6 -0
- package/dist/tools/declare-intent.d.ts.map +1 -1
- package/dist/tools/declare-intent.js +59 -6
- package/dist/tools/declare-intent.js.map +1 -1
- package/dist/tools/export-cycle.d.ts +20 -0
- package/dist/tools/export-cycle.d.ts.map +1 -0
- package/dist/tools/export-cycle.js +116 -0
- package/dist/tools/export-cycle.js.map +1 -0
- package/dist/tools/hierarchy.d.ts +28 -0
- package/dist/tools/hierarchy.d.ts.map +1 -0
- package/dist/tools/hierarchy.js +112 -0
- package/dist/tools/hierarchy.js.map +1 -0
- package/dist/tools/index.d.ts +24 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +24 -5
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/list-shelves.d.ts +13 -0
- package/dist/tools/list-shelves.d.ts.map +1 -0
- package/dist/tools/list-shelves.js +61 -0
- package/dist/tools/list-shelves.js.map +1 -0
- package/dist/tools/map-context.d.ts +7 -0
- package/dist/tools/map-context.d.ts.map +1 -1
- package/dist/tools/map-context.js +128 -10
- package/dist/tools/map-context.js.map +1 -1
- package/dist/tools/recall-mems.d.ts +13 -0
- package/dist/tools/recall-mems.d.ts.map +1 -0
- package/dist/tools/recall-mems.js +59 -0
- package/dist/tools/recall-mems.js.map +1 -0
- package/dist/tools/save-anchor.d.ts +7 -0
- package/dist/tools/save-anchor.d.ts.map +1 -0
- package/dist/tools/save-anchor.js +40 -0
- package/dist/tools/save-anchor.js.map +1 -0
- package/dist/tools/save-mem.d.ts +13 -0
- package/dist/tools/save-mem.d.ts.map +1 -0
- package/dist/tools/save-mem.js +52 -0
- package/dist/tools/save-mem.js.map +1 -0
- package/dist/tools/scan-hierarchy.d.ts +9 -0
- package/dist/tools/scan-hierarchy.d.ts.map +1 -0
- package/dist/tools/scan-hierarchy.js +71 -0
- package/dist/tools/scan-hierarchy.js.map +1 -0
- package/dist/tools/self-rate.js +5 -5
- package/dist/tools/self-rate.js.map +1 -1
- package/dist/tools/think-back.d.ts +9 -0
- package/dist/tools/think-back.d.ts.map +1 -0
- package/dist/tools/think-back.js +127 -0
- package/dist/tools/think-back.js.map +1 -0
- package/docs/10-commandments.md +202 -0
- package/package.json +14 -8
- package/skills/context-integrity/SKILL.md +185 -0
- package/skills/delegation-intelligence/SKILL.md +154 -0
- package/skills/evidence-discipline/SKILL.md +117 -0
- package/skills/hivemind-governance/SKILL.md +104 -0
- package/skills/session-lifecycle/SKILL.md +180 -0
- package/dist/dashboard/i18n/en.d.ts +0 -43
- package/dist/dashboard/i18n/en.d.ts.map +0 -1
- package/dist/dashboard/i18n/en.js +0 -43
- package/dist/dashboard/i18n/en.js.map +0 -1
- package/dist/dashboard/i18n/index.d.ts +0 -10
- package/dist/dashboard/i18n/index.d.ts.map +0 -1
- package/dist/dashboard/i18n/index.js +0 -14
- package/dist/dashboard/i18n/index.js.map +0 -1
- package/dist/dashboard/i18n/vi.d.ts +0 -43
- package/dist/dashboard/i18n/vi.d.ts.map +0 -1
- package/dist/dashboard/i18n/vi.js +0 -43
- package/dist/dashboard/i18n/vi.js.map +0 -1
- package/dist/lib/context-refresh.d.ts +0 -46
- package/dist/lib/context-refresh.d.ts.map +0 -1
- package/dist/lib/context-refresh.js +0 -77
- package/dist/lib/context-refresh.js.map +0 -1
- package/src/cli/init.ts +0 -214
- package/src/cli.ts +0 -178
- package/src/dashboard/i18n/en.ts +0 -43
- package/src/dashboard/i18n/index.ts +0 -20
- package/src/dashboard/i18n/vi.ts +0 -43
- package/src/dashboard/server.ts +0 -372
- package/src/hooks/compaction.ts +0 -104
- package/src/hooks/index.ts +0 -8
- package/src/hooks/session-lifecycle.ts +0 -133
- package/src/hooks/tool-gate.ts +0 -205
- package/src/index.ts +0 -206
- package/src/lib/complexity.ts +0 -96
- package/src/lib/context-refresh.ts +0 -107
- package/src/lib/index.ts +0 -10
- package/src/lib/logging.ts +0 -53
- package/src/lib/persistence.ts +0 -83
- package/src/lib/planning-fs.ts +0 -187
- package/src/lib/sentiment.ts +0 -183
- package/src/schemas/brain-state.ts +0 -257
- package/src/schemas/config.ts +0 -184
- package/src/schemas/hierarchy.ts +0 -58
- package/src/schemas/index.ts +0 -7
- package/src/tools/compact-session.ts +0 -97
- package/src/tools/declare-intent.ts +0 -104
- package/src/tools/index.ts +0 -14
- package/src/tools/map-context.ts +0 -105
- package/src/tools/self-rate.ts +0 -86
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,164 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.5.0] - 2026-02-12
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Evidence Gate System** — Escalating prompt pressure with 4 tiers (INFO → WARN → CRITICAL → DEGRADED) that intensify over unresolved turns
|
|
12
|
+
- **Evidence-based argument-back** — Every detection signal now includes data-backed evidence strings and counter-arguments against common agent excuses
|
|
13
|
+
- **"I am retard" mode** — New `automationLevel` CLI option with 5 levels (manual/guided/assisted/full/retard); retard mode forces strict governance, skeptical output, code review, max handholding
|
|
14
|
+
- **Write-without-read tracking (FileGuard)** — `soft-governance.ts` tracks blind file writes; detection engine generates `write_without_read` signal with evidence
|
|
15
|
+
- **`AutomationLevel` config type** — Persisted in `config.json`, read by hooks every turn (Rule 6)
|
|
16
|
+
- **`compileEscalatedSignals()`** — New entry point for evidence-based prompt injection, wraps `compileSignals()` with tiers + evidence + counter-excuses
|
|
17
|
+
- **`computeEscalationTier()`** — Pure function: turns × threshold → tier classification
|
|
18
|
+
- **44 new test assertions** — Evidence gate system tests: escalation, evidence quality, retard mode init, format compatibility (688 total)
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- **Session lifecycle hook** — Now uses `compileEscalatedSignals()` instead of `compileSignals()` for richer prompt injection
|
|
22
|
+
- **Prompt format** — Escalated signals show `[TIER] message`, `EVIDENCE: data`, `↳ counter-argument` (backward compatible with non-escalated signals)
|
|
23
|
+
- **Retard mode auto-config** — Forces strict governance, beginner expert level, skeptical output, code review required, be_skeptical=true
|
|
24
|
+
- **Archived 9 historical plan documents** to `docs/archive/`
|
|
25
|
+
|
|
26
|
+
## [2.3.0] - 2026-02-12
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
- **Entry chain edge case tests** — JSONC config handling, re-init guard, config persistence verification (14 new assertions)
|
|
30
|
+
- **Config persistence verification** — `loadConfig` deep-merges constraints with defaults, partial updates preserve existing values
|
|
31
|
+
- **Re-init guard** — `hivemind init` no longer overwrites existing config (preserves governance_mode, language)
|
|
32
|
+
|
|
33
|
+
### Fixed
|
|
34
|
+
- **JSONC config handling** — `opencode.jsonc` files now parsed correctly (was crashing on trailing commas/comments)
|
|
35
|
+
- **Master plan file tree accuracy** — docs now match actual output of `hivemind init`
|
|
36
|
+
- **Frozen config (L8)** — All 3 hooks now re-read config from disk each invocation via `loadConfig(directory)` instead of using stale closure values
|
|
37
|
+
- **Tool gate duplication (L9)** — Removed 130-line duplicated `createToolGateHookInternal` body; now delegates to `createToolGateHook().internal`
|
|
38
|
+
- **Dead sentiment_signals field (L10)** — Removed deprecated `SentimentSignal` type and `sentiment_signals: []` from BrainState schema
|
|
39
|
+
- **README accuracy (L1)** — Updated from "11 tools, 386 assertions" to "14 tools, 621 assertions"
|
|
40
|
+
- **CLI --help (L5)** — `--help` and `-h` flags now show help instead of running init
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
- Hook factories accept `_initConfig` parameter (unused — config read from disk per Rule 6)
|
|
44
|
+
- `bin/hivemind-tools.cjs` and `skills/` added to package.json `files` array for npm shipping
|
|
45
|
+
- Removed stale `tasks/prd-production-ready.md` and orphan `session-ses_3b3a.md`
|
|
46
|
+
|
|
47
|
+
### Removed
|
|
48
|
+
- `SentimentSignal` interface and `sentiment_signals` field from BrainState
|
|
49
|
+
- Duplicated `createToolGateHookInternal` function body (kept as thin wrapper for backward compat)
|
|
50
|
+
- `src/lib/sentiment.ts` export from barrel (file retained for git history)
|
|
51
|
+
|
|
52
|
+
## [2.2.0] - 2026-02-12
|
|
53
|
+
|
|
54
|
+
### Added
|
|
55
|
+
- **export_cycle tool** (14th tool) — Captures subagent results into hierarchy tree + mems brain
|
|
56
|
+
- **Auto-capture hook** — `tool.execute.after` auto-captures all Task tool returns into `brain.cycle_log[]`
|
|
57
|
+
- **Pending failure acknowledgment** — `pending_failure_ack` flag set when subagent reports failure; system prompt warns until agent acknowledges
|
|
58
|
+
- **Skill system** (5 skills) — Behavioral governance through skills: `hivemind-governance` (bootstrap), `session-lifecycle`, `evidence-discipline`, `context-integrity`, `delegation-intelligence`
|
|
59
|
+
- **Tool activation engine** (7 priorities) — Suggests next tool based on session state (LOCKED → declare_intent, high drift → map_context, etc.)
|
|
60
|
+
- **Enhanced CLI** — `bin/hivemind-tools.cjs` expanded to 23 commands (source-audit, list-tools, list-hooks, verify-package, etc.)
|
|
61
|
+
- 36 new test assertions for cycle intelligence
|
|
62
|
+
- Entry chain E2E tests (56 assertions)
|
|
63
|
+
|
|
64
|
+
## [2.1.0] - 2026-02-11
|
|
65
|
+
|
|
66
|
+
### Added
|
|
67
|
+
- **Hierarchy tree engine** — Navigable tree with timestamp-based stamps, DFS traversal, cursor tracking
|
|
68
|
+
- **Detection engine** — Tool classification (read/write/query/governance), counter logic, keyword scanning, signal compilation
|
|
69
|
+
- **Per-session files** — Each session archived with `.json` export + `.md` export
|
|
70
|
+
- **Session manifest** — `manifest.json` registry of all sessions
|
|
71
|
+
- **Configurable thresholds** — `detection_thresholds` in config for turn count, failures, section repetition
|
|
72
|
+
- **Migration path** — `hierarchy_migrate` tool converts flat hierarchy to tree format
|
|
73
|
+
- **hierarchy_prune tool** — Removes completed branches, moves cursor to root
|
|
74
|
+
- **Compact purification** — `compact_session` generates next-compaction report for context preservation
|
|
75
|
+
- 2 new tools: `hierarchy_prune`, `hierarchy_migrate` (13 total)
|
|
76
|
+
- 158 new test assertions (hierarchy tree 55, detection 45, compact purification 34, entry chain 24)
|
|
77
|
+
|
|
78
|
+
### Changed
|
|
79
|
+
- Session lifecycle hook now compiles detection signals into `<hivemind>` prompt injection
|
|
80
|
+
- Soft governance hook now runs full detection engine (tool classification, keyword scanning, failure tracking)
|
|
81
|
+
- Tree-aware chain analysis — detects timestamp gaps between nodes
|
|
82
|
+
- `max_active_md_lines` wired into detection thresholds
|
|
83
|
+
|
|
84
|
+
## [2.0.0] - 2026-02-11
|
|
85
|
+
|
|
86
|
+
### Breaking Changes
|
|
87
|
+
- System prompt injection restructured — uses `<hivemind>` tag instead of `<hivemind-governance>` and `<agent-configuration>`
|
|
88
|
+
- Commit suggestion removed from system prompt (was user concern, not agent concern)
|
|
89
|
+
- Mems count removed from system prompt (not actionable)
|
|
90
|
+
|
|
91
|
+
### Added
|
|
92
|
+
- **Priority-sectioned system prompt** — drops lowest priority sections when budget exceeded instead of malformed truncation
|
|
93
|
+
- **Anchor age indicators** — anchors in system prompt show `(Xh ago)` / `(Xd ago)`
|
|
94
|
+
- **Input validation** — all string args validated for non-empty content
|
|
95
|
+
- **Helper footers** — every tool output suggests the logical next action
|
|
96
|
+
- **Upsert for anchors** — updating an existing key shows the delta (was/now)
|
|
97
|
+
- **Memory deduplication** — save_mem rejects duplicate content on same shelf
|
|
98
|
+
- **Session awareness** — save_anchor/save_mem warn when no active session
|
|
99
|
+
- **Overwrite warning** — declare_intent warns when replacing an existing trajectory
|
|
100
|
+
- **Output budget** — think_back capped at 2000 chars, anchors at 5, plan at 10 lines
|
|
101
|
+
|
|
102
|
+
### Fixed
|
|
103
|
+
- **System prompt malformed XML** — truncation was closing `</agent-configuration>` inside `<hivemind-governance>` producing invalid XML
|
|
104
|
+
- **Hook inconsistency** — write tool lists now identical between before/after hooks (exact Set.has matching)
|
|
105
|
+
- **Fuzzy tool matching** — replaced dangerous `startsWith`/`includes` with exact `Set.has()`
|
|
106
|
+
- **Double save** — soft-governance hook consolidated to single disk write
|
|
107
|
+
- **Array mutation** — list-shelves sort no longer mutates shared state
|
|
108
|
+
- **scan_hierarchy JSON** — now returns structured text like all other tools
|
|
109
|
+
- **self_rate threshold** — score 6-7 now shows positive feedback instead of drift warning
|
|
110
|
+
|
|
111
|
+
### Changed
|
|
112
|
+
- System prompt budget increased from 1000 to 2500 chars
|
|
113
|
+
- Package.json: removed src/ from files, added exports field, tightened peerDependencies
|
|
114
|
+
- Error messages standardized with `ERROR:` prefix and guidance
|
|
115
|
+
- scan_hierarchy description differentiated from think_back
|
|
116
|
+
- save_anchor description removes "API keys" (security risk)
|
|
117
|
+
- README rewritten to document all 11 tools and 4 hooks
|
|
118
|
+
|
|
119
|
+
## [1.6.0] - 2026-02-11
|
|
120
|
+
|
|
121
|
+
### Fixed
|
|
122
|
+
- **SHOWSTOPPER**: Tool registration changed from array to named Record — tools were being registered as "0", "1", "2" instead of "declare_intent", "map_context", etc. Agents could not call any tool by name.
|
|
123
|
+
- **CRITICAL**: `hivemind init` crash on npm install — `docs/` directory now included in `package.json#files`
|
|
124
|
+
- **CRITICAL**: System transform hook now accepts `model` parameter matching SDK contract
|
|
125
|
+
- **CRITICAL**: Legacy `.opencode` path in self-rate tool changed to `.hivemind/logs`
|
|
126
|
+
- **HIGH**: Double-counting turn increments — `incrementTurnCount` removed from `tool.execute.before` hook (kept only in `tool.execute.after`)
|
|
127
|
+
- **MEDIUM**: All 11 tools now accept `ToolContext` parameter matching SDK `execute(args, context)` signature
|
|
128
|
+
|
|
129
|
+
### Changed
|
|
130
|
+
- Removed unused `zod` dependency from `package.json#dependencies` (SDK re-exports via `tool.schema.*`)
|
|
131
|
+
- Stale `.opencode/planning/` doc comment in `src/cli/init.ts` updated to `.hivemind/`
|
|
132
|
+
|
|
133
|
+
## [1.5.0] - 2026-02-11
|
|
134
|
+
|
|
135
|
+
### Added
|
|
136
|
+
- **Mems Brain** — Persistent, shelf-organized memory system for cross-session knowledge
|
|
137
|
+
- 3 new tools: `save_mem`, `list_shelves`, `recall_mems`
|
|
138
|
+
- Auto-mem on compaction: saves session summary to "sessions" shelf
|
|
139
|
+
- System prompt injection: mem count indicator
|
|
140
|
+
- Compaction context: injects recent mems for context preservation
|
|
141
|
+
- 40 new test assertions (Round 4)
|
|
142
|
+
|
|
143
|
+
## [1.4.0] - 2026-02-11
|
|
144
|
+
|
|
145
|
+
### Changed
|
|
146
|
+
- **BREAKING**: Migrated from `.opencode/planning/` to `.hivemind/` directory structure
|
|
147
|
+
- Plugin now creates `.hivemind/sessions/` for session state
|
|
148
|
+
- Added `.hivemind/10-commandments.md` (tool design reference)
|
|
149
|
+
- `.hivemind/plans/` for plan storage (not `.plan/plans/`)
|
|
150
|
+
|
|
151
|
+
### Added
|
|
152
|
+
- 10 Commandments document for tool design principles
|
|
153
|
+
- `.hivemind/` directory structure with sessions, brain, plans, logs subdirectories
|
|
154
|
+
- Git hooks setup script (scripts/setup-git-hooks.sh)
|
|
155
|
+
- Pre-commit hook for enforcing atomic commits and session awareness
|
|
156
|
+
|
|
157
|
+
### Fixed
|
|
158
|
+
- Path references throughout codebase, tests, documentation
|
|
159
|
+
|
|
160
|
+
### Migration Guide
|
|
161
|
+
Existing projects using `.opencode/planning/` can manually move files:
|
|
162
|
+
1. Create `.hivemind/` directory structure
|
|
163
|
+
2. Move `.opencode/planning/` contents to `.hivemind/`
|
|
164
|
+
3. Update `opencode.json` plugin registration if needed
|
|
165
|
+
|
|
8
166
|
## [1.3.0] - 2026-02-11
|
|
9
167
|
|
|
10
168
|
### Added
|
|
@@ -90,6 +248,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
90
248
|
- Session lifecycle management
|
|
91
249
|
- Planning directory structure (.opencode/planning/)
|
|
92
250
|
|
|
251
|
+
[2.3.0]: https://github.com/shynlee04/hivemind-plugin/compare/v2.2.0...v2.3.0
|
|
252
|
+
[2.2.0]: https://github.com/shynlee04/hivemind-plugin/compare/v2.1.0...v2.2.0
|
|
253
|
+
[2.1.0]: https://github.com/shynlee04/hivemind-plugin/compare/v2.0.0...v2.1.0
|
|
254
|
+
[2.0.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.6.0...v2.0.0
|
|
255
|
+
[1.6.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.5.0...v1.6.0
|
|
256
|
+
[1.5.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.4.0...v1.5.0
|
|
257
|
+
[1.4.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.3.0...v1.4.0
|
|
258
|
+
[1.3.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.2.1...v1.3.0
|
|
259
|
+
[1.2.1]: https://github.com/shynlee04/hivemind-plugin/compare/v1.2.0...v1.2.1
|
|
93
260
|
[1.2.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.1.0...v1.2.0
|
|
94
261
|
[1.1.0]: https://github.com/shynlee04/hivemind-plugin/compare/v1.0.0...v1.1.0
|
|
95
262
|
[1.0.0]: https://github.com/shynlee04/hivemind-plugin/releases/tag/v1.0.0
|
package/README.md
CHANGED
|
@@ -1,218 +1,259 @@
|
|
|
1
1
|
# HiveMind Context Governance
|
|
2
2
|
|
|
3
|
-
A lightweight context
|
|
3
|
+
A lightweight context governance layer for [OpenCode](https://opencode.ai) that prevents drift, manages session state, and preserves memory across agent lifecycles.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**14 tools** | **4 hooks** | **5 automation levels** | **688 test assertions**
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Quick Start
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- **3 Governance Modes**: Strict, Assisted, Permissive
|
|
13
|
-
- **4 Lifecycle Tools**: declare_intent, map_context, compact_session, self_rate
|
|
14
|
-
- **Session Archiving**: Automatic compaction and history tracking
|
|
15
|
-
- **Drift Detection**: Warnings when context goes stale
|
|
16
|
-
- **Sentiment Detection**: Automatic detection of negative signals and confusion
|
|
17
|
-
- **Complexity Nudges**: Gentle warnings when sessions get complex (3+ files or 5+ turns)
|
|
18
|
-
- **Self-Rating**: Agent self-assessment for drift tracking (1-10 scale)
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
9
|
+
```bash
|
|
10
|
+
# Install
|
|
11
|
+
npm install hivemind-context-governance
|
|
21
12
|
|
|
22
|
-
|
|
13
|
+
# Initialize in your project
|
|
14
|
+
npx hivemind init
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
npx hivemind
|
|
16
|
+
# Check status
|
|
17
|
+
npx hivemind status
|
|
26
18
|
```
|
|
27
19
|
|
|
28
|
-
This
|
|
29
|
-
1. Creates `.opencode/planning/` with session state files
|
|
30
|
-
2. Registers HiveMind in your `opencode.json` automatically
|
|
31
|
-
3. Next time you open OpenCode, HiveMind is active
|
|
20
|
+
This creates a `.hivemind/` directory and registers the plugin in `opencode.json`.
|
|
32
21
|
|
|
33
|
-
|
|
22
|
+
## How It Works
|
|
34
23
|
|
|
35
|
-
|
|
24
|
+
HiveMind uses a 3-level hierarchy to track what you're working on:
|
|
36
25
|
|
|
37
|
-
```
|
|
38
|
-
|
|
26
|
+
```
|
|
27
|
+
Trajectory (Level 1) → Tactic (Level 2) → Action (Level 3)
|
|
39
28
|
```
|
|
40
29
|
|
|
41
|
-
|
|
42
|
-
|--------|--------|---------|
|
|
43
|
-
| `--mode` | `strict`, `assisted`, `permissive` | `assisted` |
|
|
44
|
-
| `--lang` | `en`, `vi` | `en` |
|
|
30
|
+
Every session starts with `declare_intent`, which sets the trajectory and unlocks the session. As you work, `map_context` updates your current focus. When done, `compact_session` archives everything and resets.
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
The plugin fires 4 hooks automatically — injecting context into every LLM turn, tracking metrics after every tool call, enforcing governance before writes, and preserving hierarchy across context compaction.
|
|
33
|
+
|
|
34
|
+
## Governance Modes
|
|
35
|
+
|
|
36
|
+
| Mode | Behavior | Best For |
|
|
37
|
+
|------|----------|----------|
|
|
38
|
+
| **strict** | Session starts LOCKED. Warns on writes without intent. | High-compliance projects |
|
|
39
|
+
| **assisted** | Session starts OPEN. Guidance without blocking. | Most projects (default) |
|
|
40
|
+
| **permissive** | Always OPEN. Silent tracking only. | Maximum autonomy |
|
|
47
41
|
|
|
48
42
|
```bash
|
|
49
|
-
|
|
50
|
-
npx hivemind
|
|
51
|
-
npx hivemind
|
|
43
|
+
# Initialize with a specific mode
|
|
44
|
+
npx hivemind init --mode strict
|
|
45
|
+
npx hivemind init --mode assisted --lang vi
|
|
52
46
|
```
|
|
53
47
|
|
|
54
|
-
##
|
|
48
|
+
## Tools (14)
|
|
49
|
+
|
|
50
|
+
### Core (3 tools)
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
| Tool | When | What It Does |
|
|
53
|
+
|------|------|--------------|
|
|
54
|
+
| `declare_intent` | Starting work | Set your focus and mode. Unlocks the session. |
|
|
55
|
+
| `map_context` | Changing focus | Update trajectory/tactic/action hierarchy. |
|
|
56
|
+
| `compact_session` | Finishing work | Archive session and reset for next work. |
|
|
57
57
|
|
|
58
58
|
```typescript
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
level: "tactic",
|
|
68
|
-
content: "Set up JWT middleware",
|
|
69
|
-
status: "active"
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
// Rate your performance (self-assessment)
|
|
73
|
-
self_rate({
|
|
74
|
-
score: 8,
|
|
75
|
-
reason: "Making good progress on auth flow",
|
|
76
|
-
turn_context: "Currently testing JWT validation"
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
// Archive and reset
|
|
80
|
-
compact_session({
|
|
81
|
-
summary: "Auth system foundation complete"
|
|
82
|
-
})
|
|
59
|
+
declare_intent({ mode: "plan_driven", focus: "Build auth system" })
|
|
60
|
+
// → Session: "Build auth system". Mode: plan_driven. Status: OPEN.
|
|
61
|
+
|
|
62
|
+
map_context({ level: "tactic", content: "Implement JWT validation" })
|
|
63
|
+
// → [tactic] "Implement JWT validation" → active
|
|
64
|
+
|
|
65
|
+
compact_session({ summary: "Auth middleware complete" })
|
|
66
|
+
// → Archived. 15 turns, 4 files. 3 total archives.
|
|
83
67
|
```
|
|
84
68
|
|
|
85
|
-
|
|
69
|
+
### Self-Awareness (1 tool)
|
|
86
70
|
|
|
87
|
-
|
|
|
88
|
-
|
|
89
|
-
|
|
|
90
|
-
| **assisted** | Session starts OPEN. Warnings logged but not blocking. | Balanced guidance |
|
|
91
|
-
| **permissive** | Session always OPEN. Silent tracking only. | Maximum autonomy |
|
|
71
|
+
| Tool | When | What It Does |
|
|
72
|
+
|------|------|--------------|
|
|
73
|
+
| `self_rate` | Self-reflection | Rate your own performance (1-10) for drift detection. |
|
|
92
74
|
|
|
93
|
-
|
|
75
|
+
### Cognitive Mesh (4 tools)
|
|
94
76
|
|
|
95
|
-
|
|
77
|
+
| Tool | When | What It Does |
|
|
78
|
+
|------|------|--------------|
|
|
79
|
+
| `scan_hierarchy` | Quick status check | Snapshot of session state, metrics, anchors. |
|
|
80
|
+
| `save_anchor` | Saving immutable facts | Persist constraints that survive compaction. |
|
|
81
|
+
| `think_back` | Feeling lost | Deep refocus with plan review and chain analysis. |
|
|
82
|
+
| `check_drift` | Before completing | Verify alignment with declared trajectory. |
|
|
96
83
|
|
|
97
|
-
|
|
98
|
-
.opencode/planning/
|
|
99
|
-
├── index.md # Project trajectory
|
|
100
|
-
├── active.md # Current session
|
|
101
|
-
├── brain.json # Machine state
|
|
102
|
-
├── config.json # Settings
|
|
103
|
-
└── archive/ # Session history
|
|
104
|
-
└── session_2026-02-10_xxx.md
|
|
105
|
-
```
|
|
84
|
+
### Mems Brain (3 tools)
|
|
106
85
|
|
|
107
|
-
|
|
86
|
+
| Tool | When | What It Does |
|
|
87
|
+
|------|------|--------------|
|
|
88
|
+
| `save_mem` | Saving a lesson | Store decisions, patterns, errors to persistent memory. |
|
|
89
|
+
| `list_shelves` | Browsing memories | See what's in the Mems Brain by shelf. |
|
|
90
|
+
| `recall_mems` | Searching memories | Search past decisions and patterns by keyword. |
|
|
108
91
|
|
|
109
|
-
|
|
92
|
+
### Hierarchy Ops (2 tools)
|
|
110
93
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
- **Confusion indicators**: "I'm confused", "doesn't make sense", "unclear"
|
|
94
|
+
| Tool | When | What It Does |
|
|
95
|
+
|------|------|--------------|
|
|
96
|
+
| `hierarchy_prune` | Cleaning up | Remove completed branches from the tree. |
|
|
97
|
+
| `hierarchy_migrate` | Upgrading | Migrate flat hierarchy to navigable tree format. |
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
- 2 negative signals within 5 turns triggers a drift warning
|
|
119
|
-
- Warning logged to TUI: `[ContextRefresh] Drift detected. Consider compact_session.`
|
|
120
|
-
- Warning added to `active.md` for visibility
|
|
99
|
+
### Cycle Intelligence (1 tool)
|
|
121
100
|
|
|
122
|
-
|
|
101
|
+
| Tool | When | What It Does |
|
|
102
|
+
|------|------|--------------|
|
|
103
|
+
| `export_cycle` | After subagent returns | Capture subagent results into hierarchy + mems. |
|
|
123
104
|
|
|
124
|
-
|
|
105
|
+
## Hooks (4)
|
|
125
106
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
107
|
+
| Hook | Event | Purpose |
|
|
108
|
+
|------|-------|---------|
|
|
109
|
+
| `experimental.chat.system.transform` | Every LLM turn | Injects `<hivemind>` context into system prompt |
|
|
110
|
+
| `tool.execute.before` | Before tool calls | Governance enforcement (warns on writes without intent) |
|
|
111
|
+
| `tool.execute.after` | After tool calls | Tracks metrics, violations, drift detection |
|
|
112
|
+
| `experimental.session.compacting` | Context compaction | Preserves hierarchy across LLM context boundaries |
|
|
129
113
|
|
|
130
|
-
**
|
|
131
|
-
- One nudge per session (deduplicated)
|
|
132
|
-
- Resets when new intent is declared
|
|
133
|
-
- Logs: `[Nudge] Complexity rising (X files, Y turns). Consider declare_intent.`
|
|
114
|
+
> **Note:** In OpenCode v1.1+, `tool.execute.before` cannot block execution. HiveMind provides governance through warnings and tracking only.
|
|
134
115
|
|
|
135
|
-
##
|
|
116
|
+
## Configuration
|
|
136
117
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
┌─────────────▼───────────────────────────┐
|
|
150
|
-
│ 4 Lifecycle Tools │
|
|
151
|
-
│ ├─ declare_intent │
|
|
152
|
-
│ ├─ map_context │
|
|
153
|
-
│ ├─ compact_session │
|
|
154
|
-
│ └─ self_rate │
|
|
155
|
-
└─────────────┬───────────────────────────┘
|
|
156
|
-
│
|
|
157
|
-
┌─────────────▼───────────────────────────┐
|
|
158
|
-
│ State Management │
|
|
159
|
-
│ ├─ brain.json (runtime state) │
|
|
160
|
-
│ ├─ active.md (session focus) │
|
|
161
|
-
│ └─ index.md (project trajectory) │
|
|
162
|
-
└─────────────────────────────────────────┘
|
|
118
|
+
Configuration is stored in `.hivemind/config.json` and re-read from disk on every hook invocation (Rule 6: config persistence).
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"governance_mode": "assisted",
|
|
123
|
+
"max_turns_before_warning": 5,
|
|
124
|
+
"auto_compact_on_turns": 15,
|
|
125
|
+
"stale_session_days": 3,
|
|
126
|
+
"commit_suggestion_threshold": 3,
|
|
127
|
+
"max_active_md_lines": 50,
|
|
128
|
+
"language": "en"
|
|
129
|
+
}
|
|
163
130
|
```
|
|
164
131
|
|
|
165
|
-
##
|
|
132
|
+
## CLI
|
|
166
133
|
|
|
167
134
|
```bash
|
|
168
|
-
#
|
|
169
|
-
|
|
135
|
+
npx hivemind init # Initialize HiveMind in a project
|
|
136
|
+
npx hivemind init --mode strict # Initialize with strict governance
|
|
137
|
+
npx hivemind status # Check current state
|
|
138
|
+
npx hivemind help # Show help
|
|
139
|
+
npx hivemind --help # Show help
|
|
140
|
+
```
|
|
170
141
|
|
|
171
|
-
|
|
172
|
-
npm test
|
|
142
|
+
### Ecosystem Verification (`bin/hivemind-tools.cjs`)
|
|
173
143
|
|
|
174
|
-
|
|
175
|
-
|
|
144
|
+
```bash
|
|
145
|
+
node bin/hivemind-tools.cjs source-audit # Verify all source files
|
|
146
|
+
node bin/hivemind-tools.cjs list-tools # List all 14 tools
|
|
147
|
+
node bin/hivemind-tools.cjs list-hooks # List all 4 hooks
|
|
148
|
+
node bin/hivemind-tools.cjs verify-package # Check npm package completeness
|
|
149
|
+
```
|
|
176
150
|
|
|
177
|
-
|
|
178
|
-
npm run build
|
|
151
|
+
## Project Structure
|
|
179
152
|
|
|
180
|
-
|
|
181
|
-
|
|
153
|
+
```
|
|
154
|
+
.hivemind/
|
|
155
|
+
├── 10-commandments.md # Tool design reference
|
|
156
|
+
├── sessions/
|
|
157
|
+
│ ├── index.md # Project trajectory (goals, constraints, history)
|
|
158
|
+
│ ├── active.md # Current session
|
|
159
|
+
│ ├── manifest.json # Session registry
|
|
160
|
+
│ └── archive/ # Completed sessions
|
|
161
|
+
├── templates/
|
|
162
|
+
│ └── session.md # Session template
|
|
163
|
+
├── hierarchy.json # Navigable tree hierarchy
|
|
164
|
+
├── brain.json # Machine state (session, metrics, hierarchy)
|
|
165
|
+
├── config.json # Governance settings
|
|
166
|
+
├── anchors.json # Immutable facts
|
|
167
|
+
└── mems.json # Persistent memory brain
|
|
182
168
|
```
|
|
183
169
|
|
|
184
|
-
##
|
|
170
|
+
## Typical Workflow
|
|
185
171
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
| Init + Planning FS | 29 | ✅ Pass |
|
|
190
|
-
| Tool Gate (governance) | 12 | ✅ Pass |
|
|
191
|
-
| Self-Rate Tool | 28 | ✅ Pass |
|
|
192
|
-
| Integration Tests | 27 | ✅ Pass |
|
|
193
|
-
| **Total** | **131** | ✅ **All Pass** |
|
|
172
|
+
```
|
|
173
|
+
1. Start session
|
|
174
|
+
declare_intent({ mode: "plan_driven", focus: "Build auth system" })
|
|
194
175
|
|
|
195
|
-
|
|
176
|
+
2. Work on high-level planning
|
|
177
|
+
map_context({ level: "trajectory", content: "OAuth2 + JWT architecture" })
|
|
196
178
|
|
|
197
|
-
|
|
198
|
-
|
|
179
|
+
3. Switch to implementation
|
|
180
|
+
map_context({ level: "tactic", content: "Set up Passport.js" })
|
|
199
181
|
|
|
200
|
-
|
|
182
|
+
4. Specific action
|
|
183
|
+
map_context({ level: "action", content: "Install passport-jwt package" })
|
|
184
|
+
[do the work...]
|
|
201
185
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
| **User-driven** | No agent hierarchy — you control the workflow |
|
|
206
|
-
| **Soft enforcement** | Warns and logs, never hard-blocks |
|
|
207
|
-
| **Session brain** | Every session is archived and traceable |
|
|
208
|
-
| **Drift-aware** | Automatic detection via sentiment + complexity |
|
|
209
|
-
| **Self-assessment** | Built-in 1-10 scale rating for agent self-awareness |
|
|
186
|
+
5. Mark complete, next action
|
|
187
|
+
map_context({ level: "action", content: "Install passport-jwt", status: "complete" })
|
|
188
|
+
map_context({ level: "action", content: "Configure JWT strategy" })
|
|
210
189
|
|
|
211
|
-
|
|
190
|
+
6. Finish session
|
|
191
|
+
compact_session({ summary: "Auth system foundation complete" })
|
|
192
|
+
```
|
|
212
193
|
|
|
213
|
-
|
|
214
|
-
|
|
194
|
+
## Test Coverage
|
|
195
|
+
|
|
196
|
+
| Component | Assertions |
|
|
197
|
+
|-----------|-----------|
|
|
198
|
+
| Schema (BrainState, Hierarchy) | 35 |
|
|
199
|
+
| Init + Planning FS | 30 |
|
|
200
|
+
| Tool Gate (governance) | 12 |
|
|
201
|
+
| Soft Governance (tracking) | 27 |
|
|
202
|
+
| Self-Rate Tool | 28 |
|
|
203
|
+
| Complexity Detection | 28 |
|
|
204
|
+
| Integration (E2E workflow) | 74 |
|
|
205
|
+
| Auto-Hooks Pure Functions | 39 |
|
|
206
|
+
| Session Export | 32 |
|
|
207
|
+
| Session Structure | 18 |
|
|
208
|
+
| Round 3 Tools (Cognitive Mesh) | 32 |
|
|
209
|
+
| Round 4 Mems Brain | 40 |
|
|
210
|
+
| Hierarchy Tree Engine | 55 |
|
|
211
|
+
| Detection Engine | 45 |
|
|
212
|
+
| Compact Purification | 34 |
|
|
213
|
+
| Entry Chain (E2E lifecycle) | 56 |
|
|
214
|
+
| Cycle Intelligence | 36 |
|
|
215
|
+
| **Total** | **621** |
|
|
215
216
|
|
|
216
217
|
## License
|
|
217
218
|
|
|
218
219
|
MIT
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Tiếng Việt
|
|
224
|
+
|
|
225
|
+
### HiveMind là gì?
|
|
226
|
+
|
|
227
|
+
HiveMind là một lớp quản lý ngữ cảnh nhẹ cho OpenCode, giúp ngăn chặn sai lệch (drift) và quản lý trạng thái phiên làm việc xuyên suốt vòng đời của agent AI.
|
|
228
|
+
|
|
229
|
+
### Bắt đầu nhanh
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm install hivemind-context-governance
|
|
233
|
+
npx hivemind init --lang vi
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Các chế độ quản lý
|
|
237
|
+
|
|
238
|
+
| Chế độ | Hành vi |
|
|
239
|
+
|--------|---------|
|
|
240
|
+
| **strict** | Phiên bắt đầu ở trạng thái KHÓA. Cảnh báo khi ghi mà chưa khai báo ý định. |
|
|
241
|
+
| **assisted** | Phiên bắt đầu ở trạng thái MỞ. Hướng dẫn nhưng không chặn. |
|
|
242
|
+
| **permissive** | Luôn MỞ. Chỉ theo dõi im lặng. |
|
|
243
|
+
|
|
244
|
+
### 14 Công cụ
|
|
245
|
+
|
|
246
|
+
- **Cốt lõi:** `declare_intent`, `map_context`, `compact_session`
|
|
247
|
+
- **Tự đánh giá:** `self_rate`
|
|
248
|
+
- **Lưới nhận thức:** `scan_hierarchy`, `save_anchor`, `think_back`, `check_drift`
|
|
249
|
+
- **Bộ nhớ:** `save_mem`, `list_shelves`, `recall_mems`
|
|
250
|
+
- **Phân cấp:** `hierarchy_prune`, `hierarchy_migrate`
|
|
251
|
+
- **Chu trình:** `export_cycle`
|
|
252
|
+
|
|
253
|
+
### Quy trình làm việc
|
|
254
|
+
|
|
255
|
+
1. Khai báo ý định → `declare_intent`
|
|
256
|
+
2. Cập nhật ngữ cảnh → `map_context`
|
|
257
|
+
3. Làm việc → sử dụng các công cụ nhận thức khi cần
|
|
258
|
+
4. Lưu bài học → `save_mem`, `save_anchor`
|
|
259
|
+
5. Kết thúc → `compact_session`
|