hkos 1.0.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.
Files changed (167) hide show
  1. hkos-1.0.0/LICENSE +21 -0
  2. hkos-1.0.0/PKG-INFO +307 -0
  3. hkos-1.0.0/README.md +275 -0
  4. hkos-1.0.0/__init__.py +37 -0
  5. hkos-1.0.0/api/__init__.py +0 -0
  6. hkos-1.0.0/campaign/__init__.py +0 -0
  7. hkos-1.0.0/config/__init__.py +0 -0
  8. hkos-1.0.0/config/hkos-development.yaml +151 -0
  9. hkos-1.0.0/config/hkos-production.yaml +125 -0
  10. hkos-1.0.0/config/logging.yaml +44 -0
  11. hkos-1.0.0/context/__init__.py +58 -0
  12. hkos-1.0.0/context/context_builder.py +199 -0
  13. hkos-1.0.0/context/context_manager.py +113 -0
  14. hkos-1.0.0/context/context_optimizer.py +184 -0
  15. hkos-1.0.0/context/context_serializer.py +154 -0
  16. hkos-1.0.0/context/context_statistics.py +48 -0
  17. hkos-1.0.0/context/context_validator.py +90 -0
  18. hkos-1.0.0/context/exceptions.py +21 -0
  19. hkos-1.0.0/context/models.py +98 -0
  20. hkos-1.0.0/context/snapshot_loader.py +72 -0
  21. hkos-1.0.0/context/token_estimator.py +76 -0
  22. hkos-1.0.0/core/__init__.py +0 -0
  23. hkos-1.0.0/core/bootstrap.py +94 -0
  24. hkos-1.0.0/core/config.py +150 -0
  25. hkos-1.0.0/core/constants.py +48 -0
  26. hkos-1.0.0/core/engine.py +72 -0
  27. hkos-1.0.0/core/exceptions.py +42 -0
  28. hkos-1.0.0/core/health.py +71 -0
  29. hkos-1.0.0/core/hkos.py +75 -0
  30. hkos-1.0.0/core/logger.py +103 -0
  31. hkos-1.0.0/core/registry.py +79 -0
  32. hkos-1.0.0/core/state.py +88 -0
  33. hkos-1.0.0/core/types.py +72 -0
  34. hkos-1.0.0/core/version.py +67 -0
  35. hkos-1.0.0/hkos.egg-info/PKG-INFO +307 -0
  36. hkos-1.0.0/hkos.egg-info/SOURCES.txt +321 -0
  37. hkos-1.0.0/hkos.egg-info/dependency_links.txt +1 -0
  38. hkos-1.0.0/hkos.egg-info/entry_points.txt +2 -0
  39. hkos-1.0.0/hkos.egg-info/requires.txt +9 -0
  40. hkos-1.0.0/hkos.egg-info/top_level.txt +1 -0
  41. hkos-1.0.0/index/__init__.py +77 -0
  42. hkos-1.0.0/index/entity_index.py +78 -0
  43. hkos-1.0.0/index/exceptions.py +29 -0
  44. hkos-1.0.0/index/index_builder.py +159 -0
  45. hkos-1.0.0/index/index_cache.py +85 -0
  46. hkos-1.0.0/index/index_engine.py +158 -0
  47. hkos-1.0.0/index/index_manager.py +178 -0
  48. hkos-1.0.0/index/index_store.py +116 -0
  49. hkos-1.0.0/index/index_updater.py +174 -0
  50. hkos-1.0.0/index/index_validator.py +184 -0
  51. hkos-1.0.0/index/keyword_index.py +114 -0
  52. hkos-1.0.0/index/query_contract.py +288 -0
  53. hkos-1.0.0/index/relationship_index.py +171 -0
  54. hkos-1.0.0/index/statistics_index.py +65 -0
  55. hkos-1.0.0/index/tag_index.py +94 -0
  56. hkos-1.0.0/index/validation.py +46 -0
  57. hkos-1.0.0/integration/__init__.py +5 -0
  58. hkos-1.0.0/integration/hermes/__init__.py +30 -0
  59. hkos-1.0.0/integration/hermes/agent_lock.py +97 -0
  60. hkos-1.0.0/integration/hermes/audit.py +90 -0
  61. hkos-1.0.0/integration/hermes/doctor.py +196 -0
  62. hkos-1.0.0/integration/hermes/fallback.py +71 -0
  63. hkos-1.0.0/integration/hermes/hooks.py +173 -0
  64. hkos-1.0.0/integration/hermes/migration_commands.py +79 -0
  65. hkos-1.0.0/integration/hermes/migration_tools.py +298 -0
  66. hkos-1.0.0/integration/hermes/schemas.py +110 -0
  67. hkos-1.0.0/integration/hermes/security.py +174 -0
  68. hkos-1.0.0/kernel/__init__.py +9 -0
  69. hkos-1.0.0/kernel/snapshot_document.py +93 -0
  70. hkos-1.0.0/knowledge/__init__.py +0 -0
  71. hkos-1.0.0/librarian/__init__.py +0 -0
  72. hkos-1.0.0/mcp_server/__init__.py +9 -0
  73. hkos-1.0.0/mcp_server/context.py +82 -0
  74. hkos-1.0.0/mcp_server/jsonrpc.py +32 -0
  75. hkos-1.0.0/mcp_server/persistence.py +74 -0
  76. hkos-1.0.0/mcp_server/server.py +175 -0
  77. hkos-1.0.0/mcp_server/tools.py +288 -0
  78. hkos-1.0.0/migration/__init__.py +46 -0
  79. hkos-1.0.0/migration/backup_manager.py +115 -0
  80. hkos-1.0.0/migration/exceptions.py +42 -0
  81. hkos-1.0.0/migration/migration_engine.py +322 -0
  82. hkos-1.0.0/migration/migration_executor.py +74 -0
  83. hkos-1.0.0/migration/migration_history.py +68 -0
  84. hkos-1.0.0/migration/migration_manager.py +196 -0
  85. hkos-1.0.0/migration/migration_registry.py +165 -0
  86. hkos-1.0.0/migration/migration_validator.py +294 -0
  87. hkos-1.0.0/migration/rollback_manager.py +121 -0
  88. hkos-1.0.0/migration/schema_detector.py +146 -0
  89. hkos-1.0.0/migration/version_manifest.py +125 -0
  90. hkos-1.0.0/performance/__init__.py +70 -0
  91. hkos-1.0.0/performance/cache_manager.py +94 -0
  92. hkos-1.0.0/performance/context_profiles.py +147 -0
  93. hkos-1.0.0/performance/exceptions.py +13 -0
  94. hkos-1.0.0/performance/integration.py +213 -0
  95. hkos-1.0.0/performance/latency_tracker.py +59 -0
  96. hkos-1.0.0/performance/metrics_engine.py +95 -0
  97. hkos-1.0.0/performance/performance_manager.py +233 -0
  98. hkos-1.0.0/performance/profiler.py +57 -0
  99. hkos-1.0.0/performance/resource_monitor.py +110 -0
  100. hkos-1.0.0/project/__init__.py +0 -0
  101. hkos-1.0.0/pyproject.toml +110 -0
  102. hkos-1.0.0/repository/__init__.py +64 -0
  103. hkos-1.0.0/repository/artifact_repository.py +66 -0
  104. hkos-1.0.0/repository/base_repository.py +229 -0
  105. hkos-1.0.0/repository/campaign_repository.py +153 -0
  106. hkos-1.0.0/repository/decision_repository.py +95 -0
  107. hkos-1.0.0/repository/exceptions.py +31 -0
  108. hkos-1.0.0/repository/knowledge_relations.py +136 -0
  109. hkos-1.0.0/repository/knowledge_repository.py +133 -0
  110. hkos-1.0.0/repository/models.py +295 -0
  111. hkos-1.0.0/repository/project_repository.py +103 -0
  112. hkos-1.0.0/repository/repository_manager.py +71 -0
  113. hkos-1.0.0/retrieval/__init__.py +44 -0
  114. hkos-1.0.0/retrieval/candidate_builder.py +152 -0
  115. hkos-1.0.0/retrieval/exceptions.py +21 -0
  116. hkos-1.0.0/retrieval/knowledge_filter.py +50 -0
  117. hkos-1.0.0/retrieval/knowledge_selector.py +34 -0
  118. hkos-1.0.0/retrieval/query_parser.py +203 -0
  119. hkos-1.0.0/retrieval/ranking_engine.py +324 -0
  120. hkos-1.0.0/retrieval/relationship_traverser.py +124 -0
  121. hkos-1.0.0/retrieval/retrieval_engine.py +474 -0
  122. hkos-1.0.0/retrieval/retriever.py +140 -0
  123. hkos-1.0.0/services/__init__.py +103 -0
  124. hkos-1.0.0/services/campaign_factory.py +90 -0
  125. hkos-1.0.0/services/campaign_manager.py +370 -0
  126. hkos-1.0.0/services/campaign_service.py +90 -0
  127. hkos-1.0.0/services/campaign_state.py +141 -0
  128. hkos-1.0.0/services/campaign_statistics.py +142 -0
  129. hkos-1.0.0/services/campaign_validator.py +101 -0
  130. hkos-1.0.0/services/classification_policy.py +144 -0
  131. hkos-1.0.0/services/exceptions.py +53 -0
  132. hkos-1.0.0/services/librarian/__init__.py +60 -0
  133. hkos-1.0.0/services/librarian/canonicalizer.py +73 -0
  134. hkos-1.0.0/services/librarian/category_merge.py +32 -0
  135. hkos-1.0.0/services/librarian/confidence_engine.py +125 -0
  136. hkos-1.0.0/services/librarian/conflict_detector.py +109 -0
  137. hkos-1.0.0/services/librarian/exceptions.py +29 -0
  138. hkos-1.0.0/services/librarian/knowledge_classifier.py +99 -0
  139. hkos-1.0.0/services/librarian/knowledge_history.py +145 -0
  140. hkos-1.0.0/services/librarian/knowledge_merger.py +100 -0
  141. hkos-1.0.0/services/librarian/knowledge_status.py +169 -0
  142. hkos-1.0.0/services/librarian/librarian.py +338 -0
  143. hkos-1.0.0/services/memory_service.py +304 -0
  144. hkos-1.0.0/services/project_factory.py +68 -0
  145. hkos-1.0.0/services/project_manager.py +267 -0
  146. hkos-1.0.0/services/project_service.py +85 -0
  147. hkos-1.0.0/services/project_state.py +117 -0
  148. hkos-1.0.0/services/project_validator.py +139 -0
  149. hkos-1.0.0/setup.cfg +4 -0
  150. hkos-1.0.0/snapshot/__init__.py +39 -0
  151. hkos-1.0.0/snapshot/exceptions.py +25 -0
  152. hkos-1.0.0/snapshot/snapshot_builder.py +199 -0
  153. hkos-1.0.0/snapshot/snapshot_diff.py +122 -0
  154. hkos-1.0.0/snapshot/snapshot_engine.py +165 -0
  155. hkos-1.0.0/snapshot/snapshot_history.py +76 -0
  156. hkos-1.0.0/snapshot/snapshot_loader.py +114 -0
  157. hkos-1.0.0/snapshot/snapshot_manager.py +211 -0
  158. hkos-1.0.0/snapshot/snapshot_serializer.py +49 -0
  159. hkos-1.0.0/snapshot/snapshot_validator.py +119 -0
  160. hkos-1.0.0/storage/__init__.py +41 -0
  161. hkos-1.0.0/storage/atomic_writer.py +104 -0
  162. hkos-1.0.0/storage/exceptions.py +46 -0
  163. hkos-1.0.0/storage/file_store.py +116 -0
  164. hkos-1.0.0/storage/json_store.py +240 -0
  165. hkos-1.0.0/storage/path_manager.py +199 -0
  166. hkos-1.0.0/storage/storage_engine.py +187 -0
  167. hkos-1.0.0/utils/__init__.py +0 -0
hkos-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dmitry Naumov
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.
hkos-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,307 @@
1
+ Metadata-Version: 2.4
2
+ Name: hkos
3
+ Version: 1.0.0
4
+ Summary: Deterministic, file-based engineering knowledge base for LLM agents (SSOT, retrieval, snapshots, migrations)
5
+ Author-email: Dmitry Naumov <hkos_dmitry@proton.me>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/dm-naumov/hkos
8
+ Project-URL: Documentation, https://github.com/dm-naumov/hkos#readme
9
+ Project-URL: Source, https://github.com/dm-naumov/hkos
10
+ Keywords: knowledge-base,llm-agents,agent-memory,retrieval,engineering-knowledge,deterministic,ssot,python
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Database
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.12
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pyyaml>=6.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=7.0; extra == "dev"
26
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
27
+ Requires-Dist: pytest-rerunfailures>=14.0; extra == "dev"
28
+ Requires-Dist: mypy>=1.0; extra == "dev"
29
+ Requires-Dist: ruff>=0.1; extra == "dev"
30
+ Requires-Dist: mcp>=1.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # HKOS — Hermes Knowledge OS
34
+
35
+ [![CI](https://github.com/dm-naumov/hkos/actions/workflows/ci.yml/badge.svg)](https://github.com/dm-naumov/hkos/actions/workflows/ci.yml)
36
+ [![Python](https://img.shields.io/badge/python-3.12%2B-blue.svg)]()
37
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
38
+ [![Tests](https://img.shields.io/badge/tests-990%2B-brightgreen.svg)]()
39
+ [![mypy](https://img.shields.io/badge/mypy-strict-2ea44f.svg)]()
40
+ [![ruff](https://img.shields.io/badge/ruff-0%20functional%20findings-2ea44f.svg)]()
41
+
42
+ **A deterministic, file-based engineering knowledge base for LLM agents.**
43
+
44
+ HKOS is a long-lived, object-oriented knowledge database designed to store and
45
+ structure engineering memory **independently of any LLM**. Knowledge is written
46
+ through a single canonical path, indexed locally, retrieved with a bounded
47
+ query contract, and snapshotted — all in plain JSON files, with no daemon, no
48
+ external services, and no embeddings.
49
+
50
+ > **Deterministic by design.** The classification, indexing, retrieval and
51
+ > lifecycle logic contains zero LLM calls. Your memory survives model swaps,
52
+ > prompt changes and vendor lock-in — the knowledge base is the source of
53
+ > truth, not the model.
54
+
55
+ ---
56
+
57
+ ## Why HKOS exists
58
+
59
+ LLM agent memory solutions today are typically **LLM-dependent**: embeddings,
60
+ model-generated "memories", and vector stores that only mean something to the
61
+ model that produced them. That design has a hard ceiling:
62
+
63
+ - memory quality silently changes when you swap the model;
64
+ - vector recall is probabilistic — the same query can return different results;
65
+ - there is no auditable, human-readable source of truth;
66
+ - failure modes are opaque and hard to debug.
67
+
68
+ HKOS takes the opposite position: **memory is engineering data**. It is
69
+ written deliberately, validated, versioned, and stored as plain JSON under a
70
+ single source of truth (SSOT). Retrieval is deterministic, explainable, and
71
+ fast enough for interactive agent use. This is what a production engineering
72
+ organization needs — not a black box.
73
+
74
+ ## Architecture
75
+
76
+ ```
77
+ ┌───────────────────────────────────────────┐
78
+ │ integration/ Hermes Agent adapters │
79
+ │ migration/ schema migration FSM, │
80
+ │ backup / rollback │
81
+ └──────────────────────┬────────────────────┘
82
+
83
+ ┌───────────────────────────────────────────┐
84
+ │ services/ Project · Campaign (FSM) · │
85
+ │ Librarian · MemoryService │
86
+ └──────────────────────┬────────────────────┘
87
+ ┌────────────────────────────────┼────────────────────────────────┐
88
+ ▼ ▼ ▼
89
+ retrieval/ context/ snapshot/
90
+ deterministic ranking context builder derived state,
91
+ with explanations (profiles, budgets) versioned & diffed
92
+ └────────────────────────────────┼────────────────────────────────┘
93
+
94
+ ┌───────────────────────────────────────────┐
95
+ │ index/ 5 indexes, Query Contract Q1–Q5, │
96
+ │ IndexCache (warm ≈ O(1)) │
97
+ └──────────────────────┬────────────────────┘
98
+
99
+ ┌───────────────────────────────────────────┐
100
+ │ repository/ JSON Repository — the ONLY │
101
+ │ source of truth (SSOT) │
102
+ └──────────────────────┬────────────────────┘
103
+
104
+ ┌───────────────────────────────────────────┐
105
+ │ storage/ StorageEngine, JSONStore, │
106
+ │ HKOS-08 envelopes │
107
+ └──────────────────────┬────────────────────┘
108
+
109
+ ┌───────────────────────────────────────────┐
110
+ │ core/ · kernel/ · performance/ │
111
+ │ engine, config, logging · shared types · │
112
+ │ metrics & profiling (zero business logic) │
113
+ └───────────────────────────────────────────┘
114
+ ```
115
+
116
+ Dependencies flow strictly downward. `services/` orchestrates; `migration/` is
117
+ a maintenance layer on top; `performance/` measures but never mutates.
118
+
119
+ ## Design invariants
120
+
121
+ 1. **Repository is the single source of truth.** Indexes, snapshots,
122
+ manifests and caches are *derived projections* — always rebuildable from
123
+ the repository, never authoritative.
124
+ 2. **The Librarian is the only write path for knowledge.** `register` →
125
+ `validate` → `canonicalize` — no other component may create or mutate
126
+ knowledge.
127
+ 3. **Deterministic classification.** Categories (FACT, DECISION, FAILURE,
128
+ CONFIGURATION, RULE, …) are assigned by a rule-based classifier — no LLM
129
+ in the pipeline.
130
+ 4. **Crash-safe writes.** All storage writes are atomic (tmp + rename).
131
+ `kill -9` mid-write leaves either the old or the new record — never a
132
+ partial one. Recovery is rebuild, not repair.
133
+ 5. **Schema evolution is a first-class operation.** A migration FSM
134
+ (backup → apply → rebuild index → regenerate snapshot → validate) with an
135
+ append-only event log and idempotent rollback.
136
+ 6. **No daemon, no global state, no hidden databases.** HKOS is a library;
137
+ everything is files and injected dependencies (constructor DI).
138
+
139
+ ## Knowledge lifecycle
140
+
141
+ ```
142
+ register ──► NEW ──► VERIFIED ──► CANONICAL ──► ARCHIVED
143
+ │ │
144
+ └────────┴──► REJECTED / SUPERSEDED
145
+ ```
146
+
147
+ - **NEW** — just registered, not yet part of retrievable memory;
148
+ - **VERIFIED** — passed validation;
149
+ - **CANONICAL** — the only status visible to retrieval (reusable);
150
+ - **ARCHIVED / REJECTED / SUPERSEDED** — filtered out of retrieval;
151
+ negative knowledge (FAILURE with cause/fix) is kept and resurfaces first
152
+ when the same mistake is about to be repeated.
153
+
154
+ ## Quick start
155
+
156
+ ```bash
157
+ pip install hkos # Python 3.12+
158
+ # or, from a checkout: uv venv .venv && uv pip install -e .
159
+ ```
160
+
161
+ ```python
162
+ # examples/quickstart.py — full pipeline on a throwaway corpus
163
+ from hkos.core.config import ConfigLoader
164
+ from hkos.core.logger import HKOSLogger
165
+ from hkos.core.version import VersionManager
166
+ from hkos.storage import StorageEngine
167
+ from hkos.repository.repository_manager import RepositoryManager
168
+ from hkos.repository.models import Knowledge
169
+ from hkos.services.project_manager import ProjectManager
170
+ from hkos.services.campaign_manager import CampaignManager
171
+ from hkos.services.librarian import Librarian
172
+ from hkos.index import IndexEngine, IndexStore, IndexCache, IndexQueryExecutor
173
+ from hkos.retrieval import RetrievalEngine
174
+
175
+ cfg = ConfigLoader().load()
176
+ engine = StorageEngine(root="./hkos", config=cfg,
177
+ logger=HKOSLogger(), version=VersionManager())
178
+ engine.initialize()
179
+ repos = RepositoryManager(engine)
180
+
181
+ project = ProjectManager(repos, HKOSLogger()).create(
182
+ name="Demo", description="quickstart", tags=["demo"])
183
+ Librarian(repos, HKOSLogger()).register(project.id, Knowledge(
184
+ title="TCP redirect works via nftables",
185
+ body="meta l4proto tcp redirect to :12345", tags=["tcp", "nftables"]))
186
+
187
+ index = IndexEngine(repos, IndexStore(engine), HKOSLogger(), cache=IndexCache())
188
+ index.build(project.id)
189
+ retrieval = RetrievalEngine(repos, IndexQueryExecutor(IndexStore(engine), cache=IndexCache()),
190
+ cfg, HKOSLogger())
191
+ print(retrieval.retrieve("tcp redirect", project_id=project.id))
192
+ ```
193
+
194
+ Real output of `python examples/quickstart.py`:
195
+
196
+ ```
197
+ data root: /tmp/hkos-demo-x9wwf6se
198
+ project: 8c1bbd63-96ca-4c72-bd34-b70cae72bcc4
199
+ campaign: 9f00ff23-87d6-4ae5-a501-91406d50e72b
200
+ knowledge registered & canonicalized: 3
201
+ retrieval: 1 item(s) for 'udp proxy'
202
+ [FAILURE] UDP traffic bypasses the proxy
203
+ snapshot: snapshot-00001 knowledge=3
204
+ OK
205
+ ```
206
+
207
+ Note how the **negative knowledge** (the FAILURE entry) is what the retriever
208
+ returns for a query about a problem — that is HKOS's core value: past mistakes
209
+ are reused before they are repeated.
210
+
211
+ ## Performance
212
+
213
+ Measured on a stock Linux workstation, corpus generated deterministically
214
+ (no LLM involvement). Full methodology and reproduction scripts in
215
+ [`release/BENCHMARKS.md`](release/BENCHMARKS.md).
216
+
217
+ | Operation | Budget (SLA) | Measured |
218
+ |---|---|---|
219
+ | Retrieval, cold (10K knowledge) | < 100 ms | PASS |
220
+ | Retrieval, warm (IndexCache) | — | ~0.03 ms (2120× faster than cold) |
221
+ | Context build (10K) | < 200 ms | PASS |
222
+ | Save (register → canonicalize) | < 150 ms | PASS |
223
+ | Snapshot load / create / diff | < 50 / < 300 / < 500 ms | PASS |
224
+ | Migration detect @100K | < 100 ms | < 25 ms (VersionManifest; was 1470 ms) |
225
+ | Migration backup / rollback / validate | < 5 / < 10 / < 10 s | 2.8 / 3.2 / 7.2 s |
226
+ | Index build 30K | linear | 1.5 s (was 84.6 s — O(N²) removed) |
227
+ | 100K knowledge, full corpus | — | generate 19.4 s · RAM 85 MB · retrieval < 100 ms |
228
+ | 1M stress | — | mechanism validated (200K in-session); full run via `HKOS_STRESS_SCALE=1000000` |
229
+ | Crash safety | — | `kill -9` mid-write: zero partial records (atomic tmp+rename) |
230
+
231
+ ## Quality
232
+
233
+ - **990+ tests** — 807 unit, 112 integration, 51+ system-level scenarios
234
+ (pipeline, lifecycle, 10K growth, consistency, failure recovery, concurrent
235
+ agents, migration, security, 100K stress, long-running, operational).
236
+ - **mypy --strict: 0 errors** across 272 files.
237
+ - **ruff: 0 functional findings** (docstring style only).
238
+ - **compileall: clean.**
239
+ - All layers tested at unit + integration level; system tests exercise only
240
+ public APIs (SSOT discipline is itself enforced by tests).
241
+
242
+ ## How is this different?
243
+
244
+ | | HKOS | Mem0 / basic-memory | Vector-store agent memory |
245
+ |---|---|---|---|
246
+ | Memory source of truth | JSON repository (files) | internal store, LLM-extracted | embeddings (model-dependent) |
247
+ | Determinism | yes — same query, same result | no — model-dependent | no — approximate |
248
+ | LLM needed to *read* memory | no | no | yes (embedding model) |
249
+ | LLM needed to *write* memory | no (rule-based classifier) | yes (extraction prompt) | yes |
250
+ | Auditable / diffable | yes (plain JSON, snapshots, diff) | limited | no |
251
+ | Schema migration | first-class FSM + rollback | — | — |
252
+ | Crash-safe | atomic writes, `kill -9`-proof | — | — |
253
+ | Explains why an item was retrieved | yes (reason/score per item) | no | no |
254
+
255
+ **In one sentence:** most agent-memory tools make memory *another model's
256
+ output*; HKOS makes memory *your engineering data* — deterministic, versioned,
257
+ auditable, and portable across LLMs.
258
+
259
+ ## MCP
260
+
261
+ HKOS ships an MCP server (`hkos-mcp`, stdio, zero dependencies): any MCP
262
+ client — Claude Desktop, IDEs, agent frameworks — can `retrieve`, `context`,
263
+ `save`, `snapshot`, `doctor` and `status` against an HKOS knowledge base.
264
+
265
+ ```bash
266
+ pip install hkos
267
+ hkos-mcp --root ./hkos # data root (HKOS_DATA_ROOT / HKOS_PROFILE env)
268
+ ```
269
+
270
+ ```json
271
+ // claude_desktop_config.json
272
+ { "mcpServers": { "hkos": { "command": "hkos-mcp",
273
+ "args": ["--root", "/abs/path/data-root"] } } }
274
+ ```
275
+
276
+ See [docs/mcp.md](docs/mcp.md) for the tool reference and client setup.
277
+
278
+ ## Documentation
279
+
280
+ - [Installation](docs/installation.md)
281
+ - [Architecture](docs/architecture.md)
282
+ - [API reference](docs/api-reference.md)
283
+ - [Developer guide](docs/developer.md)
284
+ - [Performance guide](docs/performance-guide.md)
285
+ - [Migration guide](docs/migration-guide.md)
286
+ - [Troubleshooting](docs/troubleshooting.md)
287
+ - [Administrator guide](docs/administrator.md)
288
+
289
+ ## Roadmap
290
+
291
+ - **v1.0** — current: core, storage, repository, index, retrieval, context,
292
+ snapshot, services, migration, integration, performance layers.
293
+ - **v1.1** — MCP adapter (stdio server for any MCP client), semantic search as
294
+ an *optional* backend (SSOT untouched), CLI package.
295
+ - **v1.2** — SQLite storage backend (same API, envelope format preserved),
296
+ cross-project knowledge graphs.
297
+
298
+ ## License
299
+
300
+ MIT — see [LICENSE](LICENSE).
301
+
302
+ ---
303
+
304
+ *HKOS was developed in 15 certified sprints (DS-001…DS-015) with a documented
305
+ engineering process: architecture reviews, adversarial audits, performance
306
+ budgets, and system-level qualification. Design decisions are documented in
307
+ [`docs/design/`](docs/design/).*
hkos-1.0.0/README.md ADDED
@@ -0,0 +1,275 @@
1
+ # HKOS — Hermes Knowledge OS
2
+
3
+ [![CI](https://github.com/dm-naumov/hkos/actions/workflows/ci.yml/badge.svg)](https://github.com/dm-naumov/hkos/actions/workflows/ci.yml)
4
+ [![Python](https://img.shields.io/badge/python-3.12%2B-blue.svg)]()
5
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6
+ [![Tests](https://img.shields.io/badge/tests-990%2B-brightgreen.svg)]()
7
+ [![mypy](https://img.shields.io/badge/mypy-strict-2ea44f.svg)]()
8
+ [![ruff](https://img.shields.io/badge/ruff-0%20functional%20findings-2ea44f.svg)]()
9
+
10
+ **A deterministic, file-based engineering knowledge base for LLM agents.**
11
+
12
+ HKOS is a long-lived, object-oriented knowledge database designed to store and
13
+ structure engineering memory **independently of any LLM**. Knowledge is written
14
+ through a single canonical path, indexed locally, retrieved with a bounded
15
+ query contract, and snapshotted — all in plain JSON files, with no daemon, no
16
+ external services, and no embeddings.
17
+
18
+ > **Deterministic by design.** The classification, indexing, retrieval and
19
+ > lifecycle logic contains zero LLM calls. Your memory survives model swaps,
20
+ > prompt changes and vendor lock-in — the knowledge base is the source of
21
+ > truth, not the model.
22
+
23
+ ---
24
+
25
+ ## Why HKOS exists
26
+
27
+ LLM agent memory solutions today are typically **LLM-dependent**: embeddings,
28
+ model-generated "memories", and vector stores that only mean something to the
29
+ model that produced them. That design has a hard ceiling:
30
+
31
+ - memory quality silently changes when you swap the model;
32
+ - vector recall is probabilistic — the same query can return different results;
33
+ - there is no auditable, human-readable source of truth;
34
+ - failure modes are opaque and hard to debug.
35
+
36
+ HKOS takes the opposite position: **memory is engineering data**. It is
37
+ written deliberately, validated, versioned, and stored as plain JSON under a
38
+ single source of truth (SSOT). Retrieval is deterministic, explainable, and
39
+ fast enough for interactive agent use. This is what a production engineering
40
+ organization needs — not a black box.
41
+
42
+ ## Architecture
43
+
44
+ ```
45
+ ┌───────────────────────────────────────────┐
46
+ │ integration/ Hermes Agent adapters │
47
+ │ migration/ schema migration FSM, │
48
+ │ backup / rollback │
49
+ └──────────────────────┬────────────────────┘
50
+
51
+ ┌───────────────────────────────────────────┐
52
+ │ services/ Project · Campaign (FSM) · │
53
+ │ Librarian · MemoryService │
54
+ └──────────────────────┬────────────────────┘
55
+ ┌────────────────────────────────┼────────────────────────────────┐
56
+ ▼ ▼ ▼
57
+ retrieval/ context/ snapshot/
58
+ deterministic ranking context builder derived state,
59
+ with explanations (profiles, budgets) versioned & diffed
60
+ └────────────────────────────────┼────────────────────────────────┘
61
+
62
+ ┌───────────────────────────────────────────┐
63
+ │ index/ 5 indexes, Query Contract Q1–Q5, │
64
+ │ IndexCache (warm ≈ O(1)) │
65
+ └──────────────────────┬────────────────────┘
66
+
67
+ ┌───────────────────────────────────────────┐
68
+ │ repository/ JSON Repository — the ONLY │
69
+ │ source of truth (SSOT) │
70
+ └──────────────────────┬────────────────────┘
71
+
72
+ ┌───────────────────────────────────────────┐
73
+ │ storage/ StorageEngine, JSONStore, │
74
+ │ HKOS-08 envelopes │
75
+ └──────────────────────┬────────────────────┘
76
+
77
+ ┌───────────────────────────────────────────┐
78
+ │ core/ · kernel/ · performance/ │
79
+ │ engine, config, logging · shared types · │
80
+ │ metrics & profiling (zero business logic) │
81
+ └───────────────────────────────────────────┘
82
+ ```
83
+
84
+ Dependencies flow strictly downward. `services/` orchestrates; `migration/` is
85
+ a maintenance layer on top; `performance/` measures but never mutates.
86
+
87
+ ## Design invariants
88
+
89
+ 1. **Repository is the single source of truth.** Indexes, snapshots,
90
+ manifests and caches are *derived projections* — always rebuildable from
91
+ the repository, never authoritative.
92
+ 2. **The Librarian is the only write path for knowledge.** `register` →
93
+ `validate` → `canonicalize` — no other component may create or mutate
94
+ knowledge.
95
+ 3. **Deterministic classification.** Categories (FACT, DECISION, FAILURE,
96
+ CONFIGURATION, RULE, …) are assigned by a rule-based classifier — no LLM
97
+ in the pipeline.
98
+ 4. **Crash-safe writes.** All storage writes are atomic (tmp + rename).
99
+ `kill -9` mid-write leaves either the old or the new record — never a
100
+ partial one. Recovery is rebuild, not repair.
101
+ 5. **Schema evolution is a first-class operation.** A migration FSM
102
+ (backup → apply → rebuild index → regenerate snapshot → validate) with an
103
+ append-only event log and idempotent rollback.
104
+ 6. **No daemon, no global state, no hidden databases.** HKOS is a library;
105
+ everything is files and injected dependencies (constructor DI).
106
+
107
+ ## Knowledge lifecycle
108
+
109
+ ```
110
+ register ──► NEW ──► VERIFIED ──► CANONICAL ──► ARCHIVED
111
+ │ │
112
+ └────────┴──► REJECTED / SUPERSEDED
113
+ ```
114
+
115
+ - **NEW** — just registered, not yet part of retrievable memory;
116
+ - **VERIFIED** — passed validation;
117
+ - **CANONICAL** — the only status visible to retrieval (reusable);
118
+ - **ARCHIVED / REJECTED / SUPERSEDED** — filtered out of retrieval;
119
+ negative knowledge (FAILURE with cause/fix) is kept and resurfaces first
120
+ when the same mistake is about to be repeated.
121
+
122
+ ## Quick start
123
+
124
+ ```bash
125
+ pip install hkos # Python 3.12+
126
+ # or, from a checkout: uv venv .venv && uv pip install -e .
127
+ ```
128
+
129
+ ```python
130
+ # examples/quickstart.py — full pipeline on a throwaway corpus
131
+ from hkos.core.config import ConfigLoader
132
+ from hkos.core.logger import HKOSLogger
133
+ from hkos.core.version import VersionManager
134
+ from hkos.storage import StorageEngine
135
+ from hkos.repository.repository_manager import RepositoryManager
136
+ from hkos.repository.models import Knowledge
137
+ from hkos.services.project_manager import ProjectManager
138
+ from hkos.services.campaign_manager import CampaignManager
139
+ from hkos.services.librarian import Librarian
140
+ from hkos.index import IndexEngine, IndexStore, IndexCache, IndexQueryExecutor
141
+ from hkos.retrieval import RetrievalEngine
142
+
143
+ cfg = ConfigLoader().load()
144
+ engine = StorageEngine(root="./hkos", config=cfg,
145
+ logger=HKOSLogger(), version=VersionManager())
146
+ engine.initialize()
147
+ repos = RepositoryManager(engine)
148
+
149
+ project = ProjectManager(repos, HKOSLogger()).create(
150
+ name="Demo", description="quickstart", tags=["demo"])
151
+ Librarian(repos, HKOSLogger()).register(project.id, Knowledge(
152
+ title="TCP redirect works via nftables",
153
+ body="meta l4proto tcp redirect to :12345", tags=["tcp", "nftables"]))
154
+
155
+ index = IndexEngine(repos, IndexStore(engine), HKOSLogger(), cache=IndexCache())
156
+ index.build(project.id)
157
+ retrieval = RetrievalEngine(repos, IndexQueryExecutor(IndexStore(engine), cache=IndexCache()),
158
+ cfg, HKOSLogger())
159
+ print(retrieval.retrieve("tcp redirect", project_id=project.id))
160
+ ```
161
+
162
+ Real output of `python examples/quickstart.py`:
163
+
164
+ ```
165
+ data root: /tmp/hkos-demo-x9wwf6se
166
+ project: 8c1bbd63-96ca-4c72-bd34-b70cae72bcc4
167
+ campaign: 9f00ff23-87d6-4ae5-a501-91406d50e72b
168
+ knowledge registered & canonicalized: 3
169
+ retrieval: 1 item(s) for 'udp proxy'
170
+ [FAILURE] UDP traffic bypasses the proxy
171
+ snapshot: snapshot-00001 knowledge=3
172
+ OK
173
+ ```
174
+
175
+ Note how the **negative knowledge** (the FAILURE entry) is what the retriever
176
+ returns for a query about a problem — that is HKOS's core value: past mistakes
177
+ are reused before they are repeated.
178
+
179
+ ## Performance
180
+
181
+ Measured on a stock Linux workstation, corpus generated deterministically
182
+ (no LLM involvement). Full methodology and reproduction scripts in
183
+ [`release/BENCHMARKS.md`](release/BENCHMARKS.md).
184
+
185
+ | Operation | Budget (SLA) | Measured |
186
+ |---|---|---|
187
+ | Retrieval, cold (10K knowledge) | < 100 ms | PASS |
188
+ | Retrieval, warm (IndexCache) | — | ~0.03 ms (2120× faster than cold) |
189
+ | Context build (10K) | < 200 ms | PASS |
190
+ | Save (register → canonicalize) | < 150 ms | PASS |
191
+ | Snapshot load / create / diff | < 50 / < 300 / < 500 ms | PASS |
192
+ | Migration detect @100K | < 100 ms | < 25 ms (VersionManifest; was 1470 ms) |
193
+ | Migration backup / rollback / validate | < 5 / < 10 / < 10 s | 2.8 / 3.2 / 7.2 s |
194
+ | Index build 30K | linear | 1.5 s (was 84.6 s — O(N²) removed) |
195
+ | 100K knowledge, full corpus | — | generate 19.4 s · RAM 85 MB · retrieval < 100 ms |
196
+ | 1M stress | — | mechanism validated (200K in-session); full run via `HKOS_STRESS_SCALE=1000000` |
197
+ | Crash safety | — | `kill -9` mid-write: zero partial records (atomic tmp+rename) |
198
+
199
+ ## Quality
200
+
201
+ - **990+ tests** — 807 unit, 112 integration, 51+ system-level scenarios
202
+ (pipeline, lifecycle, 10K growth, consistency, failure recovery, concurrent
203
+ agents, migration, security, 100K stress, long-running, operational).
204
+ - **mypy --strict: 0 errors** across 272 files.
205
+ - **ruff: 0 functional findings** (docstring style only).
206
+ - **compileall: clean.**
207
+ - All layers tested at unit + integration level; system tests exercise only
208
+ public APIs (SSOT discipline is itself enforced by tests).
209
+
210
+ ## How is this different?
211
+
212
+ | | HKOS | Mem0 / basic-memory | Vector-store agent memory |
213
+ |---|---|---|---|
214
+ | Memory source of truth | JSON repository (files) | internal store, LLM-extracted | embeddings (model-dependent) |
215
+ | Determinism | yes — same query, same result | no — model-dependent | no — approximate |
216
+ | LLM needed to *read* memory | no | no | yes (embedding model) |
217
+ | LLM needed to *write* memory | no (rule-based classifier) | yes (extraction prompt) | yes |
218
+ | Auditable / diffable | yes (plain JSON, snapshots, diff) | limited | no |
219
+ | Schema migration | first-class FSM + rollback | — | — |
220
+ | Crash-safe | atomic writes, `kill -9`-proof | — | — |
221
+ | Explains why an item was retrieved | yes (reason/score per item) | no | no |
222
+
223
+ **In one sentence:** most agent-memory tools make memory *another model's
224
+ output*; HKOS makes memory *your engineering data* — deterministic, versioned,
225
+ auditable, and portable across LLMs.
226
+
227
+ ## MCP
228
+
229
+ HKOS ships an MCP server (`hkos-mcp`, stdio, zero dependencies): any MCP
230
+ client — Claude Desktop, IDEs, agent frameworks — can `retrieve`, `context`,
231
+ `save`, `snapshot`, `doctor` and `status` against an HKOS knowledge base.
232
+
233
+ ```bash
234
+ pip install hkos
235
+ hkos-mcp --root ./hkos # data root (HKOS_DATA_ROOT / HKOS_PROFILE env)
236
+ ```
237
+
238
+ ```json
239
+ // claude_desktop_config.json
240
+ { "mcpServers": { "hkos": { "command": "hkos-mcp",
241
+ "args": ["--root", "/abs/path/data-root"] } } }
242
+ ```
243
+
244
+ See [docs/mcp.md](docs/mcp.md) for the tool reference and client setup.
245
+
246
+ ## Documentation
247
+
248
+ - [Installation](docs/installation.md)
249
+ - [Architecture](docs/architecture.md)
250
+ - [API reference](docs/api-reference.md)
251
+ - [Developer guide](docs/developer.md)
252
+ - [Performance guide](docs/performance-guide.md)
253
+ - [Migration guide](docs/migration-guide.md)
254
+ - [Troubleshooting](docs/troubleshooting.md)
255
+ - [Administrator guide](docs/administrator.md)
256
+
257
+ ## Roadmap
258
+
259
+ - **v1.0** — current: core, storage, repository, index, retrieval, context,
260
+ snapshot, services, migration, integration, performance layers.
261
+ - **v1.1** — MCP adapter (stdio server for any MCP client), semantic search as
262
+ an *optional* backend (SSOT untouched), CLI package.
263
+ - **v1.2** — SQLite storage backend (same API, envelope format preserved),
264
+ cross-project knowledge graphs.
265
+
266
+ ## License
267
+
268
+ MIT — see [LICENSE](LICENSE).
269
+
270
+ ---
271
+
272
+ *HKOS was developed in 15 certified sprints (DS-001…DS-015) with a documented
273
+ engineering process: architecture reviews, adversarial audits, performance
274
+ budgets, and system-level qualification. Design decisions are documented in
275
+ [`docs/design/`](docs/design/).*
hkos-1.0.0/__init__.py ADDED
@@ -0,0 +1,37 @@
1
+ """Hermes Knowledge OS (HKOS)
2
+ ============================
3
+ An object-oriented file-based engineering knowledge database.
4
+
5
+ DS-001 (Sprint 1): Foundation
6
+ - HKOS as an importable module
7
+ - Bootstrap, Configuration, Logger, Registry
8
+ - Version and Health management
9
+ """
10
+
11
+ from hkos.core.config import ConfigLoader
12
+ from hkos.core.exceptions import (
13
+ ConfigurationError,
14
+ HKOSError,
15
+ InitializationError,
16
+ RuntimeErrorHKOS,
17
+ ValidationError,
18
+ )
19
+ from hkos.core.health import HealthManager
20
+ from hkos.core.hkos import HKOS
21
+ from hkos.core.logger import HKOSLogger
22
+ from hkos.core.registry import Registry
23
+ from hkos.core.version import VersionManager
24
+
25
+ __all__ = [
26
+ "HKOS",
27
+ "VersionManager",
28
+ "ConfigLoader",
29
+ "HealthManager",
30
+ "Registry",
31
+ "HKOSLogger",
32
+ "HKOSError",
33
+ "ConfigurationError",
34
+ "InitializationError",
35
+ "RuntimeErrorHKOS",
36
+ "ValidationError",
37
+ ]
File without changes
File without changes
File without changes