hive-ai 0.1.0__tar.gz

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.
@@ -0,0 +1,25 @@
1
+ # Large stray artifact — not referenced by any code in hive/ (~257 MB)
2
+ ruvector.db
3
+
4
+ # Runtime SQLite stores (regenerated by init_db / live state)
5
+ *.db
6
+
7
+ # Python bytecode + caches
8
+ __pycache__/
9
+ *.py[cod]
10
+ *.egg-info/
11
+ .pytest_cache/
12
+
13
+ # Build / packaging artifacts (regenerated by `python -m build` / npm)
14
+ dist/
15
+ build/
16
+ node_modules/
17
+
18
+ # Tooling output (regenerated)
19
+ graphify-out/
20
+
21
+ # Local fastembed / HuggingFace model cache, if any lands in-tree
22
+ .fastembed_cache/
23
+
24
+ # Local-only editor / agent settings
25
+ .claude/settings.local.json
hive_ai-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TejesMunde
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
hive_ai-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: hive-ai
3
+ Version: 0.1.0
4
+ Summary: Persistent, cross-agent memory for AI coding agents — a write-guarded, hybrid-retrieval decision store.
5
+ Project-URL: Homepage, https://github.com/TejesMunde/hive-mind
6
+ Project-URL: Repository, https://github.com/TejesMunde/hive-mind
7
+ Project-URL: Issues, https://github.com/TejesMunde/hive-mind/issues
8
+ Author: TejesMunde
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,claude,coding-agent,embeddings,llm,memory,rag,retrieval,sqlite
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Classifier: Topic :: Software Development :: Libraries
21
+ Requires-Python: >=3.10
22
+ Provides-Extra: dense
23
+ Requires-Dist: fastembed; extra == 'dense'
24
+ Requires-Dist: numpy; extra == 'dense'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # 🐝 Hive Mind
28
+
29
+ **Persistent, cross-agent memory for AI coding agents.**
30
+
31
+ Every time you start a fresh AI coding session, the agent forgets everything. You
32
+ re-explain "we chose Postgres over Mongo because of multi-document transactions,"
33
+ re-describe the architecture, re-justify decisions that were settled weeks ago.
34
+ Hive Mind fixes that: it's a local, file-based memory store that any agent reads
35
+ before it works and writes to after — so decisions, dead ends, and context survive
36
+ across sessions **and across different agents**.
37
+
38
+ ```python
39
+ from hive import read_memory, write_memory
40
+
41
+ # Before working: inherit everything the last agent knew
42
+ ctx = read_memory(project="my-api", query="add rate limiting to the public API")
43
+
44
+ # After deciding: leave it for the next agent
45
+ write_memory("decision", "my-api", {
46
+ "what": "Token-bucket rate limiting at the gateway, 100 req/s per key",
47
+ "why": "Sliding-window was 3x the Redis ops; token-bucket is good enough",
48
+ })
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Why it's different
54
+
55
+ Most "memory" tools are a dump of embeddings you hope are relevant. Hive Mind is
56
+ opinionated about **quality** and **trust**:
57
+
58
+ - **A write guard nothing bypasses.** Every write passes 6 rules (required fields,
59
+ vagueness, exact/fuzzy duplicates, contradictions, missing rationale) *before* it
60
+ touches the store. Bad writes go to a review queue, not the bin — so even rejects
61
+ are signal.
62
+ - **Hybrid retrieval that actually wins.** TF-IDF keyword precision fused with dense
63
+ semantic recall (RRF). Beats pure keyword search on every metric and holds across
64
+ 54× corpus growth.
65
+ - **Memory that ages honestly.** Confidence decays on a half-life; stale decisions
66
+ fall out of the working set; re-affirming one resets its clock. Computed at read
67
+ time — stored data is never silently mutated.
68
+ - **Provenance, not just answers.** Record what you *ruled out* and link it to what
69
+ you chose. Later: "what did we consider before this?"
70
+ - **It captures itself.** A git post-commit hook extracts decisions straight from
71
+ commit messages — gated by a quality floor, never bypassing the guard.
72
+ - **Local-first, zero setup.** One SQLite file that survives `git clone`. No server,
73
+ no vector DB, no cloud. Pure-stdlib core; the semantic layer is optional.
74
+
75
+ ---
76
+
77
+ ## Install
78
+
79
+ Pick whichever fits your stack — all three install the same `hive` CLI and the
80
+ importable `hive` Python package:
81
+
82
+ ```bash
83
+ # Python (recommended)
84
+ pipx install hive-mind # isolated, or:
85
+ pip install hive-mind
86
+
87
+ # npm (thin launcher around the Python package — needs Python 3.10+)
88
+ npm install -g hive-mind
89
+
90
+ # curl
91
+ curl -fsSL https://raw.githubusercontent.com/TejesMunde/hive-mind/main/install.sh | sh
92
+ # Windows PowerShell:
93
+ # irm https://raw.githubusercontent.com/TejesMunde/hive-mind/main/install.ps1 | iex
94
+ ```
95
+
96
+ > The npm and curl installers bootstrap the Python package, so **Python 3.10+** must
97
+ > be on the machine. (Zero-Python standalone binaries are a planned follow-up.)
98
+
99
+ The **semantic (dense) retrieval layer is optional**. Install it as an extra; without
100
+ it the reader degrades silently to TF-IDF:
101
+
102
+ ```bash
103
+ pip install "hive-mind[dense]" # adds numpy + fastembed
104
+ ```
105
+
106
+ Verify, then use it:
107
+
108
+ ```bash
109
+ hive --version
110
+ hive --help
111
+ ```
112
+
113
+ ```python
114
+ from hive import init_db
115
+ init_db() # idempotent: creates tables + runs migrations
116
+ ```
117
+
118
+ ### From source
119
+
120
+ ```bash
121
+ git clone https://github.com/TejesMunde/hive-mind.git
122
+ cd hive-mind
123
+ pip install -e ".[dense]"
124
+ ```
125
+
126
+ ---
127
+
128
+ ## Quick start
129
+
130
+ ```python
131
+ from hive import init_db, read_memory, write_memory
132
+ from hive.core.writer import close_task
133
+
134
+ init_db()
135
+ project = "my-api"
136
+
137
+ # Record a decision (passes the write guard)
138
+ write_memory("decision", project, {
139
+ "what": "Chose PostgreSQL for the primary OLTP store",
140
+ "why": "ACID guarantees and JSONB fit the workload better than Mongo",
141
+ "agent": "claude-code",
142
+ })
143
+
144
+ # Track open work
145
+ write_memory("open_task", project, {"description": "Wire up connection pooling"})
146
+
147
+ # Later (or in another agent): retrieve ranked context
148
+ ctx = read_memory(project, query="what database are we using and why")
149
+ for d in ctx["warm"]["decisions"]:
150
+ print(d["score"], d["what"])
151
+ # ctx["hot"] → open tasks + latest snapshot
152
+ # ctx["warm"] → decisions ranked against the query
153
+ ```
154
+
155
+ ### Record what you ruled out (provenance)
156
+
157
+ ```python
158
+ from hive import write_memory, get_provenance
159
+
160
+ dec = write_memory("decision", project, {
161
+ "what": "Migrated the queue from RabbitMQ to Kafka",
162
+ "why": "Need partition ordering and replay for billing events"})
163
+
164
+ write_memory("dead_end", project, {
165
+ "what_tried": "Evaluated RabbitMQ for the event backbone",
166
+ "why_failed": "No native replay; ordering guarantees were per-queue only",
167
+ "chosen_decision_id": dec["id"]})
168
+
169
+ prov = get_provenance(dec["id"]) # {decision, dead_ends[], supersedes}
170
+ ```
171
+
172
+ ### Let confidence age, re-affirm what's still true
173
+
174
+ ```python
175
+ from hive import reinforce_decision, sweep_archive
176
+ reinforce_decision(decision_id) # +confidence, resets the decay clock, un-archives
177
+ sweep_archive(project) # cold-archive decisions whose decayed conf < 0.25
178
+ ```
179
+
180
+ ### Hand off to the next agent / route work
181
+
182
+ ```python
183
+ from hive import create_handoff, route_task
184
+
185
+ packet = create_handoff(project, from_agent="claude", to_agent="next")
186
+ # packet["state"] = open tasks + snapshot + top decisions
187
+ # packet["delta"] = what changed since the previous handoff
188
+
189
+ ranked = route_task(project, "add OAuth to the public API")
190
+ # -> [{agent, score, evidence:[...]}] (advisory only — never auto-assigns)
191
+ ```
192
+
193
+ ### Auto-capture decisions from git commits
194
+
195
+ ```bash
196
+ python -m hive.cli.hook install # idempotent post-commit hook (per repo)
197
+ python -m hive.cli.capture <sha> # what the hook runs: extract → guard → write
198
+ python -m hive.cli.capture stats # decisions at conf 1.0, by source, skip reasons
199
+ python -m hive.cli.capture calibrate 50 # LOG-ONLY pre-filter pass-rate + verdict
200
+ python -m hive.cli.hook uninstall # removes only Hive's hook block
201
+ ```
202
+
203
+ Only commits carrying decision language (`chose … over`, `switched to`, `because`, …)
204
+ clear the floor; survivors go through the **full guard** at reduced confidence (0.6),
205
+ tagged `source='git-hook'`. Sub-threshold commits are dropped and audited, never staged.
206
+
207
+ ---
208
+
209
+ ## How retrieval works
210
+
211
+ ```
212
+ query → normalize (case-fold, stopwords, stem, synonym-expand)
213
+ → TF-IDF overlap score (smoothed IDF, headline + recency + confidence boosts)
214
+ → hybrid rerank: pin the top TF-IDF hit, let dense embeddings reorder the head
215
+ → pack into a token budget (hot 500 / warm 2500)
216
+ ```
217
+
218
+ - **TF-IDF** — keyword precision, set-overlap on smoothed IDF.
219
+ - **Dense** — `BAAI/bge-small-en-v1.5` (384-dim, 33 MB, ONNX via fastembed, no torch).
220
+ - **Hybrid (RRF)** — fuses the two; pins the keyword #1 (confidence-gated) and lets
221
+ the embeddings reorder the rest of the head. The keyword anchor is what keeps it
222
+ robust at scale where dense-alone drifts to semantically-adjacent-but-wrong docs.
223
+
224
+ ### Benchmark
225
+
226
+ Measured against a labeled query/decision eval set (`tests/eval_corpus.json`):
227
+
228
+ | method | Recall@1 | Recall@3 | MRR |
229
+ |----------------------|----------|----------|-------|
230
+ | TF-IDF | 74.0% | 83.3% | 0.803 |
231
+ | dense | 60.4% | 80.2% | 0.721 |
232
+ | **hybrid (default)** | **79.2%**| **91.7%**| **0.856** |
233
+
234
+ Hybrid beats TF-IDF on every metric and every category, and **stays flat across 54×
235
+ corpus growth** (a cross-encoder reranker was evaluated and rejected — worse and
236
+ ~250× slower). Run it yourself:
237
+
238
+ ```bash
239
+ PYTHONIOENCODING=utf-8 python tests/bench_recall.py # tfidf vs dense vs hybrid
240
+ PYTHONIOENCODING=utf-8 python tests/bench_scale.py # recall + latency vs corpus size
241
+ ```
242
+
243
+ ---
244
+
245
+ ## The write guard
246
+
247
+ Every write — human, agent, or git-hook — passes through `hive/core/guard.py`
248
+ before commit. Order matters:
249
+
250
+ 1. Required fields present and non-empty
251
+ 2. Not vague (decisions/tasks need ≥ 5 words in the main field)
252
+ 3. Not an exact duplicate
253
+ 4. **Not a contradiction** of an existing decision (opposition markers, swapped sides)
254
+ 5. Not a fuzzy duplicate (Jaccard token overlap ≥ 0.45)
255
+ 6. Has a `why`
256
+
257
+ A flagged write isn't dropped — it goes to a **staging** queue for human review, or
258
+ is auto-rejected only if the system *learned* that category is reliably wrong for
259
+ this project. Review staged records:
260
+
261
+ ```bash
262
+ hive staging list # pending review
263
+ hive staging accept <id> # promote to the store
264
+ hive staging tune # learn auto-reject policies from history
265
+ hive audit tail # append-only event log
266
+ ```
267
+
268
+ ---
269
+
270
+ ## Command-line interface
271
+
272
+ Once installed, everything is under one `hive` command:
273
+
274
+ ```bash
275
+ hive recall <project> "<query>" # retrieve ranked context (JSON)
276
+ hive remember <project> "<what>" "<why>" # record a decision (through the guard)
277
+ hive capture <sha> | stats | calibrate # extract decisions from git commits
278
+ hive hook install | uninstall | status # post-commit capture hook
279
+ hive staging list | accept | reject | … # review guard-flagged writes
280
+ hive audit tail | counts | fails # append-only event log
281
+ hive init # inject Hive usage block into agent configs
282
+ hive --version | --help
283
+ ```
284
+
285
+ > Each subcommand is also runnable directly as `python -m hive.cli.<name>` if you
286
+ > prefer not to install the console script.
287
+
288
+ ---
289
+
290
+ ## Storage
291
+
292
+ A single SQLite file (`hive.db`, override with `HIVE_DB_PATH`). 10 tables:
293
+
294
+ | Table | Role |
295
+ |---|---|
296
+ | `decisions` | committed long-term decisions (warm tier) + supersession, archive, source |
297
+ | `snapshots` | latest project structure (hot tier) |
298
+ | `open_tasks` | live work items (hot tier) |
299
+ | `dead_ends` | rejected approaches, linked to the decision that replaced them |
300
+ | `staging` | writes the guard flagged for review |
301
+ | `staging_history` | reviewer outcomes — feeds the auto-tune learner |
302
+ | `guard_policy` | per-project, per-category action (`stage` / `auto_reject`) |
303
+ | `audit_log` | append-only event stream (every write + every query) |
304
+ | `decision_embeddings` | cached float32 embeddings per decision |
305
+ | `handoffs` | persisted agent handoff packets (state + delta) |
306
+
307
+ ---
308
+
309
+ ## Project layout
310
+
311
+ ```
312
+ hive/
313
+ __init__.py public API (read_memory, write_memory, get_provenance, …)
314
+ db/setup.py SQLite init + idempotent migrations
315
+ core/
316
+ guard.py 6 write-guard rules (never bypassed)
317
+ writer.py write_memory, close_task, reinforce/archive, staging promote
318
+ reader.py read_memory (hot + warm tiers), get_provenance
319
+ normalize.py tokeniser: stopwords, stemmer, synonym map
320
+ dense.py dense cosine + RRF hybrid fusion
321
+ embedder.py fastembed wrapper (bge-small-en-v1.5)
322
+ decay.py confidence decay + archive constants
323
+ handoff.py agent handoff packets (state + delta)
324
+ routing.py expertise routing (decay-aware, advisory)
325
+ extract.py pure commit → decision extractor (the quality floor)
326
+ policy.py per-project guard policy + auto-tune learner
327
+ audit.py append-only event log
328
+ cli/
329
+ staging.py audit.py init.py capture.py hook.py
330
+ tests/
331
+ test_day1.py … test_day11.py per-feature end-to-end tests
332
+ bench_recall.py bench_scale.py bench_rerank.py eval_corpus.json
333
+ ```
334
+
335
+ ---
336
+
337
+ ## Running the tests
338
+
339
+ ```bash
340
+ # End-to-end feature tests (all must pass before any commit)
341
+ PYTHONIOENCODING=utf-8 python tests/test_day1.py # … through test_day11.py
342
+
343
+ # Retrieval benchmarks (must not regress below the table above)
344
+ PYTHONIOENCODING=utf-8 python tests/bench_recall.py
345
+ PYTHONIOENCODING=utf-8 python tests/bench_scale.py
346
+ ```
347
+
348
+ ---
349
+
350
+ ## Roadmap
351
+
352
+ - **Phase 1** — Core memory, write guard, staging, audit, auto-tune. ✅
353
+ - **Phase 2** — Semantic embeddings + hybrid RRF retrieval. ✅
354
+ - **Phase 3** — Dead ends, decision provenance, idempotent agent global config. ✅
355
+ - **Phase 4** — Confidence decay, cold archive, contradiction detection v2. ✅
356
+ - **Phase 5** — Agent handoff packets, decay-aware expertise routing. ✅
357
+ - **Phase 6** — Git-commit decision extraction (quality floor + post-commit hook). ✅
358
+ - **Phase 7** — Distribution: PyPI + npm + curl install, unified `hive` CLI, MIT license. ✅
359
+ - **Later** — zero-Python standalone binaries (PyInstaller + GitHub Releases),
360
+ file watcher / daemon, vectorized TF-IDF for large corpora.
361
+
362
+ ---
363
+
364
+ ## Design principles
365
+
366
+ - **Never bypass the write guard** — one corrupt record poisons every future retrieval.
367
+ - **Reads are side-effect free** — decay and ranking never mutate stored data, so the
368
+ benchmark stays honest.
369
+ - **The TF-IDF fallback must always work** — the dense path is strictly optional.
370
+ - **Staging over deletion** — deleted bad data gives no signal; every staged record
371
+ is feedback for the learner.
372
+ - **Local-first** — no vector DB until records exceed the benchmarked crossover point.
373
+
374
+ ---
375
+
376
+ ## License
377
+
378
+ [MIT](LICENSE) © TejesMunde.