@krimto-labs/krimto 0.2.6

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 (42) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +268 -0
  3. package/bin/krimto.mjs +15 -0
  4. package/package.json +53 -0
  5. package/src/access/.gitkeep +0 -0
  6. package/src/access/auth.ts +123 -0
  7. package/src/access/membership.ts +132 -0
  8. package/src/access/membershipStore.ts +134 -0
  9. package/src/access/scope.ts +72 -0
  10. package/src/index/.gitkeep +0 -0
  11. package/src/index/db.ts +44 -0
  12. package/src/index/embeddings.ts +92 -0
  13. package/src/index/factIndex.ts +266 -0
  14. package/src/index/providers.ts +132 -0
  15. package/src/index/schema.ts +57 -0
  16. package/src/index/serialize.ts +16 -0
  17. package/src/retrieval/.gitkeep +0 -0
  18. package/src/retrieval/lexical.ts +75 -0
  19. package/src/retrieval/pipeline.ts +183 -0
  20. package/src/server/admin.ts +137 -0
  21. package/src/server/banner.ts +39 -0
  22. package/src/server/bootstrap.ts +56 -0
  23. package/src/server/connect.ts +46 -0
  24. package/src/server/errors.ts +56 -0
  25. package/src/server/health.ts +89 -0
  26. package/src/server/http.ts +114 -0
  27. package/src/server/index.ts +379 -0
  28. package/src/server/ratelimit.ts +76 -0
  29. package/src/server/telemetry.ts +135 -0
  30. package/src/server/tokenVerifier.ts +28 -0
  31. package/src/server/tools.ts +292 -0
  32. package/src/storage/.gitkeep +0 -0
  33. package/src/storage/batcher.ts +113 -0
  34. package/src/storage/fact.ts +181 -0
  35. package/src/storage/git.ts +185 -0
  36. package/src/storage/store.ts +124 -0
  37. package/src/storage/sync.ts +72 -0
  38. package/src/web/html.ts +44 -0
  39. package/src/web/router.ts +236 -0
  40. package/src/web/session.ts +47 -0
  41. package/src/web/views.ts +245 -0
  42. package/tsconfig.json +21 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,268 @@
1
+ # Krimto
2
+
3
+ > **Krimto — open-source team memory for AI coding agents.** Personal, team, and org knowledge your
4
+ > agents share, in plain markdown you own (git-backed, Apache-2.0). **Try it solo in two minutes, then
5
+ > bring your team.**
6
+
7
+ One shared brain for every agent at your company. Every agent at every team writes facts to one
8
+ place and reads the right slice of it — Alice's preferences override the team's defaults, the team's
9
+ conventions override the org's standards, and every fact carries a paper trail (author, source,
10
+ timestamp, reviewer).
11
+
12
+ > **Where we are:** this is the **v0.2** surface. Here today: the markdown-in-git storage layer, the
13
+ > `user → team → org` hierarchy, hybrid retrieval, server-enforced access, two-way git sync, and the
14
+ > MCP server over **both stdio and HTTP — the HTTP transport has `Bearer` API-key auth and
15
+ > `/health` endpoints**. On the near-term roadmap: a single-Docker image and the web UI. We claim the
16
+ > team-memory position now and fulfil it in the open — see [ROADMAP.md](ROADMAP.md).
17
+
18
+ ## Try it in 2 minutes (solo, no account)
19
+
20
+ 1. **Run it** (data stays in `~/.krimto`):
21
+ ```bash
22
+ docker run -d -p 8080:8080 -v ~/.krimto:/data ghcr.io/krimto-labs/krimto:latest # or, from a clone: pnpm dev
23
+ ```
24
+ 2. **Point Claude Code at it — one line, no key:**
25
+ ```json
26
+ { "mcpServers": { "krimto": { "url": "http://localhost:8080/mcp" } } }
27
+ ```
28
+ (or run `claude mcp add --transport http krimto http://localhost:8080/mcp`)
29
+ 3. Tell your agent: **"remember that our staging DB resets every Sunday."** Then ask in a *new* chat:
30
+ **"what do you know about staging?"** — it remembers.
31
+ 4. Open **http://localhost:8080** to browse. That's your *personal* layer — Krimto's point is the
32
+ **team** layer: restart with `KRIMTO_BOOTSTRAP_ADMIN=you@acme.com` to turn on accounts and invite
33
+ teammates.
34
+
35
+ ## Connect your agent
36
+
37
+ Krimto is one MCP server — point any client at `http://localhost:8080/mcp`. Verified for **Claude Code**
38
+ and **Cursor**:
39
+
40
+ **Claude Code** (local, no key):
41
+
42
+ ```bash
43
+ claude mcp add --transport http krimto http://localhost:8080/mcp
44
+ ```
45
+
46
+ **Cursor** (local, no key) — add to `~/.cursor/mcp.json` and restart Cursor:
47
+
48
+ ```json
49
+ { "mcpServers": { "krimto": { "url": "http://localhost:8080/mcp" } } }
50
+ ```
51
+
52
+ …or one-click: open **http://localhost:8080/ui/connect** and click **Add to Cursor**.
53
+
54
+ **Team mode** (after `KRIMTO_BOOTSTRAP_ADMIN`): connecting needs your API key. The server prints a
55
+ ready-to-paste config (with the key) on boot, and `/ui/connect` shows it too. Add the key as a header:
56
+
57
+ - Claude Code: append `--header "Authorization: Bearer krm_live_…"`
58
+ - Cursor: add `"headers": { "Authorization": "Bearer krm_live_…" }` to the server block
59
+
60
+ Other clients (Codex, Gemini CLI, Copilot, Cline) use the same `url` (plus the `Bearer` header in team
61
+ mode); those are best-effort and not yet individually verified.
62
+
63
+ ### Make it automatic
64
+
65
+ By default your agent uses Krimto only when you ask. To make it recall and save **on its own**, add a
66
+ standing rule to your agent's rules file — Claude Code: `CLAUDE.md`; Cursor: `.cursor/rules/krimto.mdc`;
67
+ Codex: `AGENTS.md`; Gemini CLI: `GEMINI.md`:
68
+
69
+ ```
70
+ # Krimto memory — always use
71
+ - Before a task, call krimto_recall to load what we already know.
72
+ - When I say "remember", or you learn a durable fact, call krimto_write
73
+ (user/me = personal, team/<slug> = shared).
74
+ - Respect precedence: user beats team beats org.
75
+ - Don't save secrets or one-off chatter.
76
+ ```
77
+
78
+ The in-product **Connect** page (`/ui/connect`) shows this same rule with a copy button.
79
+
80
+ ## How it works
81
+
82
+ Three layers, one source of truth:
83
+
84
+ 1. **Storage** — facts are **markdown files in a git repository**. Humans read them, edit them, and
85
+ review them via pull request. Git is the audit log.
86
+ 2. **Index** — a **SQLite + sqlite-vec** hybrid index (BM25 + vector) sits on top for fast semantic
87
+ retrieval, with hierarchical scope precedence applied at ranking time.
88
+ 3. **Access** — an **API server** enforces who can read/write which scope. Folder paths are the data
89
+ model; the server is the access enforcer (filesystem permissions are not RBAC).
90
+
91
+ This hybrid pattern (markdown for storage + index for retrieval + server for access) is the
92
+ verified-successful approach used by Claude Code's CLAUDE.md system, Manus, OpenClaw, and
93
+ [memweave](https://towardsdatascience.com/) (Towards Data Science, April 2026). Krimto's
94
+ differentiator is the storage *choice within* that pattern — human-readable markdown in git — plus
95
+ `user → team → org` hierarchy as the primary primitive.
96
+
97
+ ## Quick start (self-host)
98
+
99
+ ```bash
100
+ git clone https://github.com/krimto-labs/krimto && cd krimto
101
+ pnpm install
102
+ ```
103
+
104
+ Facts live as markdown files under `KRIMTO_DATA` (default `~/.krimto/`) — a folder you can open in any
105
+ editor and version with git. Run Krimto with `pnpm` (Options A/B) or in **Docker** (Option C).
106
+
107
+ ### Option A — local, over stdio (no auth)
108
+
109
+ For a single developer on one machine. **Fastest path — no clone, no Docker** (Claude Code shown):
110
+
111
+ ```bash
112
+ claude mcp add krimto -- npx -y @krimto-labs/krimto
113
+ ```
114
+
115
+ …or the config-file form any stdio MCP client accepts (Cursor, Codex CLI, Gemini CLI, Copilot,
116
+ OpenClaw, Cline use the same shape):
117
+
118
+ ```json
119
+ {
120
+ "mcpServers": {
121
+ "krimto": {
122
+ "command": "npx",
123
+ "args": ["-y", "@krimto-labs/krimto"],
124
+ "env": { "KRIMTO_IDENTITY": "you@acme.com" }
125
+ }
126
+ }
127
+ }
128
+ ```
129
+
130
+ The first run downloads dependencies (including `better-sqlite3`, which ships prebuilt binaries), then
131
+ starts the **stdio** server with data in `~/.krimto` (override with `KRIMTO_DATA`). This is the solo
132
+ path; HTTP/team mode uses Docker (Option C) or the server below.
133
+
134
+ From a clone instead of npm, swap the command for `pnpm`:
135
+
136
+ ```json
137
+ {
138
+ "mcpServers": {
139
+ "krimto": {
140
+ "command": "pnpm",
141
+ "args": ["--dir", "/absolute/path/to/krimto", "dev"],
142
+ "env": { "KRIMTO_DATA": "/Users/you/.krimto", "KRIMTO_IDENTITY": "you@acme.com" }
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ `KRIMTO_IDENTITY` is who the agent writes as (fact author + access scope). Stdio mode has **no network
149
+ auth** — run it locally/trusted.
150
+
151
+ ### Option B — over HTTP, with bearer auth (teams)
152
+
153
+ For a shared/networked deployment. Start the HTTP server; the first run prints an admin API key once:
154
+
155
+ ```bash
156
+ KRIMTO_HTTP_PORT=8080 KRIMTO_BOOTSTRAP_ADMIN=you@acme.com pnpm dev
157
+ # → "issued admin API key for you@acme.com (shown once): krm_live_…"
158
+ # MCP at http://localhost:8080/mcp ; health at http://localhost:8080/health/ready
159
+ ```
160
+
161
+ Then point your agent at it with that key:
162
+
163
+ ```json
164
+ {
165
+ "mcpServers": {
166
+ "krimto": {
167
+ "url": "http://localhost:8080/mcp",
168
+ "headers": { "Authorization": "Bearer krm_live_..." }
169
+ }
170
+ }
171
+ }
172
+ ```
173
+
174
+ To sync with teammates, set `KRIMTO_GIT_REMOTE` to a git remote you can push/pull over SSH.
175
+
176
+ Optional HTTP knobs (both **off by default**): set `KRIMTO_RATE_LIMIT_PER_MINUTE=<n>` to rate-limit
177
+ each API key on `/mcp` (responses carry `X-RateLimit-*`; over the limit returns `429` with
178
+ `Retry-After`); set `KRIMTO_TELEMETRY_ENDPOINT=<url>` to send anonymous, **bucketed** usage counts
179
+ (version, install id, and size buckets only — never fact content, identities, queries, scopes, or git
180
+ remotes).
181
+
182
+ **Locked out of the admin account?** Restart with `KRIMTO_REISSUE_ADMIN_KEY=you@acme.com` to mint and
183
+ print a fresh admin key. (The web UI also refuses to revoke your last remaining key.)
184
+
185
+ **Multi-instance sync:** Krimto pushes and pulls on the repo's current branch, so give every instance
186
+ the same default branch — e.g. `git config --global init.defaultBranch main` before first run. A
187
+ stuck pull is reported at `/health/ready` under `git_sync` (it never blocks readiness).
188
+
189
+ When an agent saves a personal note, point it at `user/me` — the server resolves that to the caller's
190
+ own scope, so facts never land in an unreadable scope.
191
+
192
+ **Inviting teammates (org admins).** Open `http://localhost:8080/ui/admin` (or use the
193
+ admin REST API: `POST /admin/members`, `POST /admin/keys`, `POST /admin/teams`,
194
+ `PATCH /admin/teams/:slug`, all bearer-authed and org-admin-only) to add members, manage teams, and
195
+ issue/revoke keys — no file edits or restarts. `KRIMTO_BOOTSTRAP_ADMIN` only makes the **first** admin;
196
+ add later admins/members through the admin surface.
197
+
198
+ ### Option C — Docker (HTTP + bearer auth, containerized)
199
+
200
+ Build the image and run it (a published image is coming):
201
+
202
+ ```bash
203
+ docker build -t krimto .
204
+ docker run -d --name krimto -p 8080:8080 \
205
+ -e KRIMTO_BOOTSTRAP_ADMIN=you@acme.com \
206
+ -v ~/.krimto:/data \
207
+ krimto
208
+ docker logs krimto | grep "admin API key" # the key is printed once
209
+ ```
210
+
211
+ The container serves MCP at `http://localhost:8080/mcp` (bearer auth) and health at
212
+ `/health/ready`; facts persist in the mounted `/data` volume. Point your agent at it with the same
213
+ `"url"` + `Bearer` config as Option B.
214
+
215
+ **Pulling a published image (no local build):** pushing a `v*` git tag runs
216
+ [`.github/workflows/docker-publish.yml`](.github/workflows/docker-publish.yml), which publishes the
217
+ image to `ghcr.io/krimto-labs/krimto`. After the first release tag you can skip `docker build` and run
218
+ the published image directly:
219
+
220
+ ```bash
221
+ docker run -d --name krimto -p 8080:8080 \
222
+ -e KRIMTO_BOOTSTRAP_ADMIN=you@acme.com -v ~/.krimto:/data \
223
+ ghcr.io/krimto-labs/krimto:latest
224
+ ```
225
+
226
+ ### Web UI (humans)
227
+
228
+ When the HTTP server is running, open `http://localhost:8080/ui` and **sign in with any Krimto API
229
+ key**. You can browse and search the facts you're allowed to see, open a fact, and manage your own API
230
+ keys (issue / revoke). It reuses the same access control as the MCP tools, so you only ever see facts
231
+ you can read. Set `KRIMTO_SESSION_SECRET` to keep sessions valid across restarts (otherwise a random
232
+ per-boot secret is used). The UI is read-only for facts; editing with a review/approval flow lands in
233
+ v0.3.
234
+
235
+ ## The eight promises (current status)
236
+
237
+ | # | Promise | Status |
238
+ |---|---------|--------|
239
+ | 1 | Markdown-first hybrid storage | ✓ v0.2 |
240
+ | 2 | Hierarchical scope (`user`/`team`/`org`) as primary primitive | ✓ v0.2 |
241
+ | 3 | Cross-vendor SDK (MCP server + per-marketplace plugins) | ✓ MCP server over stdio + HTTP v0.2; native plugins planned |
242
+ | 4 | Attribution baked into every fact | ✓ v0.2 |
243
+ | 5 | Self-hostable, single Docker | ✓ v0.2 — stdio, HTTP, or **Docker** (`docker build` + `docker run`); a published pull-image is next |
244
+ | 6 | Apache-2.0 — fully open, no rug-pull | ✓ |
245
+ | 7 | Web interface for humans, on top of git | ✓ minimal v0.2 (`/ui` — login, browse/search, fact detail, API keys); full UI + PR approval in v0.3 |
246
+ | 8 | Zero-friction migration between self-hosted and Cloud | ⏳ full flow with v1.0 Cloud (`git clone` works today) |
247
+
248
+ ## How Krimto compares
249
+
250
+ Krimto combines three properties that are each uncommon among existing memory tools:
251
+
252
+ - **Apache-2.0** — fully open, with no managed-service restriction. (ByteRover/Cipher is
253
+ source-available under the Elastic License 2.0, which is not OSI-approved open source.)
254
+ - **Markdown-files-in-git storage** — human-readable and reviewable in git. (Hindsight uses
255
+ PostgreSQL; Mem0 uses a vector + graph database.)
256
+ - **`user → team → org` hierarchy as the primary primitive.** (Mem0 organizes by user/session/agent.)
257
+
258
+ Cross-vendor reach — working across Claude Code, Cursor, Codex, Gemini CLI, Copilot, OpenClaw, and
259
+ Cline — is table stakes today, so Krimto ships it but doesn't lead with it.
260
+
261
+ ## Roadmap
262
+
263
+ `v0.2` (teams, today) → `v0.3` (web UI) → `v1.0` (Krimto Cloud). See [ROADMAP.md](ROADMAP.md).
264
+
265
+ ## License
266
+
267
+ [Apache-2.0](LICENSE). The same code is self-hostable by a solo developer, a startup, or an
268
+ enterprise — no tier walls in the open-source distribution.
package/bin/krimto.mjs ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ // npx entry: start the Krimto MCP server over stdio (solo, no Docker / no key).
3
+ // The server source is ESM with extensionless imports, so it is loaded through tsx's
4
+ // programmatic API — the same tsx-at-runtime approach the Dockerfile uses. No build step,
5
+ // no rewrite. With no KRIMTO_HTTP_PORT set, main() takes the stdio path automatically.
6
+ import process from "node:process";
7
+ import { tsImport } from "tsx/esm/api";
8
+
9
+ try {
10
+ const mod = await tsImport("../src/server/index.ts", import.meta.url);
11
+ await mod.main();
12
+ } catch (e) {
13
+ process.stderr.write(`krimto: ${e instanceof Error ? e.message : String(e)}\n`);
14
+ process.exit(1);
15
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@krimto-labs/krimto",
3
+ "version": "0.2.6",
4
+ "description": "Open-source team memory layer for AI agents — markdown files in git, user/team/org hierarchy, cross-vendor MCP server.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "packageManager": "pnpm@11.2.2",
8
+ "engines": {
9
+ "node": ">=20"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/krimto-labs/krimto.git"
14
+ },
15
+ "homepage": "https://krimto.com",
16
+ "bin": {
17
+ "krimto": "bin/krimto.mjs"
18
+ },
19
+ "files": [
20
+ "src",
21
+ "bin",
22
+ "tsconfig.json"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsc -p tsconfig.json",
26
+ "typecheck": "tsc --noEmit",
27
+ "lint": "eslint .",
28
+ "test": "vitest run",
29
+ "test:integration": "vitest run tests/integration --passWithNoTests",
30
+ "dev": "tsx src/server/index.ts",
31
+ "start": "tsx src/server/index.ts"
32
+ },
33
+ "devDependencies": {
34
+ "@eslint/js": "^9.13.0",
35
+ "@types/better-sqlite3": "^7.6.13",
36
+ "@types/express": "^5.0.6",
37
+ "@types/node": "^22.8.0",
38
+ "eslint": "^9.13.0",
39
+ "typescript": "^5.6.0",
40
+ "typescript-eslint": "^8.12.0",
41
+ "vitest": "^2.1.0"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.29.0",
45
+ "better-sqlite3": "^12.10.0",
46
+ "express": "^5.2.1",
47
+ "sqlite-vec": "^0.1.9",
48
+ "tsx": "^4.19.0",
49
+ "ulid": "^3.0.2",
50
+ "yaml": "^2.9.0",
51
+ "zod": "^4.4.3"
52
+ }
53
+ }
File without changes
@@ -0,0 +1,123 @@
1
+ // Gap 06 — Authentication. MCP clients present an API key (bearer token); humans
2
+ // paste an API key into the web UI (/ui), which holds it as a signed-cookie session
3
+ // (real OAuth sign-in is v0.3). Keys are krm_live_/krm_test_ + 32 random base62 chars,
4
+ // shown once, stored only as a hash.
5
+ //
6
+ // Note: API keys are ~190-bit random tokens, not passwords. A fast SHA-256 hash at
7
+ // rest is the correct, performant choice (a per-request memory-hard KDF would add
8
+ // ~100ms to every call). This is an intentional, reasoned divergence from the Build
9
+ // Spec's literal "Argon2", which is meant for low-entropy secrets.
10
+
11
+ import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
12
+ import { promises as fs } from "node:fs";
13
+ import * as path from "node:path";
14
+
15
+ export type KeyEnvironment = "live" | "test";
16
+
17
+ /** OAuth providers supported for the web UI (v0.3). Scaffold only for now. */
18
+ export const OAUTH_PROVIDERS = ["google", "github", "microsoft-entra", "okta", "auth0"] as const;
19
+
20
+ const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
21
+ const KEY_BODY_LENGTH = 32;
22
+
23
+ export interface ApiKeyRecord {
24
+ /** sha256(plaintext key), hex. */
25
+ hash: string;
26
+ identity: string;
27
+ prefix: string;
28
+ created: string;
29
+ label?: string;
30
+ }
31
+
32
+ export interface GeneratedKey {
33
+ /** Plaintext key — shown once, never persisted. */
34
+ key: string;
35
+ record: ApiKeyRecord;
36
+ }
37
+
38
+ function randomBase62(length: number): string {
39
+ const bytes = randomBytes(length);
40
+ let out = "";
41
+ for (let i = 0; i < length; i++) out += BASE62[(bytes[i] ?? 0) % 62];
42
+ return out;
43
+ }
44
+
45
+ export function hashKey(key: string): string {
46
+ return createHash("sha256").update(key).digest("hex");
47
+ }
48
+
49
+ export function generateApiKey(
50
+ identity: string,
51
+ env: KeyEnvironment = "live",
52
+ now: Date = new Date(),
53
+ label?: string,
54
+ ): GeneratedKey {
55
+ const prefix = `krm_${env}_`;
56
+ const key = `${prefix}${randomBase62(KEY_BODY_LENGTH)}`;
57
+ return { key, record: { hash: hashKey(key), identity, prefix, created: now.toISOString(), label } };
58
+ }
59
+
60
+ /** Constant-time comparison of a presented key against a stored hash. */
61
+ export function keyMatches(presented: string, storedHashHex: string): boolean {
62
+ const a = Buffer.from(hashKey(presented), "hex");
63
+ const b = Buffer.from(storedHashHex, "hex");
64
+ return a.length === b.length && timingSafeEqual(a, b);
65
+ }
66
+
67
+ /**
68
+ * File-backed API key store. MUST live outside the facts git repo (it holds secrets,
69
+ * even though only hashes are stored).
70
+ */
71
+ export class ApiKeyStore {
72
+ constructor(private readonly filePath: string) {}
73
+
74
+ private async read(): Promise<ApiKeyRecord[]> {
75
+ try {
76
+ return JSON.parse(await fs.readFile(this.filePath, "utf8")) as ApiKeyRecord[];
77
+ } catch {
78
+ return [];
79
+ }
80
+ }
81
+
82
+ private async write(records: ApiKeyRecord[]): Promise<void> {
83
+ await fs.mkdir(path.dirname(this.filePath), { recursive: true });
84
+ await fs.writeFile(this.filePath, JSON.stringify(records, null, 2), "utf8");
85
+ }
86
+
87
+ /** Issue a new key for an identity. Returns the plaintext once. */
88
+ async issue(identity: string, env: KeyEnvironment = "live", label?: string): Promise<GeneratedKey> {
89
+ const generated = generateApiKey(identity, env, new Date(), label);
90
+ const records = await this.read();
91
+ records.push(generated.record);
92
+ await this.write(records);
93
+ return generated;
94
+ }
95
+
96
+ /** Resolve a presented key to its identity, or null if unknown. */
97
+ async resolveIdentity(presentedKey: string): Promise<string | null> {
98
+ for (const record of await this.read()) {
99
+ if (keyMatches(presentedKey, record.hash)) return record.identity;
100
+ }
101
+ return null;
102
+ }
103
+
104
+ /** List keys. Exposes the hash so callers can revoke by id. */
105
+ async list(): Promise<{ hash: string; identity: string; prefix: string; created: string; label?: string }[]> {
106
+ return (await this.read()).map((r) => ({
107
+ hash: r.hash,
108
+ identity: r.identity,
109
+ prefix: r.prefix,
110
+ created: r.created,
111
+ label: r.label,
112
+ }));
113
+ }
114
+
115
+ /** Remove the key with this hash. Returns true if one was removed. */
116
+ async revoke(hash: string): Promise<boolean> {
117
+ const records = await this.read();
118
+ const next = records.filter((r) => r.hash !== hash);
119
+ if (next.length === records.length) return false;
120
+ await this.write(next);
121
+ return true;
122
+ }
123
+ }