memhub-sdk 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.
Files changed (72) hide show
  1. memhub_sdk-0.1.0/LICENSE +201 -0
  2. memhub_sdk-0.1.0/NOTICE +19 -0
  3. memhub_sdk-0.1.0/PKG-INFO +225 -0
  4. memhub_sdk-0.1.0/README.md +201 -0
  5. memhub_sdk-0.1.0/pyproject.toml +61 -0
  6. memhub_sdk-0.1.0/setup.cfg +4 -0
  7. memhub_sdk-0.1.0/src/memhub/__init__.py +10 -0
  8. memhub_sdk-0.1.0/src/memhub/__main__.py +5 -0
  9. memhub_sdk-0.1.0/src/memhub/capture/__init__.py +9 -0
  10. memhub_sdk-0.1.0/src/memhub/capture/checkpoint.py +89 -0
  11. memhub_sdk-0.1.0/src/memhub/capture/cursor_plan.py +73 -0
  12. memhub_sdk-0.1.0/src/memhub/capture/transcript.py +121 -0
  13. memhub_sdk-0.1.0/src/memhub/cli/__init__.py +1 -0
  14. memhub_sdk-0.1.0/src/memhub/cli/hook_commands.py +138 -0
  15. memhub_sdk-0.1.0/src/memhub/cli/main.py +102 -0
  16. memhub_sdk-0.1.0/src/memhub/cli/setup_commands.py +127 -0
  17. memhub_sdk-0.1.0/src/memhub/cli/streams.py +28 -0
  18. memhub_sdk-0.1.0/src/memhub/cli/syncbot_commands.py +109 -0
  19. memhub_sdk-0.1.0/src/memhub/cli/workspace.py +43 -0
  20. memhub_sdk-0.1.0/src/memhub/client.py +164 -0
  21. memhub_sdk-0.1.0/src/memhub/config.py +145 -0
  22. memhub_sdk-0.1.0/src/memhub/errors.py +19 -0
  23. memhub_sdk-0.1.0/src/memhub/git_repo.py +146 -0
  24. memhub_sdk-0.1.0/src/memhub/hooks.py +110 -0
  25. memhub_sdk-0.1.0/src/memhub/local_store.py +178 -0
  26. memhub_sdk-0.1.0/src/memhub/models.py +86 -0
  27. memhub_sdk-0.1.0/src/memhub/outbound.py +101 -0
  28. memhub_sdk-0.1.0/src/memhub/push_range.py +106 -0
  29. memhub_sdk-0.1.0/src/memhub/py.typed +0 -0
  30. memhub_sdk-0.1.0/src/memhub/rekal/LICENSE +201 -0
  31. memhub_sdk-0.1.0/src/memhub/rekal/__init__.py +5 -0
  32. memhub_sdk-0.1.0/src/memhub/rekal/gitx.py +40 -0
  33. memhub_sdk-0.1.0/src/memhub/rekal/scrub/__init__.py +10 -0
  34. memhub_sdk-0.1.0/src/memhub/rekal/scrub/paths.py +84 -0
  35. memhub_sdk-0.1.0/src/memhub/rekal/scrub/scrub_payload.py +34 -0
  36. memhub_sdk-0.1.0/src/memhub/rekal/scrub/secrets.py +171 -0
  37. memhub_sdk-0.1.0/src/memhub/rekal/session/__init__.py +31 -0
  38. memhub_sdk-0.1.0/src/memhub/rekal/session/bench.py +48 -0
  39. memhub_sdk-0.1.0/src/memhub/rekal/session/claude.py +177 -0
  40. memhub_sdk-0.1.0/src/memhub/rekal/session/codex.py +158 -0
  41. memhub_sdk-0.1.0/src/memhub/rekal/session/codex_entries.py +139 -0
  42. memhub_sdk-0.1.0/src/memhub/rekal/session/compressed.py +38 -0
  43. memhub_sdk-0.1.0/src/memhub/rekal/session/content_blocks.py +126 -0
  44. memhub_sdk-0.1.0/src/memhub/rekal/session/decoding.py +128 -0
  45. memhub_sdk-0.1.0/src/memhub/rekal/session/identity.py +33 -0
  46. memhub_sdk-0.1.0/src/memhub/rekal/session/models.py +114 -0
  47. memhub_sdk-0.1.0/src/memhub/rekal/session/repo_paths.py +35 -0
  48. memhub_sdk-0.1.0/src/memhub/rekal/session/transcript.py +203 -0
  49. memhub_sdk-0.1.0/src/memhub/repo_name.py +46 -0
  50. memhub_sdk-0.1.0/src/memhub/syncbot/__init__.py +5 -0
  51. memhub_sdk-0.1.0/src/memhub/syncbot/event_queue.py +91 -0
  52. memhub_sdk-0.1.0/src/memhub/syncbot/push_events.py +149 -0
  53. memhub_sdk-0.1.0/src/memhub/syncbot/sender.py +152 -0
  54. memhub_sdk-0.1.0/src/memhub/transport.py +93 -0
  55. memhub_sdk-0.1.0/src/memhub/upload.py +46 -0
  56. memhub_sdk-0.1.0/src/memhub/version.py +3 -0
  57. memhub_sdk-0.1.0/src/memhub/wire.py +182 -0
  58. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/PKG-INFO +225 -0
  59. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/SOURCES.txt +70 -0
  60. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/dependency_links.txt +1 -0
  61. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/entry_points.txt +2 -0
  62. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/requires.txt +3 -0
  63. memhub_sdk-0.1.0/src/memhub_sdk.egg-info/top_level.txt +1 -0
  64. memhub_sdk-0.1.0/tests/test_capture.py +82 -0
  65. memhub_sdk-0.1.0/tests/test_cli.py +97 -0
  66. memhub_sdk-0.1.0/tests/test_cli_syncbot.py +124 -0
  67. memhub_sdk-0.1.0/tests/test_client.py +121 -0
  68. memhub_sdk-0.1.0/tests/test_config.py +48 -0
  69. memhub_sdk-0.1.0/tests/test_hooks.py +31 -0
  70. memhub_sdk-0.1.0/tests/test_outbound.py +39 -0
  71. memhub_sdk-0.1.0/tests/test_push_range.py +53 -0
  72. memhub_sdk-0.1.0/tests/test_repo_name.py +31 -0
@@ -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 [yyyy] [name of copyright owner]
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,19 @@
1
+ MemHub
2
+ Copyright 2026 Team Nexus
3
+
4
+ This product includes software from rekal-cli (https://github.com/rekal-dev/rekal-cli),
5
+ licensed under the Apache License, Version 2.0. The full license text is in
6
+ src/memhub/rekal/LICENSE.
7
+
8
+ src/memhub/rekal is a Python translation of these rekal-cli packages at commit fce1b3f:
9
+
10
+ rekal/session from cmd/rekal/cli/session (Claude Code and Codex session discovery and parsing)
11
+ rekal/scrub from cmd/rekal/cli/scrub (secret redaction, path anonymization)
12
+ rekal/gitx from cmd/rekal/cli/gitx (rebase detection)
13
+
14
+ Each translated file names its source Go file in its header.
15
+
16
+ The hook installation in hooks.py and the turn dedup in capture/ follow patterns from rekal-cli's
17
+ init.go and checkpoint.go but are new code.
18
+
19
+ MemHub is not Rekal and is not endorsed by the rekal-cli authors.
@@ -0,0 +1,225 @@
1
+ Metadata-Version: 2.4
2
+ Name: memhub-sdk
3
+ Version: 0.1.0
4
+ Summary: MemHub CLI and Python SDK: git-aware memory for AI coding agents
5
+ Author: Team Nexus
6
+ License-Expression: Apache-2.0
7
+ Keywords: ai-agents,agent-memory,git,claude-code,codex,llm
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Environment :: Console
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Topic :: Software Development :: Version Control :: Git
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ License-File: NOTICE
21
+ License-File: src/memhub/rekal/LICENSE
22
+ Requires-Dist: zstandard>=0.23; python_version < "3.14"
23
+ Dynamic: license-file
24
+
25
+ # memhub CLI and Python SDK
26
+
27
+ One Python package, two ways in:
28
+
29
+ - The **`memhub` command** captures what AI coding agents said while you worked, ties it to the
30
+ commit it led to, and uploads it when you push.
31
+ - The **SDK** (`from memhub import Memhub`) lets an agent write a memory directly and recall
32
+ memory for the branch it is on.
33
+
34
+ Both talk to the MemHub server in [`backend/`](../backend/README.md), which holds each memory back
35
+ until its commit is actually on GitHub, and then forwards it to Memsy.
36
+
37
+ ## Install
38
+
39
+ Python 3.10 or newer, and git.
40
+
41
+ ```bash
42
+ pip install memhub-sdk # the command and the import are both `memhub`
43
+ memhub --help
44
+ ```
45
+
46
+ From a clone of this repository instead:
47
+
48
+ ```bash
49
+ cd memhub
50
+ uv sync # or: pip install -e .
51
+ uv run memhub --help # or, with the venv active: memhub --help
52
+ ```
53
+
54
+ Runtime dependencies: none, apart from `zstandard` on Python older than 3.14, for reading Codex's
55
+ compressed sessions.
56
+
57
+ ## How a commit becomes memory
58
+
59
+ 1. `memhub init` installs a `post-commit` and a `pre-push` hook. Each hook carries the line
60
+ `# managed by memhub`, and a hook from another tool is never overwritten. If `memhub` is not on
61
+ `PATH` when the hook runs, the hook falls back to `<the Python that ran init> -m memhub`, so a
62
+ memhub installed in a virtualenv keeps working without activating it. Local data lives in
63
+ `$(git rev-parse --git-common-dir)/memhub/`. That folder is inside `.git`, so it is never
64
+ committed, and every worktree of the repo shares it.
65
+ 2. **post-commit → `memhub checkpoint`** (offline). It finds Claude Code and Codex sessions for
66
+ this repo and keeps only the turns added since the last checkpoint. It removes secrets, then
67
+ writes one record for the commit to a local SQLite outbox.
68
+ 3. **pre-push → `memhub push --remote "$1" --git-pid "$PPID"`**. It reads git's ref updates from stdin and works out
69
+ which commits are new:
70
+
71
+ | Case | How it's spotted | Commits uploaded |
72
+ |---|---|---|
73
+ | Update a branch | both SHAs set | `git rev-list <remote>..<local>` |
74
+ | New branch | remote SHA all zeros | `git rev-list <local> --not --remotes=<remote>` |
75
+ | Delete a branch | local SHA all zeros | none; the webhook handles it |
76
+
77
+ It sends those commits' records with a 3-second timeout and an idempotency key, and always
78
+ exits 0. If the upload fails, the records stay queued for the next push or `memhub flush`.
79
+ Records for commits that were amended or rebased away move onto the pushed branch tip.
80
+ 4. The server keeps each memory `pending` until GitHub's push webhook shows its commit is there,
81
+ then marks it `live`, `merged` or `graveyard`. See [backend/README.md](../backend/README.md).
82
+
83
+ The reasoning behind these choices is in [docs/memhub-architecture.md](../docs/memhub-architecture.md).
84
+
85
+ ## Sending pushes to SyncBot
86
+
87
+ [SyncBot](../syncBot/README.md) is the Aetherion agent that feeds the MemHub UI. It normally
88
+ learns about pushes from GitHub's webhook. To drive a SyncBot worker running on your machine
89
+ instead, turn the pre-push hook's SyncBot step on once per clone:
90
+
91
+ ```bash
92
+ memhub init --syncbot # SyncBot in ./syncBot of this repo
93
+ memhub init --syncbot ../syncBot # or any other folder, relative to the repo root
94
+ ```
95
+
96
+ Then, on every `git push`:
97
+
98
+ 1. The pre-push hook turns each branch update into a GitHub-style push body: `ref`, `after`,
99
+ `deleted`, `repository` and `commits` with message, author, timestamp, URL and changed files.
100
+ That is what SyncBot's webhook parser reads. A deleted branch is sent as `deleted: true`. Tags
101
+ are skipped, and pushes of more than 100 commits are split into several events.
102
+ 2. The events are queued in `<git-common-dir>/memhub/syncbot-queue/`, and a background sender
103
+ starts. The hook returns at once, so the push is not slowed down.
104
+ 3. The sender waits for `git push` to finish and checks the remote-tracking branches. Events for
105
+ updates the remote rejected are dropped. A push straight to a URL has no tracking branches, so
106
+ its events are sent unchecked.
107
+ 4. It sends each event, oldest first, with `uv run aetherion agent sync_bot '<event>' --no-wait`,
108
+ run in the SyncBot folder with that folder's `.env` loaded. So the SyncBot worker
109
+ (`aetherion run` in that folder) must be up.
110
+
111
+ If SyncBot can't be reached, the events stay queued, in order, until the next push or
112
+ `memhub syncbot-send`. The sender logs to `<git-common-dir>/memhub/syncbot.log`, and
113
+ `memhub status` shows how many events are waiting. `MEMHUB_SYNCBOT_COMMAND` replaces
114
+ `uv run aetherion agent sync_bot`, for another runner or for tests.
115
+
116
+ ## CLI commands
117
+
118
+ | Command | What it does |
119
+ |---|---|
120
+ | `memhub init [--server URL] [--share team\|private] [--syncbot [FOLDER]]` | Create local data and config, and install hooks. Safe to re-run. `--syncbot` also sends pushes to a local SyncBot worker. |
121
+ | `memhub checkpoint` | Queue new agent turns under HEAD. Run by `post-commit`. |
122
+ | `memhub push --remote <name>` | Upload records for the commits being pushed. Run by `pre-push`. |
123
+ | `memhub flush [--remote origin]` | Upload queued records whose commits are already on the remote, for example after `git push --no-verify`. |
124
+ | `memhub login --token-stdin` | Save the upload token for this repo's server. |
125
+ | `memhub status` | Show server, share mode, token, hooks, outbox and SyncBot queue. |
126
+ | `memhub syncbot-send` | Send push events still queued for SyncBot. The pre-push hook runs it in the background. |
127
+
128
+ `--share private` keeps branch memory visible only to you until the branch merges. The default,
129
+ `team`, shares it once the commit is on GitHub.
130
+
131
+ ## Write and recall from Python
132
+
133
+ ```python
134
+ from memhub import Memhub
135
+
136
+ memory = Memhub(repo="calfus/payments")
137
+
138
+ # branch + commit are captured automatically
139
+ memory.write("Mobile OAuth uses the PKCE flow")
140
+
141
+ # recall from wherever the agent is working
142
+ result = memory.recall("how do we store sessions?", branch="fix/login-timeout")
143
+
144
+ result.facts # merged on the default branch: safe to state as truth
145
+ result.in_flight # live on fix/login-timeout: the current plan, not settled yet
146
+ result.context # Graveyard: "we tried this, here's why not"
147
+ ```
148
+
149
+ Each item is a `RecalledMemory` with `text`, `status`, `branch`, `commit_sha`, `agent`, `author`,
150
+ `created_at` and `score` (the share of the question's words it contains, 0 to 1).
151
+
152
+ `Memhub()` with no arguments works in a repository where `memhub init` and `memhub login` have run.
153
+ The CLI and the SDK find their settings the same way:
154
+
155
+ | Setting | Argument | Then | Then | Default |
156
+ |---|---|---|---|---|
157
+ | Server | `server_url=` / `--server` | `MEMHUB_SERVER_URL` | server saved by `memhub init` | `http://localhost:8080` |
158
+ | Token | `token=` | `MEMHUB_TOKEN` | token saved by `memhub login` | none: error |
159
+ | Repository | `repo="owner/name"` | the `origin` remote | | |
160
+ | Share mode | `--share` (init) | share mode saved by `memhub init` | | `team` |
161
+
162
+ The token is a GitHub token with push access to the repository. With a server in dev mode
163
+ (`MEMHUB_AUTH_MODE=dev`), any string works and is used as your login.
164
+
165
+ What to expect from the SDK:
166
+
167
+ - **A write starts as `pending`** and is not recalled by anyone until its commit is on GitHub.
168
+ Then it is `live` on its branch, and `merged` once the branch merges. Write after you commit.
169
+ - **A write on a commit that is later amended or rebased away is never shown.** Writes go straight
170
+ to the server, so unlike outbox records they cannot move onto the new commit. Pass `commit=`
171
+ with the SHA you will push if HEAD is about to change.
172
+ - **Live memory from other branches is never recalled.** Pass the agent's branch to see its own
173
+ in-flight work. Outside a git repository, recall still works with `repo=` and `branch=`.
174
+ - **Every failure raises `MemhubError`.** `status_code` holds the server's HTTP status, or `None`
175
+ when the server could not be reached. A dropped connection is retried once; that is safe because
176
+ each write carries an ID the server stores only once.
177
+
178
+ ## Code layout
179
+
180
+ ```
181
+ memhub/src/memhub/
182
+ ├── __init__.py SDK exports: Memhub, MemhubError, RecallResult, ...
183
+ ├── client.py The SDK client
184
+ ├── cli/ Commands: init, checkpoint, push, flush, login, status, syncbot-send
185
+ ├── capture/ Session discovery, turn dedup, record building
186
+ ├── rekal/ Translated from rekal-cli (Apache-2.0): session parsing, scrub, git helpers
187
+ ├── syncbot/ Push events for SyncBot: building, queueing, sending
188
+ ├── hooks.py Marker-tagged hook install
189
+ ├── push_range.py Pre-push stdin parsing and commit ranges
190
+ ├── outbound.py Which outbox records an upload carries
191
+ ├── local_store.py SQLite outbox and transcript cursors
192
+ ├── upload.py Push-endpoint client; transport.py does the HTTP
193
+ ├── config.py Repo config and token file
194
+ ├── git_repo.py Git plumbing
195
+ ├── repo_name.py owner/name parsing and validation
196
+ └── wire.py Upload JSON, matching the server's
197
+ ```
198
+
199
+ ## Check your work
200
+
201
+ ```bash
202
+ cd memhub
203
+ uv run ruff format --check . && uv run ruff check . && uv run pytest
204
+ ```
205
+
206
+ The tests create throwaway git repos and point `HOME` at a temp folder, so they never read your
207
+ real agent sessions or tokens. The CLI tests run the real hooks through `git commit` and
208
+ `git push` against a fake server.
209
+
210
+ ## Not wired up yet
211
+
212
+ - **Only Claude Code and Codex sessions are captured.** Rekal's parsers for Cursor, Copilot,
213
+ Gemini, Kiro and OpenCode are not translated yet; `rekal/session` keeps the adapter interface
214
+ they plug into.
215
+ - **The first checkpoint after `init`** attaches every earlier turn of this repo's sessions to that
216
+ commit.
217
+ - **Windows is untested.** Path anonymization only knows `/Users/<name>` and `/home/<name>`, not
218
+ `C:\Users\<name>`.
219
+ - **The MemHub server is not published.** The SDK and CLI need one to talk to; run it from
220
+ `backend/` in this repository.
221
+
222
+ ## Credits
223
+
224
+ `src/memhub/rekal` is translated from [rekal-cli](https://github.com/rekal-dev/rekal-cli) under
225
+ Apache-2.0; see [NOTICE](NOTICE).
@@ -0,0 +1,201 @@
1
+ # memhub CLI and Python SDK
2
+
3
+ One Python package, two ways in:
4
+
5
+ - The **`memhub` command** captures what AI coding agents said while you worked, ties it to the
6
+ commit it led to, and uploads it when you push.
7
+ - The **SDK** (`from memhub import Memhub`) lets an agent write a memory directly and recall
8
+ memory for the branch it is on.
9
+
10
+ Both talk to the MemHub server in [`backend/`](../backend/README.md), which holds each memory back
11
+ until its commit is actually on GitHub, and then forwards it to Memsy.
12
+
13
+ ## Install
14
+
15
+ Python 3.10 or newer, and git.
16
+
17
+ ```bash
18
+ pip install memhub-sdk # the command and the import are both `memhub`
19
+ memhub --help
20
+ ```
21
+
22
+ From a clone of this repository instead:
23
+
24
+ ```bash
25
+ cd memhub
26
+ uv sync # or: pip install -e .
27
+ uv run memhub --help # or, with the venv active: memhub --help
28
+ ```
29
+
30
+ Runtime dependencies: none, apart from `zstandard` on Python older than 3.14, for reading Codex's
31
+ compressed sessions.
32
+
33
+ ## How a commit becomes memory
34
+
35
+ 1. `memhub init` installs a `post-commit` and a `pre-push` hook. Each hook carries the line
36
+ `# managed by memhub`, and a hook from another tool is never overwritten. If `memhub` is not on
37
+ `PATH` when the hook runs, the hook falls back to `<the Python that ran init> -m memhub`, so a
38
+ memhub installed in a virtualenv keeps working without activating it. Local data lives in
39
+ `$(git rev-parse --git-common-dir)/memhub/`. That folder is inside `.git`, so it is never
40
+ committed, and every worktree of the repo shares it.
41
+ 2. **post-commit → `memhub checkpoint`** (offline). It finds Claude Code and Codex sessions for
42
+ this repo and keeps only the turns added since the last checkpoint. It removes secrets, then
43
+ writes one record for the commit to a local SQLite outbox.
44
+ 3. **pre-push → `memhub push --remote "$1" --git-pid "$PPID"`**. It reads git's ref updates from stdin and works out
45
+ which commits are new:
46
+
47
+ | Case | How it's spotted | Commits uploaded |
48
+ |---|---|---|
49
+ | Update a branch | both SHAs set | `git rev-list <remote>..<local>` |
50
+ | New branch | remote SHA all zeros | `git rev-list <local> --not --remotes=<remote>` |
51
+ | Delete a branch | local SHA all zeros | none; the webhook handles it |
52
+
53
+ It sends those commits' records with a 3-second timeout and an idempotency key, and always
54
+ exits 0. If the upload fails, the records stay queued for the next push or `memhub flush`.
55
+ Records for commits that were amended or rebased away move onto the pushed branch tip.
56
+ 4. The server keeps each memory `pending` until GitHub's push webhook shows its commit is there,
57
+ then marks it `live`, `merged` or `graveyard`. See [backend/README.md](../backend/README.md).
58
+
59
+ The reasoning behind these choices is in [docs/memhub-architecture.md](../docs/memhub-architecture.md).
60
+
61
+ ## Sending pushes to SyncBot
62
+
63
+ [SyncBot](../syncBot/README.md) is the Aetherion agent that feeds the MemHub UI. It normally
64
+ learns about pushes from GitHub's webhook. To drive a SyncBot worker running on your machine
65
+ instead, turn the pre-push hook's SyncBot step on once per clone:
66
+
67
+ ```bash
68
+ memhub init --syncbot # SyncBot in ./syncBot of this repo
69
+ memhub init --syncbot ../syncBot # or any other folder, relative to the repo root
70
+ ```
71
+
72
+ Then, on every `git push`:
73
+
74
+ 1. The pre-push hook turns each branch update into a GitHub-style push body: `ref`, `after`,
75
+ `deleted`, `repository` and `commits` with message, author, timestamp, URL and changed files.
76
+ That is what SyncBot's webhook parser reads. A deleted branch is sent as `deleted: true`. Tags
77
+ are skipped, and pushes of more than 100 commits are split into several events.
78
+ 2. The events are queued in `<git-common-dir>/memhub/syncbot-queue/`, and a background sender
79
+ starts. The hook returns at once, so the push is not slowed down.
80
+ 3. The sender waits for `git push` to finish and checks the remote-tracking branches. Events for
81
+ updates the remote rejected are dropped. A push straight to a URL has no tracking branches, so
82
+ its events are sent unchecked.
83
+ 4. It sends each event, oldest first, with `uv run aetherion agent sync_bot '<event>' --no-wait`,
84
+ run in the SyncBot folder with that folder's `.env` loaded. So the SyncBot worker
85
+ (`aetherion run` in that folder) must be up.
86
+
87
+ If SyncBot can't be reached, the events stay queued, in order, until the next push or
88
+ `memhub syncbot-send`. The sender logs to `<git-common-dir>/memhub/syncbot.log`, and
89
+ `memhub status` shows how many events are waiting. `MEMHUB_SYNCBOT_COMMAND` replaces
90
+ `uv run aetherion agent sync_bot`, for another runner or for tests.
91
+
92
+ ## CLI commands
93
+
94
+ | Command | What it does |
95
+ |---|---|
96
+ | `memhub init [--server URL] [--share team\|private] [--syncbot [FOLDER]]` | Create local data and config, and install hooks. Safe to re-run. `--syncbot` also sends pushes to a local SyncBot worker. |
97
+ | `memhub checkpoint` | Queue new agent turns under HEAD. Run by `post-commit`. |
98
+ | `memhub push --remote <name>` | Upload records for the commits being pushed. Run by `pre-push`. |
99
+ | `memhub flush [--remote origin]` | Upload queued records whose commits are already on the remote, for example after `git push --no-verify`. |
100
+ | `memhub login --token-stdin` | Save the upload token for this repo's server. |
101
+ | `memhub status` | Show server, share mode, token, hooks, outbox and SyncBot queue. |
102
+ | `memhub syncbot-send` | Send push events still queued for SyncBot. The pre-push hook runs it in the background. |
103
+
104
+ `--share private` keeps branch memory visible only to you until the branch merges. The default,
105
+ `team`, shares it once the commit is on GitHub.
106
+
107
+ ## Write and recall from Python
108
+
109
+ ```python
110
+ from memhub import Memhub
111
+
112
+ memory = Memhub(repo="calfus/payments")
113
+
114
+ # branch + commit are captured automatically
115
+ memory.write("Mobile OAuth uses the PKCE flow")
116
+
117
+ # recall from wherever the agent is working
118
+ result = memory.recall("how do we store sessions?", branch="fix/login-timeout")
119
+
120
+ result.facts # merged on the default branch: safe to state as truth
121
+ result.in_flight # live on fix/login-timeout: the current plan, not settled yet
122
+ result.context # Graveyard: "we tried this, here's why not"
123
+ ```
124
+
125
+ Each item is a `RecalledMemory` with `text`, `status`, `branch`, `commit_sha`, `agent`, `author`,
126
+ `created_at` and `score` (the share of the question's words it contains, 0 to 1).
127
+
128
+ `Memhub()` with no arguments works in a repository where `memhub init` and `memhub login` have run.
129
+ The CLI and the SDK find their settings the same way:
130
+
131
+ | Setting | Argument | Then | Then | Default |
132
+ |---|---|---|---|---|
133
+ | Server | `server_url=` / `--server` | `MEMHUB_SERVER_URL` | server saved by `memhub init` | `http://localhost:8080` |
134
+ | Token | `token=` | `MEMHUB_TOKEN` | token saved by `memhub login` | none: error |
135
+ | Repository | `repo="owner/name"` | the `origin` remote | | |
136
+ | Share mode | `--share` (init) | share mode saved by `memhub init` | | `team` |
137
+
138
+ The token is a GitHub token with push access to the repository. With a server in dev mode
139
+ (`MEMHUB_AUTH_MODE=dev`), any string works and is used as your login.
140
+
141
+ What to expect from the SDK:
142
+
143
+ - **A write starts as `pending`** and is not recalled by anyone until its commit is on GitHub.
144
+ Then it is `live` on its branch, and `merged` once the branch merges. Write after you commit.
145
+ - **A write on a commit that is later amended or rebased away is never shown.** Writes go straight
146
+ to the server, so unlike outbox records they cannot move onto the new commit. Pass `commit=`
147
+ with the SHA you will push if HEAD is about to change.
148
+ - **Live memory from other branches is never recalled.** Pass the agent's branch to see its own
149
+ in-flight work. Outside a git repository, recall still works with `repo=` and `branch=`.
150
+ - **Every failure raises `MemhubError`.** `status_code` holds the server's HTTP status, or `None`
151
+ when the server could not be reached. A dropped connection is retried once; that is safe because
152
+ each write carries an ID the server stores only once.
153
+
154
+ ## Code layout
155
+
156
+ ```
157
+ memhub/src/memhub/
158
+ ├── __init__.py SDK exports: Memhub, MemhubError, RecallResult, ...
159
+ ├── client.py The SDK client
160
+ ├── cli/ Commands: init, checkpoint, push, flush, login, status, syncbot-send
161
+ ├── capture/ Session discovery, turn dedup, record building
162
+ ├── rekal/ Translated from rekal-cli (Apache-2.0): session parsing, scrub, git helpers
163
+ ├── syncbot/ Push events for SyncBot: building, queueing, sending
164
+ ├── hooks.py Marker-tagged hook install
165
+ ├── push_range.py Pre-push stdin parsing and commit ranges
166
+ ├── outbound.py Which outbox records an upload carries
167
+ ├── local_store.py SQLite outbox and transcript cursors
168
+ ├── upload.py Push-endpoint client; transport.py does the HTTP
169
+ ├── config.py Repo config and token file
170
+ ├── git_repo.py Git plumbing
171
+ ├── repo_name.py owner/name parsing and validation
172
+ └── wire.py Upload JSON, matching the server's
173
+ ```
174
+
175
+ ## Check your work
176
+
177
+ ```bash
178
+ cd memhub
179
+ uv run ruff format --check . && uv run ruff check . && uv run pytest
180
+ ```
181
+
182
+ The tests create throwaway git repos and point `HOME` at a temp folder, so they never read your
183
+ real agent sessions or tokens. The CLI tests run the real hooks through `git commit` and
184
+ `git push` against a fake server.
185
+
186
+ ## Not wired up yet
187
+
188
+ - **Only Claude Code and Codex sessions are captured.** Rekal's parsers for Cursor, Copilot,
189
+ Gemini, Kiro and OpenCode are not translated yet; `rekal/session` keeps the adapter interface
190
+ they plug into.
191
+ - **The first checkpoint after `init`** attaches every earlier turn of this repo's sessions to that
192
+ commit.
193
+ - **Windows is untested.** Path anonymization only knows `/Users/<name>` and `/home/<name>`, not
194
+ `C:\Users\<name>`.
195
+ - **The MemHub server is not published.** The SDK and CLI need one to talk to; run it from
196
+ `backend/` in this repository.
197
+
198
+ ## Credits
199
+
200
+ `src/memhub/rekal` is translated from [rekal-cli](https://github.com/rekal-dev/rekal-cli) under
201
+ Apache-2.0; see [NOTICE](NOTICE).