hermes-memory-metronix 0.1.2__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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025-2026 Metronix Core Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: hermes-memory-metronix
3
+ Version: 0.1.2
4
+ Summary: Standalone Hermes memory-provider plugin scaffold for Metronix
5
+ Author: Metronix Contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/mtrnix/hermes-memory-metronix
8
+ Project-URL: Issues, https://github.com/mtrnix/hermes-memory-metronix/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: requests<3,>=2.31
17
+ Requires-Dist: pyyaml<7,>=6
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest<10,>=9; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # hermes-memory-metronix
23
+
24
+ Standalone Hermes `MemoryProvider` backed by Metronix Memory.
25
+
26
+ This repository owns the Hermes-native adapter layer:
27
+
28
+ - Hermes plugin packaging
29
+ - config and auth resolution
30
+ - prefetch and write-through behavior
31
+ - Hermes-focused unit, integration, and smoke tests
32
+
33
+ Metronix backend contracts and MCP integration docs remain in the
34
+ `metronix-memory` repository.
35
+
36
+ ## Status
37
+
38
+ This is a scaffold, not a finished public plugin release.
39
+
40
+ What it already does:
41
+
42
+ - Implements the Hermes `MemoryProvider` contract
43
+ - Prefetches relevant Metronix memory records before a turn
44
+ - Mirrors Hermes `memory(action="add")` writes into Metronix
45
+ - Optionally writes completed turns as session-scoped Metronix memory
46
+ - Supports bearer-token auth, with email/password login fallback
47
+
48
+ What is intentionally still conservative:
49
+
50
+ - No custom Hermes setup wizard yet
51
+ - No extra provider-specific model tools yet
52
+ - Prefetch currently targets `/api/v1/memory/search`
53
+ - Knowledge-document / page retrieval is left as a follow-up
54
+
55
+ ## Layout
56
+
57
+ The installable Hermes plugin is this repository root. Its provider
58
+ implementation lives in:
59
+
60
+ - `plugin/metronix/`
61
+
62
+ Hermes discovers user-installed memory providers from:
63
+
64
+ - `~/.hermes/plugins/<name>/__init__.py`
65
+
66
+ ## Install for Hermes
67
+
68
+ Install the repository into your Hermes plugin directory:
69
+
70
+ ```bash
71
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
72
+ ```
73
+
74
+ Then set Hermes to use it:
75
+
76
+ ```yaml
77
+ memory:
78
+ provider: metronix
79
+ ```
80
+
81
+ ## Python distribution
82
+
83
+ `pip install hermes-memory-metronix` distributes the adapter for development
84
+ and Hermes-hosted environments. It does not register the provider with Hermes.
85
+ For Hermes discovery, install this GitHub plugin with:
86
+
87
+ ```bash
88
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
89
+ ```
90
+
91
+ ## Plugin config
92
+
93
+ The plugin reads non-secret config from:
94
+
95
+ - `$HERMES_HOME/metronix.json`
96
+
97
+ And secrets from:
98
+
99
+ - `$HERMES_HOME/.env`
100
+ - process environment
101
+
102
+ Example `metronix.json`:
103
+
104
+ ```json
105
+ {
106
+ "base_url": "http://localhost:8000",
107
+ "workspace_id": "MTRNIX",
108
+ "agent_id": "hermes",
109
+ "prefetch": true,
110
+ "prefetch_top_k": 8,
111
+ "prefetch_types": ["fact", "preference", "pinned"],
112
+ "cite_sources": true,
113
+ "write_through": true,
114
+ "write_scope": "workspace",
115
+ "sync_turns": true
116
+ }
117
+ ```
118
+
119
+ Secrets:
120
+
121
+ ```bash
122
+ METRONIX_AUTH_TOKEN=...
123
+ # or:
124
+ METRONIX_EMAIL=admin@metronix.local
125
+ METRONIX_PASSWORD=...
126
+ ```
127
+
128
+ Important:
129
+
130
+ - `METRONIX_AUTH_TOKEN` must be a REST JWT or personal API key for `/api/v1/*`
131
+ - `METRONIX_MCP_API_KEY` is for `/mcp`, not `/api/v1/memory/*`
132
+ - if you provide both a bearer token and login credentials, the client will
133
+ retry once with a fresh login JWT when the original bearer gets a `401`
134
+
135
+ ## Mapping notes
136
+
137
+ Hermes write scopes map to Metronix scopes like this:
138
+
139
+ - `per_agent` -> `per_agent`
140
+ - `workspace` -> `global`
141
+ - `shared` -> `global`
142
+ - `session` -> `session`
143
+
144
+ The current prefetch path uses Metronix memory search, so `prefetch_types`
145
+ maps to Metronix memory kinds:
146
+
147
+ - `fact`
148
+ - `preference`
149
+ - `pinned`
150
+
151
+ `page` is not wired yet because the current scaffold does not call a unified
152
+ knowledge-search endpoint.
153
+
154
+ ## Migrating an existing llm-wiki into Metronix
155
+
156
+ Hermes's bundled `llm-wiki` skill maintains a directory of markdown pages
157
+ (`entities/`, `concepts/`, `comparisons/`, `queries/`, `raw/`) at `$WIKI_PATH`
158
+ (default `~/wiki`). To bulk-ingest an existing wiki into Metronix's Knowledge
159
+ Base (chunked, embedded, searchable via `metronix_search_fast`/`metronix_get`):
160
+
161
+ ```bash
162
+ python scripts/migrate_wiki.py \
163
+ --wiki-path ~/wiki \
164
+ --base-url http://localhost:8000 \
165
+ --workspace-id MTRNIX \
166
+ --auth-token "$METRONIX_AUTH_TOKEN"
167
+ ```
168
+
169
+ Each page becomes a document with `source_type="hermes_llm_wiki"` and a
170
+ deterministic `doc_label` derived from its wiki-relative path, so re-running
171
+ the script updates existing documents instead of duplicating them. By
172
+ default, only `raw/`, `entities/`, `concepts/`, `comparisons/`, and
173
+ `queries/` are ingested; `SCHEMA.md`, `index.md`, `log*.md`, and
174
+ `_archive/**` are skipped (pass `--include-archive` to include archived
175
+ pages instead).
176
+
177
+ Requires `METRONIX_AUTH_TOKEN` to be a REST JWT or personal API key for
178
+ `/api/v1/*`, not `METRONIX_MCP_API_KEY`, which is for `/mcp` only.
179
+
180
+ ## Development
181
+
182
+ Run the fast local checks:
183
+
184
+ ```bash
185
+ uv run --extra dev pytest tests/unit -v
186
+ RUN_INTEGRATION_TESTS=1 uv run --extra dev pytest tests/integration/test_live_metronix.py -v
187
+ ```
188
+
189
+ ### Verify against Hermes
190
+
191
+ Clone a clean Hermes checkout separately, then verify both the current
192
+ `MemoryProvider` abstract base class and Hermes's real plugin loader:
193
+
194
+ ```bash
195
+ HERMES_AGENT_SRC=/absolute/path/to/hermes-agent \
196
+ uv run --extra dev pytest \
197
+ tests/unit/test_real_abc_contract.py tests/unit/test_hermes_plugin.py -v
198
+ ```
199
+
200
+ The compatibility tests skip with an explicit reason when `HERMES_AGENT_SRC`
201
+ does not point to a Hermes checkout. They should pass before publishing a
202
+ plugin release.
@@ -0,0 +1,181 @@
1
+ # hermes-memory-metronix
2
+
3
+ Standalone Hermes `MemoryProvider` backed by Metronix Memory.
4
+
5
+ This repository owns the Hermes-native adapter layer:
6
+
7
+ - Hermes plugin packaging
8
+ - config and auth resolution
9
+ - prefetch and write-through behavior
10
+ - Hermes-focused unit, integration, and smoke tests
11
+
12
+ Metronix backend contracts and MCP integration docs remain in the
13
+ `metronix-memory` repository.
14
+
15
+ ## Status
16
+
17
+ This is a scaffold, not a finished public plugin release.
18
+
19
+ What it already does:
20
+
21
+ - Implements the Hermes `MemoryProvider` contract
22
+ - Prefetches relevant Metronix memory records before a turn
23
+ - Mirrors Hermes `memory(action="add")` writes into Metronix
24
+ - Optionally writes completed turns as session-scoped Metronix memory
25
+ - Supports bearer-token auth, with email/password login fallback
26
+
27
+ What is intentionally still conservative:
28
+
29
+ - No custom Hermes setup wizard yet
30
+ - No extra provider-specific model tools yet
31
+ - Prefetch currently targets `/api/v1/memory/search`
32
+ - Knowledge-document / page retrieval is left as a follow-up
33
+
34
+ ## Layout
35
+
36
+ The installable Hermes plugin is this repository root. Its provider
37
+ implementation lives in:
38
+
39
+ - `plugin/metronix/`
40
+
41
+ Hermes discovers user-installed memory providers from:
42
+
43
+ - `~/.hermes/plugins/<name>/__init__.py`
44
+
45
+ ## Install for Hermes
46
+
47
+ Install the repository into your Hermes plugin directory:
48
+
49
+ ```bash
50
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
51
+ ```
52
+
53
+ Then set Hermes to use it:
54
+
55
+ ```yaml
56
+ memory:
57
+ provider: metronix
58
+ ```
59
+
60
+ ## Python distribution
61
+
62
+ `pip install hermes-memory-metronix` distributes the adapter for development
63
+ and Hermes-hosted environments. It does not register the provider with Hermes.
64
+ For Hermes discovery, install this GitHub plugin with:
65
+
66
+ ```bash
67
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
68
+ ```
69
+
70
+ ## Plugin config
71
+
72
+ The plugin reads non-secret config from:
73
+
74
+ - `$HERMES_HOME/metronix.json`
75
+
76
+ And secrets from:
77
+
78
+ - `$HERMES_HOME/.env`
79
+ - process environment
80
+
81
+ Example `metronix.json`:
82
+
83
+ ```json
84
+ {
85
+ "base_url": "http://localhost:8000",
86
+ "workspace_id": "MTRNIX",
87
+ "agent_id": "hermes",
88
+ "prefetch": true,
89
+ "prefetch_top_k": 8,
90
+ "prefetch_types": ["fact", "preference", "pinned"],
91
+ "cite_sources": true,
92
+ "write_through": true,
93
+ "write_scope": "workspace",
94
+ "sync_turns": true
95
+ }
96
+ ```
97
+
98
+ Secrets:
99
+
100
+ ```bash
101
+ METRONIX_AUTH_TOKEN=...
102
+ # or:
103
+ METRONIX_EMAIL=admin@metronix.local
104
+ METRONIX_PASSWORD=...
105
+ ```
106
+
107
+ Important:
108
+
109
+ - `METRONIX_AUTH_TOKEN` must be a REST JWT or personal API key for `/api/v1/*`
110
+ - `METRONIX_MCP_API_KEY` is for `/mcp`, not `/api/v1/memory/*`
111
+ - if you provide both a bearer token and login credentials, the client will
112
+ retry once with a fresh login JWT when the original bearer gets a `401`
113
+
114
+ ## Mapping notes
115
+
116
+ Hermes write scopes map to Metronix scopes like this:
117
+
118
+ - `per_agent` -> `per_agent`
119
+ - `workspace` -> `global`
120
+ - `shared` -> `global`
121
+ - `session` -> `session`
122
+
123
+ The current prefetch path uses Metronix memory search, so `prefetch_types`
124
+ maps to Metronix memory kinds:
125
+
126
+ - `fact`
127
+ - `preference`
128
+ - `pinned`
129
+
130
+ `page` is not wired yet because the current scaffold does not call a unified
131
+ knowledge-search endpoint.
132
+
133
+ ## Migrating an existing llm-wiki into Metronix
134
+
135
+ Hermes's bundled `llm-wiki` skill maintains a directory of markdown pages
136
+ (`entities/`, `concepts/`, `comparisons/`, `queries/`, `raw/`) at `$WIKI_PATH`
137
+ (default `~/wiki`). To bulk-ingest an existing wiki into Metronix's Knowledge
138
+ Base (chunked, embedded, searchable via `metronix_search_fast`/`metronix_get`):
139
+
140
+ ```bash
141
+ python scripts/migrate_wiki.py \
142
+ --wiki-path ~/wiki \
143
+ --base-url http://localhost:8000 \
144
+ --workspace-id MTRNIX \
145
+ --auth-token "$METRONIX_AUTH_TOKEN"
146
+ ```
147
+
148
+ Each page becomes a document with `source_type="hermes_llm_wiki"` and a
149
+ deterministic `doc_label` derived from its wiki-relative path, so re-running
150
+ the script updates existing documents instead of duplicating them. By
151
+ default, only `raw/`, `entities/`, `concepts/`, `comparisons/`, and
152
+ `queries/` are ingested; `SCHEMA.md`, `index.md`, `log*.md`, and
153
+ `_archive/**` are skipped (pass `--include-archive` to include archived
154
+ pages instead).
155
+
156
+ Requires `METRONIX_AUTH_TOKEN` to be a REST JWT or personal API key for
157
+ `/api/v1/*`, not `METRONIX_MCP_API_KEY`, which is for `/mcp` only.
158
+
159
+ ## Development
160
+
161
+ Run the fast local checks:
162
+
163
+ ```bash
164
+ uv run --extra dev pytest tests/unit -v
165
+ RUN_INTEGRATION_TESTS=1 uv run --extra dev pytest tests/integration/test_live_metronix.py -v
166
+ ```
167
+
168
+ ### Verify against Hermes
169
+
170
+ Clone a clean Hermes checkout separately, then verify both the current
171
+ `MemoryProvider` abstract base class and Hermes's real plugin loader:
172
+
173
+ ```bash
174
+ HERMES_AGENT_SRC=/absolute/path/to/hermes-agent \
175
+ uv run --extra dev pytest \
176
+ tests/unit/test_real_abc_contract.py tests/unit/test_hermes_plugin.py -v
177
+ ```
178
+
179
+ The compatibility tests skip with an explicit reason when `HERMES_AGENT_SRC`
180
+ does not point to a Hermes checkout. They should pass before publishing a
181
+ plugin release.
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.4
2
+ Name: hermes-memory-metronix
3
+ Version: 0.1.2
4
+ Summary: Standalone Hermes memory-provider plugin scaffold for Metronix
5
+ Author: Metronix Contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/mtrnix/hermes-memory-metronix
8
+ Project-URL: Issues, https://github.com/mtrnix/hermes-memory-metronix/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: requests<3,>=2.31
17
+ Requires-Dist: pyyaml<7,>=6
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest<10,>=9; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # hermes-memory-metronix
23
+
24
+ Standalone Hermes `MemoryProvider` backed by Metronix Memory.
25
+
26
+ This repository owns the Hermes-native adapter layer:
27
+
28
+ - Hermes plugin packaging
29
+ - config and auth resolution
30
+ - prefetch and write-through behavior
31
+ - Hermes-focused unit, integration, and smoke tests
32
+
33
+ Metronix backend contracts and MCP integration docs remain in the
34
+ `metronix-memory` repository.
35
+
36
+ ## Status
37
+
38
+ This is a scaffold, not a finished public plugin release.
39
+
40
+ What it already does:
41
+
42
+ - Implements the Hermes `MemoryProvider` contract
43
+ - Prefetches relevant Metronix memory records before a turn
44
+ - Mirrors Hermes `memory(action="add")` writes into Metronix
45
+ - Optionally writes completed turns as session-scoped Metronix memory
46
+ - Supports bearer-token auth, with email/password login fallback
47
+
48
+ What is intentionally still conservative:
49
+
50
+ - No custom Hermes setup wizard yet
51
+ - No extra provider-specific model tools yet
52
+ - Prefetch currently targets `/api/v1/memory/search`
53
+ - Knowledge-document / page retrieval is left as a follow-up
54
+
55
+ ## Layout
56
+
57
+ The installable Hermes plugin is this repository root. Its provider
58
+ implementation lives in:
59
+
60
+ - `plugin/metronix/`
61
+
62
+ Hermes discovers user-installed memory providers from:
63
+
64
+ - `~/.hermes/plugins/<name>/__init__.py`
65
+
66
+ ## Install for Hermes
67
+
68
+ Install the repository into your Hermes plugin directory:
69
+
70
+ ```bash
71
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
72
+ ```
73
+
74
+ Then set Hermes to use it:
75
+
76
+ ```yaml
77
+ memory:
78
+ provider: metronix
79
+ ```
80
+
81
+ ## Python distribution
82
+
83
+ `pip install hermes-memory-metronix` distributes the adapter for development
84
+ and Hermes-hosted environments. It does not register the provider with Hermes.
85
+ For Hermes discovery, install this GitHub plugin with:
86
+
87
+ ```bash
88
+ hermes plugins install mtrnix/hermes-memory-metronix --no-enable
89
+ ```
90
+
91
+ ## Plugin config
92
+
93
+ The plugin reads non-secret config from:
94
+
95
+ - `$HERMES_HOME/metronix.json`
96
+
97
+ And secrets from:
98
+
99
+ - `$HERMES_HOME/.env`
100
+ - process environment
101
+
102
+ Example `metronix.json`:
103
+
104
+ ```json
105
+ {
106
+ "base_url": "http://localhost:8000",
107
+ "workspace_id": "MTRNIX",
108
+ "agent_id": "hermes",
109
+ "prefetch": true,
110
+ "prefetch_top_k": 8,
111
+ "prefetch_types": ["fact", "preference", "pinned"],
112
+ "cite_sources": true,
113
+ "write_through": true,
114
+ "write_scope": "workspace",
115
+ "sync_turns": true
116
+ }
117
+ ```
118
+
119
+ Secrets:
120
+
121
+ ```bash
122
+ METRONIX_AUTH_TOKEN=...
123
+ # or:
124
+ METRONIX_EMAIL=admin@metronix.local
125
+ METRONIX_PASSWORD=...
126
+ ```
127
+
128
+ Important:
129
+
130
+ - `METRONIX_AUTH_TOKEN` must be a REST JWT or personal API key for `/api/v1/*`
131
+ - `METRONIX_MCP_API_KEY` is for `/mcp`, not `/api/v1/memory/*`
132
+ - if you provide both a bearer token and login credentials, the client will
133
+ retry once with a fresh login JWT when the original bearer gets a `401`
134
+
135
+ ## Mapping notes
136
+
137
+ Hermes write scopes map to Metronix scopes like this:
138
+
139
+ - `per_agent` -> `per_agent`
140
+ - `workspace` -> `global`
141
+ - `shared` -> `global`
142
+ - `session` -> `session`
143
+
144
+ The current prefetch path uses Metronix memory search, so `prefetch_types`
145
+ maps to Metronix memory kinds:
146
+
147
+ - `fact`
148
+ - `preference`
149
+ - `pinned`
150
+
151
+ `page` is not wired yet because the current scaffold does not call a unified
152
+ knowledge-search endpoint.
153
+
154
+ ## Migrating an existing llm-wiki into Metronix
155
+
156
+ Hermes's bundled `llm-wiki` skill maintains a directory of markdown pages
157
+ (`entities/`, `concepts/`, `comparisons/`, `queries/`, `raw/`) at `$WIKI_PATH`
158
+ (default `~/wiki`). To bulk-ingest an existing wiki into Metronix's Knowledge
159
+ Base (chunked, embedded, searchable via `metronix_search_fast`/`metronix_get`):
160
+
161
+ ```bash
162
+ python scripts/migrate_wiki.py \
163
+ --wiki-path ~/wiki \
164
+ --base-url http://localhost:8000 \
165
+ --workspace-id MTRNIX \
166
+ --auth-token "$METRONIX_AUTH_TOKEN"
167
+ ```
168
+
169
+ Each page becomes a document with `source_type="hermes_llm_wiki"` and a
170
+ deterministic `doc_label` derived from its wiki-relative path, so re-running
171
+ the script updates existing documents instead of duplicating them. By
172
+ default, only `raw/`, `entities/`, `concepts/`, `comparisons/`, and
173
+ `queries/` are ingested; `SCHEMA.md`, `index.md`, `log*.md`, and
174
+ `_archive/**` are skipped (pass `--include-archive` to include archived
175
+ pages instead).
176
+
177
+ Requires `METRONIX_AUTH_TOKEN` to be a REST JWT or personal API key for
178
+ `/api/v1/*`, not `METRONIX_MCP_API_KEY`, which is for `/mcp` only.
179
+
180
+ ## Development
181
+
182
+ Run the fast local checks:
183
+
184
+ ```bash
185
+ uv run --extra dev pytest tests/unit -v
186
+ RUN_INTEGRATION_TESTS=1 uv run --extra dev pytest tests/integration/test_live_metronix.py -v
187
+ ```
188
+
189
+ ### Verify against Hermes
190
+
191
+ Clone a clean Hermes checkout separately, then verify both the current
192
+ `MemoryProvider` abstract base class and Hermes's real plugin loader:
193
+
194
+ ```bash
195
+ HERMES_AGENT_SRC=/absolute/path/to/hermes-agent \
196
+ uv run --extra dev pytest \
197
+ tests/unit/test_real_abc_contract.py tests/unit/test_hermes_plugin.py -v
198
+ ```
199
+
200
+ The compatibility tests skip with an explicit reason when `HERMES_AGENT_SRC`
201
+ does not point to a Hermes checkout. They should pass before publishing a
202
+ plugin release.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ plugin/hermes_memory_metronix.egg-info/PKG-INFO
5
+ plugin/hermes_memory_metronix.egg-info/SOURCES.txt
6
+ plugin/hermes_memory_metronix.egg-info/dependency_links.txt
7
+ plugin/hermes_memory_metronix.egg-info/requires.txt
8
+ plugin/hermes_memory_metronix.egg-info/top_level.txt
9
+ plugin/metronix/__init__.py
10
+ plugin/metronix/client.py
11
+ plugin/metronix/plugin.yaml
@@ -0,0 +1,5 @@
1
+ requests<3,>=2.31
2
+ pyyaml<7,>=6
3
+
4
+ [dev]
5
+ pytest<10,>=9
@@ -0,0 +1,337 @@
1
+ """Standalone Hermes memory-provider scaffold for Metronix.
2
+
3
+ Designed to be installed into ``~/.hermes/plugins/metronix``.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ import logging
10
+ import os
11
+ import threading
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ from agent.memory_provider import MemoryProvider
16
+
17
+ from .client import MetronixClient
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ def _get_hermes_home() -> Path:
23
+ try:
24
+ from hermes_constants import get_hermes_home
25
+
26
+ return get_hermes_home()
27
+ except Exception:
28
+ return Path.home() / ".hermes"
29
+
30
+
31
+ def _read_json(path: Path) -> dict[str, Any]:
32
+ if not path.exists():
33
+ return {}
34
+ try:
35
+ return dict(json.loads(path.read_text(encoding="utf-8")))
36
+ except Exception:
37
+ return {}
38
+
39
+
40
+ def _write_json(path: Path, payload: dict[str, Any]) -> None:
41
+ path.parent.mkdir(parents=True, exist_ok=True)
42
+ path.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8")
43
+
44
+
45
+ class MetronixMemoryProvider(MemoryProvider):
46
+ def __init__(self) -> None:
47
+ self._config: dict[str, Any] = {}
48
+ self._client: MetronixClient | None = None
49
+ self._session_id = ""
50
+ self._agent_id = "hermes"
51
+ self._warning_callback = None
52
+ self._status_callback = None
53
+ self._prefetch_cache: dict[str, str] = {}
54
+ self._prefetch_lock = threading.Lock()
55
+
56
+ @property
57
+ def name(self) -> str:
58
+ return "metronix"
59
+
60
+ def is_available(self) -> bool:
61
+ cfg = self._load_config()
62
+ has_auth = bool(cfg.get("auth_token") or (cfg.get("email") and cfg.get("password")))
63
+ return bool(cfg.get("base_url") and cfg.get("workspace_id") and has_auth)
64
+
65
+ def save_config(self, values, hermes_home):
66
+ path = Path(hermes_home) / "metronix.json"
67
+ existing = _read_json(path)
68
+ existing.update(values)
69
+ _write_json(path, existing)
70
+
71
+ def get_config_schema(self):
72
+ return [
73
+ {"key": "base_url", "description": "Metronix base URL", "required": True},
74
+ {"key": "workspace_id", "description": "Metronix workspace id", "required": True},
75
+ {"key": "auth_token", "description": "Metronix bearer token", "secret": True, "env_var": "METRONIX_AUTH_TOKEN"},
76
+ {"key": "email", "description": "Metronix login email"},
77
+ {"key": "password", "description": "Metronix login password", "secret": True, "env_var": "METRONIX_PASSWORD"},
78
+ {"key": "agent_id", "description": "Stable Hermes agent id", "default": "hermes"},
79
+ {"key": "prefetch", "description": "Enable Metronix prefetch injection", "default": True},
80
+ {"key": "prefetch_top_k", "description": "Top K prefetched memories", "default": 8},
81
+ {"key": "prefetch_types", "description": "Kinds to inject: fact, preference, pinned", "default": ["fact", "preference", "pinned"]},
82
+ {"key": "cite_sources", "description": "Include record ids in injected context", "default": True},
83
+ {"key": "write_through", "description": "Mirror Hermes memory writes into Metronix", "default": True},
84
+ {"key": "write_scope", "description": "per_agent, workspace, shared, or session", "default": "workspace"},
85
+ {"key": "sync_turns", "description": "Persist completed turns as session memory", "default": True},
86
+ {"key": "timeout_seconds", "description": "REST timeout in seconds", "default": 20},
87
+ ]
88
+
89
+ def initialize(self, session_id: str, **kwargs) -> None:
90
+ self._config = self._load_config()
91
+ self._session_id = session_id
92
+ self._warning_callback = kwargs.get("warning_callback")
93
+ self._status_callback = kwargs.get("status_callback")
94
+ configured_agent_id = str(self._config.get("agent_id") or "").strip()
95
+ self._agent_id = (
96
+ configured_agent_id
97
+ if configured_agent_id and configured_agent_id != "hermes"
98
+ else ""
99
+ ) or (
100
+ str(kwargs.get("agent_identity") or "").strip()
101
+ or "hermes"
102
+ )
103
+ self._client = MetronixClient(
104
+ base_url=str(self._config.get("base_url", "")).strip(),
105
+ workspace_id=str(self._config.get("workspace_id", "")).strip(),
106
+ auth_token=str(self._config.get("auth_token", "")).strip(),
107
+ email=str(self._config.get("email", "")).strip(),
108
+ password=str(self._config.get("password", "")).strip(),
109
+ timeout=float(self._config.get("timeout_seconds", 20) or 20),
110
+ )
111
+ if self._status_callback:
112
+ try:
113
+ self._status_callback("Metronix memory provider initialized")
114
+ except Exception:
115
+ pass
116
+
117
+ def system_prompt_block(self) -> str:
118
+ return (
119
+ "# Metronix Memory\n"
120
+ "Active. Relevant Metronix memory may be injected before each turn. "
121
+ "Treat it as background context, not as new user input."
122
+ )
123
+
124
+ def prefetch(self, query: str, *, session_id: str = "") -> str:
125
+ if not self._config.get("prefetch", True):
126
+ return ""
127
+ target_session_id = session_id or self._session_id
128
+ with self._prefetch_lock:
129
+ return self._prefetch_cache.get(target_session_id, "")
130
+
131
+ def queue_prefetch(self, query: str, *, session_id: str = "") -> None:
132
+ if not self._client or not self._config.get("prefetch", True):
133
+ return
134
+ target_session_id = session_id or self._session_id
135
+
136
+ def _fetch() -> None:
137
+ try:
138
+ agent_filter = self._agent_id if self._read_scope() == "per_agent" else None
139
+ results = self._client.search_memory(
140
+ query=query,
141
+ top_k=int(self._config.get("prefetch_top_k", 8) or 8),
142
+ agent_id=agent_filter,
143
+ )
144
+ kinds = {str(k).strip().lower() for k in self._config.get("prefetch_types", []) or []}
145
+ filtered = [r for r in results if self._keep_prefetch_result(r, kinds)]
146
+ formatted = self._format_prefetch(filtered)
147
+ with self._prefetch_lock:
148
+ self._prefetch_cache[target_session_id] = formatted
149
+ except Exception as exc:
150
+ self._warn(f"Metronix prefetch failed: {exc}")
151
+
152
+ threading.Thread(target=_fetch, daemon=True, name="metronix-queue-prefetch").start()
153
+
154
+ def on_session_switch(
155
+ self,
156
+ new_session_id: str,
157
+ *,
158
+ parent_session_id: str = "",
159
+ reset: bool = False,
160
+ rewound: bool = False,
161
+ **kwargs: Any,
162
+ ) -> None:
163
+ if not new_session_id:
164
+ return
165
+ old_session_id = self._session_id
166
+ self._session_id = new_session_id
167
+ with self._prefetch_lock:
168
+ self._prefetch_cache.pop(old_session_id, None)
169
+
170
+ def sync_turn(
171
+ self,
172
+ user_content: str,
173
+ assistant_content: str,
174
+ *,
175
+ session_id: str = "",
176
+ messages=None,
177
+ ) -> None:
178
+ if not self._client or not self._config.get("sync_turns", True):
179
+ return
180
+ target_session_id = session_id or self._session_id
181
+
182
+ def _sync() -> None:
183
+ try:
184
+ if user_content.strip():
185
+ self._client.create_memory(
186
+ content=user_content.strip(),
187
+ agent_id=self._agent_id,
188
+ scope="session",
189
+ kind="fact",
190
+ source_type="hermes_turn_user",
191
+ session_id=target_session_id,
192
+ metadata={"session_id": target_session_id, "role": "user"},
193
+ )
194
+ if assistant_content.strip():
195
+ self._client.create_memory(
196
+ content=assistant_content.strip(),
197
+ agent_id=self._agent_id,
198
+ scope="session",
199
+ kind="fact",
200
+ source_type="hermes_turn_assistant",
201
+ session_id=target_session_id,
202
+ metadata={"session_id": target_session_id, "role": "assistant"},
203
+ )
204
+ except Exception as exc:
205
+ self._warn(f"Metronix turn sync failed: {exc}")
206
+
207
+ threading.Thread(target=_sync, daemon=True, name="metronix-sync-turn").start()
208
+
209
+ def on_memory_write(
210
+ self,
211
+ action: str,
212
+ target: str,
213
+ content: str,
214
+ metadata: dict[str, Any] | None = None,
215
+ ) -> None:
216
+ if action != "add" or not content or not self._client:
217
+ return
218
+ if not self._config.get("write_through", True):
219
+ return
220
+
221
+ def _write() -> None:
222
+ try:
223
+ self._client.create_memory(
224
+ content=content.strip(),
225
+ agent_id=self._agent_id,
226
+ scope=self._map_write_scope(self._config.get("write_scope", "workspace")),
227
+ kind=self._infer_kind(target, metadata),
228
+ source_type="hermes_memory_write",
229
+ tags=["hermes", target],
230
+ metadata={"target": target, **(metadata or {})},
231
+ )
232
+ except Exception as exc:
233
+ self._warn(f"Metronix write-through failed: {exc}")
234
+
235
+ threading.Thread(target=_write, daemon=True, name="metronix-memory-write").start()
236
+
237
+ def get_tool_schemas(self):
238
+ return []
239
+
240
+ def shutdown(self) -> None:
241
+ return None
242
+
243
+ def _load_config(self) -> dict[str, Any]:
244
+ home = _get_hermes_home()
245
+ file_cfg = _read_json(home / "metronix.json")
246
+ merged: dict[str, Any] = {
247
+ "base_url": os.environ.get("METRONIX_BASE_URL", ""),
248
+ "workspace_id": os.environ.get("METRONIX_WORKSPACE_ID", ""),
249
+ "auth_token": os.environ.get("METRONIX_AUTH_TOKEN", ""),
250
+ "email": os.environ.get("METRONIX_EMAIL", ""),
251
+ "password": os.environ.get("METRONIX_PASSWORD", ""),
252
+ "agent_id": os.environ.get("METRONIX_AGENT_ID", ""),
253
+ "prefetch": self._env_bool("METRONIX_PREFETCH", True),
254
+ "prefetch_top_k": int(os.environ.get("METRONIX_PREFETCH_TOP_K", "8")),
255
+ "prefetch_types": self._env_list("METRONIX_PREFETCH_TYPES", ["fact", "preference", "pinned"]),
256
+ "cite_sources": self._env_bool("METRONIX_CITE_SOURCES", True),
257
+ "write_through": self._env_bool("METRONIX_WRITE_THROUGH", True),
258
+ "write_scope": os.environ.get("METRONIX_WRITE_SCOPE", "workspace"),
259
+ "sync_turns": self._env_bool("METRONIX_SYNC_TURNS", True),
260
+ "timeout_seconds": float(os.environ.get("METRONIX_TIMEOUT_SECONDS", "20")),
261
+ }
262
+ merged.update(file_cfg)
263
+ for config_key, environment_key in (
264
+ ("auth_token", "METRONIX_AUTH_TOKEN"),
265
+ ("email", "METRONIX_EMAIL"),
266
+ ("password", "METRONIX_PASSWORD"),
267
+ ("agent_id", "METRONIX_AGENT_ID"),
268
+ ):
269
+ environment_value = os.environ.get(environment_key)
270
+ if environment_value:
271
+ merged[config_key] = environment_value
272
+ return merged
273
+
274
+ def _read_scope(self) -> str:
275
+ write_scope = str(self._config.get("write_scope", "workspace")).strip().lower()
276
+ return "per_agent" if write_scope == "per_agent" else "workspace"
277
+
278
+ def _keep_prefetch_result(self, result: dict[str, Any], kinds: set[str]) -> bool:
279
+ if not kinds:
280
+ return True
281
+ record = result.get("record") or {}
282
+ kind = str(record.get("kind", "") or "").strip().lower()
283
+ return kind in kinds
284
+
285
+ def _format_prefetch(self, results: list[dict[str, Any]]) -> str:
286
+ if not results:
287
+ return ""
288
+ lines = ["<memory-context>", "## Metronix Memory Context"]
289
+ cite = bool(self._config.get("cite_sources", True))
290
+ for item in results:
291
+ record = item.get("record") or {}
292
+ content = str(record.get("content", "") or "").strip()
293
+ if not content:
294
+ continue
295
+ prefix = f"[{record.get('id')}]" if cite and record.get("id") else "-"
296
+ lines.append(f"{prefix} {content}")
297
+ lines.append("</memory-context>")
298
+ return "\n".join(lines) if len(lines) > 3 else ""
299
+
300
+ def _map_write_scope(self, scope: Any) -> str:
301
+ normalized = str(scope or "workspace").strip().lower()
302
+ if normalized == "per_agent":
303
+ return "per_agent"
304
+ if normalized == "session":
305
+ return "session"
306
+ return "global"
307
+
308
+ def _infer_kind(self, target: str, metadata: dict[str, Any] | None) -> str:
309
+ if target == "user":
310
+ return "preference"
311
+ if metadata and str(metadata.get("kind", "")).strip():
312
+ return str(metadata["kind"]).strip().lower()
313
+ return "fact"
314
+
315
+ def _warn(self, message: str) -> None:
316
+ logger.debug(message)
317
+ if self._warning_callback:
318
+ try:
319
+ self._warning_callback(message)
320
+ except Exception:
321
+ pass
322
+
323
+ def _env_bool(self, key: str, default: bool) -> bool:
324
+ raw = os.environ.get(key)
325
+ if raw is None:
326
+ return default
327
+ return raw.strip().lower() not in {"0", "false", "no", "off"}
328
+
329
+ def _env_list(self, key: str, default: list[str]) -> list[str]:
330
+ raw = os.environ.get(key)
331
+ if not raw:
332
+ return default
333
+ return [part.strip() for part in raw.split(",") if part.strip()]
334
+
335
+
336
+ def register(ctx) -> None:
337
+ ctx.register_memory_provider(MetronixMemoryProvider())
@@ -0,0 +1,136 @@
1
+ from __future__ import annotations
2
+
3
+ import threading
4
+ from typing import Any
5
+ from urllib.parse import urlencode
6
+
7
+ import requests
8
+
9
+
10
+ class MetronixClient:
11
+ """Thin synchronous REST client for the standalone Hermes plugin."""
12
+
13
+ def __init__(
14
+ self,
15
+ *,
16
+ base_url: str,
17
+ workspace_id: str,
18
+ auth_token: str = "",
19
+ email: str = "",
20
+ password: str = "",
21
+ timeout: float = 20.0,
22
+ ) -> None:
23
+ self._base_url = base_url.rstrip("/")
24
+ self._workspace_id = workspace_id
25
+ self._auth_token = auth_token
26
+ self._email = email
27
+ self._password = password
28
+ self._timeout = timeout
29
+ self._session = requests.Session()
30
+ self._login_lock = threading.Lock()
31
+
32
+ def search_memory(
33
+ self,
34
+ *,
35
+ query: str,
36
+ top_k: int,
37
+ agent_id: str | None = None,
38
+ ) -> list[dict[str, Any]]:
39
+ payload: dict[str, Any] = {"query": query, "top_k": top_k}
40
+ if agent_id:
41
+ payload["agent_id"] = agent_id
42
+ data = self._request("POST", "/api/v1/memory/search", json=payload)
43
+ return list(data.get("results", []))
44
+
45
+ def create_memory(
46
+ self,
47
+ *,
48
+ content: str,
49
+ agent_id: str,
50
+ scope: str,
51
+ kind: str,
52
+ source_type: str,
53
+ tags: list[str] | None = None,
54
+ session_id: str | None = None,
55
+ metadata: dict[str, Any] | None = None,
56
+ ) -> dict[str, Any]:
57
+ payload: dict[str, Any] = {
58
+ "content": content,
59
+ "agent_id": agent_id,
60
+ "scope": scope,
61
+ "kind": kind,
62
+ "source_type": source_type,
63
+ "tags": tags or [],
64
+ "metadata": metadata or {},
65
+ }
66
+ if session_id:
67
+ payload["session_id"] = session_id
68
+ return self._request("POST", "/api/v1/memory/records", json=payload)
69
+
70
+ def store_document(
71
+ self,
72
+ *,
73
+ content: str,
74
+ title: str | None = None,
75
+ doc_label: str | None = None,
76
+ source_type: str = "memory",
77
+ metadata: dict[str, Any] | None = None,
78
+ ) -> dict[str, Any]:
79
+ payload: dict[str, Any] = {"content": content, "source_type": source_type}
80
+ if title:
81
+ payload["title"] = title
82
+ if doc_label:
83
+ payload["doc_label"] = doc_label
84
+ if metadata:
85
+ payload["metadata"] = metadata
86
+ return self._request("POST", "/api/v1/knowledge/store", json=payload)
87
+
88
+ def ping(self) -> dict[str, Any]:
89
+ return self._request("GET", "/api/v1/auth/me")
90
+
91
+ def delete_memory(self, record_id: str) -> None:
92
+ self._request("DELETE", f"/api/v1/memory/records/{record_id}")
93
+
94
+ def _request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
95
+ headers = dict(kwargs.pop("headers", {}) or {})
96
+ query = urlencode({"workspace_id": self._workspace_id})
97
+ url = f"{self._base_url}{path}?{query}"
98
+ response = self._send_request(method, url, headers=headers, **kwargs)
99
+ if response.status_code == 401 and self._email and self._password:
100
+ self._auth_token = ""
101
+ response = self._send_request(method, url, headers=headers, **kwargs)
102
+ response.raise_for_status()
103
+ if not response.content:
104
+ return {}
105
+ return dict(response.json())
106
+
107
+ def _send_request(self, method: str, url: str, *, headers: dict[str, Any], **kwargs: Any):
108
+ request_headers = dict(headers)
109
+ token = self._get_token()
110
+ if token:
111
+ request_headers["Authorization"] = f"Bearer {token}"
112
+ return self._session.request(
113
+ method,
114
+ url,
115
+ headers=request_headers,
116
+ timeout=self._timeout,
117
+ **kwargs,
118
+ )
119
+
120
+ def _get_token(self) -> str:
121
+ if self._auth_token:
122
+ return self._auth_token
123
+ if not (self._email and self._password):
124
+ return ""
125
+ with self._login_lock:
126
+ if self._auth_token:
127
+ return self._auth_token
128
+ response = self._session.post(
129
+ f"{self._base_url}/api/v1/auth/login",
130
+ json={"email": self._email, "password": self._password},
131
+ timeout=self._timeout,
132
+ )
133
+ response.raise_for_status()
134
+ data = response.json()
135
+ self._auth_token = str(data.get("token", "") or "")
136
+ return self._auth_token
@@ -0,0 +1,6 @@
1
+ name: metronix
2
+ version: 0.1.0
3
+ description: "Metronix shared memory provider for Hermes"
4
+ hooks:
5
+ - on_memory_write
6
+ - on_session_end
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "hermes-memory-metronix"
7
+ version = "0.1.2"
8
+ description = "Standalone Hermes memory-provider plugin scaffold for Metronix"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ authors = [{ name = "Metronix Contributors" }]
12
+ license = "Apache-2.0"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3 :: Only",
16
+ "Programming Language :: Python :: 3.11",
17
+ "Operating System :: OS Independent",
18
+ ]
19
+ dependencies = [
20
+ "requests>=2.31,<3",
21
+ "pyyaml>=6,<7",
22
+ ]
23
+
24
+ [project.urls]
25
+ Repository = "https://github.com/mtrnix/hermes-memory-metronix"
26
+ Issues = "https://github.com/mtrnix/hermes-memory-metronix/issues"
27
+
28
+ [project.optional-dependencies]
29
+ dev = [
30
+ "pytest>=9,<10",
31
+ ]
32
+
33
+ [tool.setuptools.packages.find]
34
+ where = ["plugin"]
35
+
36
+ [tool.setuptools.package-data]
37
+ metronix = ["plugin.yaml"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
41
+ pythonpath = ["plugin"]
42
+ markers = ["integration: tests that require a live Metronix backend"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+