@nxuss/lemma 1.10.0 → 1.12.0

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 (114) hide show
  1. package/README.md +92 -819
  2. package/dist/cjs/cli/lemma-proxy.d.ts.map +1 -1
  3. package/dist/cjs/cli/lemma-proxy.js +21 -2
  4. package/dist/cjs/cli/lemma-proxy.js.map +1 -1
  5. package/dist/cjs/infra/mcp-tools.d.ts +7 -0
  6. package/dist/cjs/infra/mcp-tools.d.ts.map +1 -1
  7. package/dist/cjs/infra/mcp-tools.js +22 -0
  8. package/dist/cjs/infra/mcp-tools.js.map +1 -1
  9. package/dist/cjs/mcp/index.js +32 -7
  10. package/dist/cjs/mcp/index.js.map +1 -1
  11. package/dist/cjs/mcp/prompts.d.ts +1 -0
  12. package/dist/cjs/mcp/prompts.d.ts.map +1 -1
  13. package/dist/cjs/mcp/prompts.js +98 -0
  14. package/dist/cjs/mcp/prompts.js.map +1 -1
  15. package/dist/cjs/mcp/resources.d.ts +2 -0
  16. package/dist/cjs/mcp/resources.d.ts.map +1 -1
  17. package/dist/cjs/mcp/resources.js +26 -0
  18. package/dist/cjs/mcp/resources.js.map +1 -1
  19. package/dist/cjs/mcp/tool-profiles.d.ts.map +1 -1
  20. package/dist/cjs/mcp/tool-profiles.js +64 -45
  21. package/dist/cjs/mcp/tool-profiles.js.map +1 -1
  22. package/dist/cjs/mcp/tools.d.ts.map +1 -1
  23. package/dist/cjs/mcp/tools.js +309 -65
  24. package/dist/cjs/mcp/tools.js.map +1 -1
  25. package/dist/cjs/proxy/Gatekeeper.d.ts +29 -0
  26. package/dist/cjs/proxy/Gatekeeper.d.ts.map +1 -1
  27. package/dist/cjs/proxy/Gatekeeper.js +122 -1
  28. package/dist/cjs/proxy/Gatekeeper.js.map +1 -1
  29. package/dist/cjs/utils/AstSymbolCache.d.ts +29 -0
  30. package/dist/cjs/utils/AstSymbolCache.d.ts.map +1 -0
  31. package/dist/cjs/utils/AstSymbolCache.js +66 -0
  32. package/dist/cjs/utils/AstSymbolCache.js.map +1 -0
  33. package/dist/cjs/utils/ContextSqueezer.d.ts +24 -4
  34. package/dist/cjs/utils/ContextSqueezer.d.ts.map +1 -1
  35. package/dist/cjs/utils/ContextSqueezer.js +32 -3
  36. package/dist/cjs/utils/ContextSqueezer.js.map +1 -1
  37. package/dist/cjs/utils/OutputLedger.d.ts.map +1 -1
  38. package/dist/cjs/utils/OutputLedger.js +20 -2
  39. package/dist/cjs/utils/OutputLedger.js.map +1 -1
  40. package/dist/cjs/utils/ReadWorkspaceCache.d.ts.map +1 -1
  41. package/dist/cjs/utils/ReadWorkspaceCache.js +25 -2
  42. package/dist/cjs/utils/ReadWorkspaceCache.js.map +1 -1
  43. package/dist/cjs/utils/RoiLedger.d.ts +31 -0
  44. package/dist/cjs/utils/RoiLedger.d.ts.map +1 -0
  45. package/dist/cjs/utils/RoiLedger.js +113 -0
  46. package/dist/cjs/utils/RoiLedger.js.map +1 -0
  47. package/dist/cjs/utils/SharedLedgerStore.d.ts +26 -0
  48. package/dist/cjs/utils/SharedLedgerStore.d.ts.map +1 -0
  49. package/dist/cjs/utils/SharedLedgerStore.js +130 -0
  50. package/dist/cjs/utils/SharedLedgerStore.js.map +1 -0
  51. package/dist/cjs/utils/SpeculativeWarmer.d.ts +24 -0
  52. package/dist/cjs/utils/SpeculativeWarmer.d.ts.map +1 -0
  53. package/dist/cjs/utils/SpeculativeWarmer.js +73 -0
  54. package/dist/cjs/utils/SpeculativeWarmer.js.map +1 -0
  55. package/dist/cjs/utils/reportSavings.d.ts.map +1 -1
  56. package/dist/cjs/utils/reportSavings.js +11 -0
  57. package/dist/cjs/utils/reportSavings.js.map +1 -1
  58. package/dist/esm/cli/lemma-proxy.d.ts.map +1 -1
  59. package/dist/esm/cli/lemma-proxy.js +21 -2
  60. package/dist/esm/cli/lemma-proxy.js.map +1 -1
  61. package/dist/esm/infra/mcp-tools.d.ts +7 -0
  62. package/dist/esm/infra/mcp-tools.d.ts.map +1 -1
  63. package/dist/esm/infra/mcp-tools.js +22 -0
  64. package/dist/esm/infra/mcp-tools.js.map +1 -1
  65. package/dist/esm/mcp/index.js +34 -9
  66. package/dist/esm/mcp/index.js.map +1 -1
  67. package/dist/esm/mcp/prompts.d.ts +1 -0
  68. package/dist/esm/mcp/prompts.d.ts.map +1 -1
  69. package/dist/esm/mcp/prompts.js +95 -1
  70. package/dist/esm/mcp/prompts.js.map +1 -1
  71. package/dist/esm/mcp/resources.d.ts +2 -0
  72. package/dist/esm/mcp/resources.d.ts.map +1 -1
  73. package/dist/esm/mcp/resources.js +27 -2
  74. package/dist/esm/mcp/resources.js.map +1 -1
  75. package/dist/esm/mcp/tool-profiles.d.ts.map +1 -1
  76. package/dist/esm/mcp/tool-profiles.js +64 -45
  77. package/dist/esm/mcp/tool-profiles.js.map +1 -1
  78. package/dist/esm/mcp/tools.d.ts.map +1 -1
  79. package/dist/esm/mcp/tools.js +309 -65
  80. package/dist/esm/mcp/tools.js.map +1 -1
  81. package/dist/esm/proxy/Gatekeeper.d.ts +29 -0
  82. package/dist/esm/proxy/Gatekeeper.d.ts.map +1 -1
  83. package/dist/esm/proxy/Gatekeeper.js +120 -0
  84. package/dist/esm/proxy/Gatekeeper.js.map +1 -1
  85. package/dist/esm/utils/AstSymbolCache.d.ts +29 -0
  86. package/dist/esm/utils/AstSymbolCache.d.ts.map +1 -0
  87. package/dist/esm/utils/AstSymbolCache.js +58 -0
  88. package/dist/esm/utils/AstSymbolCache.js.map +1 -0
  89. package/dist/esm/utils/ContextSqueezer.d.ts +24 -4
  90. package/dist/esm/utils/ContextSqueezer.d.ts.map +1 -1
  91. package/dist/esm/utils/ContextSqueezer.js +32 -3
  92. package/dist/esm/utils/ContextSqueezer.js.map +1 -1
  93. package/dist/esm/utils/OutputLedger.d.ts.map +1 -1
  94. package/dist/esm/utils/OutputLedger.js +20 -2
  95. package/dist/esm/utils/OutputLedger.js.map +1 -1
  96. package/dist/esm/utils/ReadWorkspaceCache.d.ts.map +1 -1
  97. package/dist/esm/utils/ReadWorkspaceCache.js +25 -2
  98. package/dist/esm/utils/ReadWorkspaceCache.js.map +1 -1
  99. package/dist/esm/utils/RoiLedger.d.ts +31 -0
  100. package/dist/esm/utils/RoiLedger.d.ts.map +1 -0
  101. package/dist/esm/utils/RoiLedger.js +104 -0
  102. package/dist/esm/utils/RoiLedger.js.map +1 -0
  103. package/dist/esm/utils/SharedLedgerStore.d.ts +26 -0
  104. package/dist/esm/utils/SharedLedgerStore.d.ts.map +1 -0
  105. package/dist/esm/utils/SharedLedgerStore.js +122 -0
  106. package/dist/esm/utils/SharedLedgerStore.js.map +1 -0
  107. package/dist/esm/utils/SpeculativeWarmer.d.ts +24 -0
  108. package/dist/esm/utils/SpeculativeWarmer.d.ts.map +1 -0
  109. package/dist/esm/utils/SpeculativeWarmer.js +66 -0
  110. package/dist/esm/utils/SpeculativeWarmer.js.map +1 -0
  111. package/dist/esm/utils/reportSavings.d.ts.map +1 -1
  112. package/dist/esm/utils/reportSavings.js +11 -0
  113. package/dist/esm/utils/reportSavings.js.map +1 -1
  114. package/package.json +2 -2
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # 🧠 Lemma v1.10.0
1
+ # 🧠 Lemma
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@nxuss/lemma.svg?color=orange&style=flat-square)](https://www.npmjs.com/package/@nxuss/lemma)
4
4
  [![License](https://img.shields.io/npm/l/@nxuss/lemma.svg?color=blue&style=flat-square)](https://github.com/Nxusbets/lemma/blob/main/LICENSE)
@@ -8,439 +8,115 @@
8
8
  [![Tests](https://img.shields.io/badge/tests-378%20passing-00c853?style=flat-square)](https://github.com/Nxusbets/lemma)
9
9
 
10
10
  ```text
11
- __
11
+ __
12
12
  / / ___ ____ ___ ____ ___ ____ _
13
13
  / / / _ \/ __ `__ \/ __ `__ \/ __ `/
14
- / /___/ __/ / / / / / / / / / / /_/ /
15
- /_____/\___/_/ /_/ /_/_/ /_/ /_/\__,_/
14
+ / /___/ __/ / / / / / / / / / / /_/ /
15
+ /_____/\___/_/ /_/ /_/_/ /_/ /_/\__,_/
16
16
  ```
17
17
 
18
18
  > **The Intelligent local-first AI Gateway — Privacy, Performance, Static Code Intelligence, and Infrastructure Command Center for the Agentic Era.**
19
19
 
20
- Lemma is a high-performance orchestration layer that sits between your development environment and LLM providers. It transforms the way you build with AI by providing **Shared Semantic Memory**, **Autonomous Cost Optimization**, **Privacy Guardrails**, **22 Infrastructure Management Tools**, and a suite of **95 MCP tools** including zero-token static code intelligence that runs entirely on your machine with no LLM calls required.
20
+ Lemma sits between your development environment and LLM providers as an MCP server / local proxy.
21
+ It cuts what actually enters the model's context — repeated reads, unfiltered command output, tool
22
+ schemas the project can't use — while keeping every answer verifiable: a cache hit is disclosed as
23
+ a cache hit, a compressed file is never what the user sees, and a savings number always traces back
24
+ to an auditable ledger, never an estimate.
21
25
 
22
- Since v1.7.0 those 95 tools are all registered, but only the ones your project can actually use
23
- are advertised to the model each turn. The rest stay one `lemma_toolbox` call away. See
24
- [Tool profiles](#-tool-profiles).
26
+ ## 🚀 Quick start
25
27
 
26
- ---
27
-
28
- ## 📋 Changelog
29
-
30
- ### v1.10.0 — Repeated output stops being re-sent, and a stale memory can't hide behind a fresh one *(NEW)*
31
-
32
- Two separate problems, same root cause: Lemma was treating an answer as one indivisible blob,
33
- so any change anywhere forced either "resend everything" or "trust nothing."
34
-
35
- | Change | What it does | Why it matters |
36
- | :--- | :--- | :--- |
37
- | **Output dedup across the board** | `run_workspace_command`, `search_workspace`, the dependency graph, and `test_oracle` now return `IDENTICAL: ... (call #N)` or a diff instead of the same payload again. | Re-running the same command/search mid-session (common in an edit/verify loop) used to re-send the full output every time. |
38
- | **`read_workspace_file` in delta mode** | Re-reading a file that changed since the last read now returns `CHANGED: N hunks +a/-b` when the diff is under 50% of the file, instead of the whole file. | The read cache already tracked what was "unchanged"; it had no answer for "changed a little." |
39
- | **`affected_tests`** *(new tool)* | Given changed files, walks the dependency graph (memoized by file fingerprint) and returns only the tests that could actually be affected. | Replaces full-suite reruns — the single largest context sink in an edit/verify loop — with a scoped list. |
40
- | **Local prefilter for `search_workspace`** *(opt-in, `LEMMA_LOCAL_PREFILTER=1`)* | Ranks candidate files with a local Ollama model before they're sent, instead of after. Fails open on any error. | Search stays cheap even when it can't distinguish "roughly relevant" from "exactly what was asked" purely by text match. |
41
- | **Claim-level freshness in The Brain** | `store_memory` accepts `claims: [{text, filePaths?, symbols?}]` — a response with several independent statements can now go stale one claim at a time instead of all-or-nothing. `search_memory` reports which claims are still ✓ fresh and which are ✗ stale. | Symbol-level freshness (v1.8.0) already stopped an unrelated edit in the same file from staling a memory. This is the same idea one level up: an unrelated *claim* in the same memory shouldn't stale the ones still true. |
42
-
43
- Both dedup and delta mode share one invariant, unchanged from before: a compressed or
44
- withheld payload is only ever a stand-in for content the model already received in this
45
- session. Nothing is ever hidden that wasn't sent first.
46
-
47
- **378 tests passing** (up from 333), including coverage for partial claim invalidation and
48
- that entries written before `claims` existed keep working with no migration step.
49
-
50
- ### v1.9.0 — The tools stop fighting the agent using them
51
-
52
- Lemma's savings only count if the agent actually uses the tools. Five defects were pushing it back
53
- to its native tools instead — which means the file gets read twice, and Lemma's overhead is charged
54
- for nothing. Each one below was found by driving the tools as a consumer, not by reading the code.
55
-
56
- | Change | What it does | Why it matters |
57
- | :--- | :--- | :--- |
58
- | **Real line numbers in `read_workspace_file`** | Every line carries its true line number in the original file, mapped through compression rather than renumbered. Squeezer markers get a blank gutter instead of borrowing a neighbour's number. | A compressed read could not be cited (`file.ts:120`) or edited from, so the agent re-read the file with a native tool — paying for it twice and cancelling the squeeze. |
59
- | **`offset` / `limit`** | Read a line range of a large file, numbered from the range start. | Whole-file reads were the only option, on files where a 30-line window was the actual need. |
60
- | **Imports are named, not just counted** | `// [Lemma Squeezer: Squeezed 2 import/dependency lines: fs, path]` | "Squeezed 3 import lines" made *"is this module already imported?"* unanswerable without a full re-read. |
61
- | **`run_workspace_command` timeout: 15s → 120s, configurable to 600s** | `timeoutMs` parameter. | 15s is below the runtime of a real `npm test` or `tsc --noEmit` — the exact commands the output distiller exists for. The tool always timed out, so it was never used. |
62
- | **Timed-out commands keep their output** | Partial stdout/stderr is distilled and returned with a truncation notice. | The old path discarded everything on timeout, and the partial output is normally where the failure is. |
63
- | **Allowlist covers real toolchains** | `python`, `pytest`, `cargo`, `go`, `make`, `rg`, `sed`, `awk`, `docker`, `kubectl`, `gh` and more. Still deny-by-default. | A blocked command is not a command prevented — it is a refused round-trip followed by the same command run through an unrestricted shell, outside Lemma's view. |
64
- | **The read cache stops withholding unsent content** | The dedup key now includes the view (range, numbering, compact mode), not just the path. | Reading lines 1-50 then 51-100 returned `UNCHANGED` for content that had **never been sent**. This was data loss, not just friction. |
65
- | **`UNCHANGED` carries a symbol outline** | Instead of a bare hash, the marker lists the file's symbols and their lines. | *"Reuse your existing copy"* assumes the agent still has it — but its context gets compacted as a session grows, and the server has no way to know. |
66
- | **Free sessions stop paying for tools they can't run** | `resolveToolSurface` takes an entitlement check; Pro-gated tools are no longer advertised without a license. They stay registered and discoverable via `lemma_toolbox`. | A free session advertised the full core surface — read, search, patch, run, AST — and refused 14 of those 20 at call time, charging ~3k tokens per turn for the privilege. |
67
- | **TURBOMODE prompt: ~1,700 → ~894 tokens** | Rule 3 no longer contradicts rule 0. Rationale written for human readers moved into source comments. | *"NEVER read files blindly, always call get_ast_hologram first"* told the model to spend a round-trip to save a read that was often cheaper than the round-trip. |
68
-
69
- **Safety net for the new gutter:** `apply_workspace_patch` strips a line-number prefix from a search
70
- block, but only when *every* non-empty line carries one. A lone `1| ` inside real content (a markdown
71
- table) is left alone. Both cases are covered by tests.
72
-
73
- Line numbers are exact rather than approximate because of what compression actually does: it only
74
- *drops* whole lines and normalizes whitespace *within* a line — it never reorders, merges or splits
75
- them. A line that cannot be located reports no number rather than a wrong one, and does not
76
- desynchronise the lines after it.
77
-
78
- **333 tests passing** (up from 309), including a guard that fails the build if a prompt trim removes
79
- one of the correctness disclosures. It caught a real regression during this work.
80
-
81
- ### v1.8.1 — Two correctness fixes: secret scrubbing and patch data loss
82
-
83
- An audit of the tools with no test coverage turned up two bugs where the tool looked done but
84
- silently produced wrong output.
85
-
86
- - **`apply_workspace_patch` could corrupt a line.** The exact-match strategy computed
87
- `startLine`/`endLine` from a raw substring `indexOf`, but the handler always spliced by whole
88
- line. A search block that was a *fragment* of a line (not the entire line) collapsed
89
- `startLine === endLine`, and the splice replaced the entire line with just the replacement —
90
- discarding everything else on it. Exact matches now splice by character offset;
91
- whitespace-normalized/indent-anchored/fuzzy matches (already full-line windows) are unaffected.
92
- - **The privacy scrubber only recognized 3 generic patterns.** Default patterns covered
93
- `API_KEY`/`EMAIL`/`Bearer ...` shapes only — vendor-specific secrets (Stripe, AWS, GitHub,
94
- Google, Slack, JWTs, PEM private-key blocks) and custom-named secrets (e.g. a project's own
95
- `_SALT` or `_WEBHOOK_SECRET` env var) passed through unmasked. Also, a project's custom
96
- `lemma.config.json` patterns silently *replaced* the defaults instead of adding to them, so
97
- defining one narrow pattern dropped coverage for everything else. Added vendor-specific
98
- patterns plus a generic `ENV_SECRET` catch-all keyed on variable-name conventions, and custom
99
- patterns now augment the defaults by default (`replaceDefaults: true` opts into full override).
100
-
101
- ### v1.8.0 — The Brain learns from project history, not just what it's told *(NEW)*
102
-
103
- Every memory in The Brain used to depend on the assistant remembering to call `store_memory`. If
104
- nobody called it, the Brain knew nothing about work that already happened.
105
-
106
- | Change | What it does | Why it matters |
107
- | :--- | :--- | :--- |
108
- | **`lemma-brain-ingest`** *(new CLI)* | Feeds The Brain from git commits and `CHANGELOG.md` — no assistant call needed. Incremental via a marker file, safe to wire to `post-commit`. | The Brain stops depending on the model remembering to save anything. |
109
- | **Checkpoints now feed The Brain** | `saveCheckpoint()` indexes any checkpoint with real content into the same Brain `search_memory` reads. | Decisions and bugs recorded in a checkpoint used to be invisible to search. |
110
- | **`get_project_history`** *(new tool)* | Merges recent commits, checkpoints, and Brain memories for the current project into one call. | Answers "what have we done here" without three separate lookups. |
111
- | **Outcome tagging** | `store_memory` accepts `outcome: 'failed'`; search surfaces it as a warning, not a suggestion. | A dead end is now as memorable as a fix. |
112
- | **Symbol-level freshness** | `store_memory` accepts `symbols: [{filePath, symbolName}]` — freshness is judged by that function's own source, not the whole file. | An unrelated edit elsewhere in the file no longer stales the memory out. |
113
-
114
- **PR review memory was silently going nowhere.** `BrainBridge` talked to the proxy's
115
- `/api/search`/`/api/memory/store`, both backed by ChromaDB + a local Ollama server on `:11434` —
116
- the exact stack TheBrainV2 replaced in 1.0.0. Whenever Ollama wasn't running (the common case
117
- now), every call failed inside a `try/catch` and returned empty. It now reads/writes `TheBrainV2`
118
- directly, so PR review and interactive coding share one memory instead of two disconnected ones.
119
-
120
- **Two projects could quietly share — or split — memories.** `deriveProjectId` hashed the
121
- project path without resolving symlinks; on macOS `process.cwd()` and an `os.tmpdir()`-built path
122
- can report different strings for the same directory, hashing to two different project scopes. It
123
- now resolves via `fs.realpathSync` first.
124
-
125
- **Spanish text was mangled before it reached the index.** `tokenize()` used `\w` to strip
126
- punctuation, which doesn't match accented letters — "Cómo" became "mo", "diseño" became "dise",
127
- and the same word typed without its accent tokenized completely differently. `tokenize()` now
128
- normalizes diacritics first, and gained an additive English/Spanish stemmer and Spanish stopwords.
129
-
130
- **`token_budget` reported a multiplier no ledger backed.** It fetched a proxy route that doesn't
131
- exist, silently fell back to an uncosted estimate, and reported a bigger number than the
132
- session's own auditable ledger would support. It now reads the real `SavingsLedger` net position
133
- (`/api/savings-breakdown`) or says plainly there's nothing to report if the proxy isn't running.
134
-
135
- ### v1.7.0 — The cost of being connected
136
-
137
- Every tool schema Lemma advertises goes into the model's system prompt and is **re-sent on every
138
- request of the session** — including schemas for tools the project can never use. On this repo that
139
- was ~13,950 tokens per turn before Lemma saved anything.
140
-
141
- | Change | What it does | Why it matters |
142
- | :--- | :--- | :--- |
143
- | **Project-scoped tool surface** | Core tools are always advertised; situational groups (infrastructure, review) only when the repo shows evidence they apply. `mcp.toolProfile` accepts `auto`, `core`, or `full`. | ~3,420 tokens of schemas per turn instead of ~11,600. |
144
- | **`lemma_toolbox`** *(new)* | Lists tools whose schemas were withheld, returns any tool's schema, and invokes it. | A withheld schema is a deferred cost, never a lost capability. |
145
- | **Leaner TURBOMODE prompt** | ~2,340 → ~1,700 tokens. Instructions for tools the session doesn't advertise are gone; every correctness rule stays, enforced by tests. | The prompt stops paying for advice the model can't act on directly. |
146
- | **Overhead in `token_budget`** | Reports profile, advertised vs. hidden counts, active groups, and the real schema token cost. | The fixed cost is visible instead of assumed. |
147
-
148
- **Total fixed cost per turn on this repo: ~5,120 tokens, down from ~13,950.**
149
-
150
- **The Brain reported cache hits that never happened.** Duplicate detection runs an internal search
151
- before storing a memory, and that search shared the counters behind the reported hit rate — while
152
- searching with a minimum similarity of 0, so it matched nearly every time. Every store inflated the
153
- session hit rate and bumped an unrelated entry's hit counter. Internal lookups no longer count.
154
- **Reported hit rates will be lower after upgrading; the lower number is the correct one.**
155
-
156
- **Three features silently did nothing.** `get_telepathic_hints`, `auto_context_bundle`, and
157
- `test_autofix_interceptor` read prior knowledge from `<project>/.lemma/memory/` — a directory no
158
- code path writes. They returned empty in every project while the Brain held the answers. All three
159
- now query the Brain directly.
160
-
161
- **Also in this release:**
162
-
163
- - **Memories are scoped by project** via a `projectId` derived from the git remote. Entries stored
164
- before this release stay visible everywhere rather than disappearing.
165
- - **Brain entries are ~38% smaller** — `terms` duplicated `Object.keys(termFreq)` and is now
166
- rebuilt on load instead of stored. Existing files are read unchanged.
167
- - **`get_project_onboarding` works without the proxy**, falling back to a locally derived map
168
- instead of returning an error on the first call of the session.
169
- - **`lemma-checkpoint`** *(new CLI)* captures a checkpoint from repository state, so it no longer
170
- depends on the assistant remembering to call the tool. See [Session checkpoints](#-session-checkpoints).
171
- - **Removed the `lemma-autopilot` prompt** — it told the model to call tools unconditionally, the
172
- opposite of the net-savings accounting added in v1.6.0. `lemma-turbomode` is the supported prompt.
173
-
174
- ---
175
-
176
- ### v1.6.0 — The savings ledger can now report a loss
177
-
178
- Every release up to this one measured only what Lemma **saved**. That is single-entry bookkeeping:
179
- a number that can only go up is not evidence of anything, because the ledger had no way to express
180
- the outcome *"this session cost more than it returned."* Meanwhile Lemma's own overhead — the
181
- TURBOMODE prompt and 93 tool schemas injected into the model's system prompt, plus every tool
182
- result that lands in context — was real spend that appeared nowhere.
183
-
184
- | Change | What it does | Why it matters |
185
- | :--- | :--- | :--- |
186
- | **Cost side of the ledger** | Records `mcpInstructions` (prompt + all tool schemas, charged **once at MCP connect** — ~13,700 tokens on this repo), `toolResult` (charged on **every** call, including ones that also report a saving), and `cacheMiss`. | A session now starts visibly underwater and has to earn its way out, instead of starting at zero and only ever climbing. |
187
- | **Net position** | `getSnapshot()` returns `net.netTokens`, `net.netCost`, and `net.ratio` (saved ÷ spent). The terminal summary prints **`NET COST`** instead of `NET SAVED` when the ratio drops below 1.0. | The report is falsifiable. If Lemma isn't paying for itself, it says so. |
188
- | **`POST /api/cost-record`** *(new)* | Counterpart to `/api/savings-record`, so out-of-process callers (MCP server, CLI) can charge the ledger. Unknown sources are rejected with a 400. | Costs incurred outside the proxy were previously unrecordable. |
189
- | **Versioned ledger file** | `_version: 2`. Savings stay top-level so pre-v2 readers keep working; costs are additive under `_costs`. A v1 ledger loads with zeroed costs rather than failing. | No migration step, no data loss on upgrade. |
190
-
191
- **Three ways the old numbers were wrong**, now fixed:
192
-
193
- - **Cache hits were credited a hardcoded 2,000 tokens** — every semantic, synthesized, and cloud
194
- hit reported the same invented figure regardless of what was actually served. Savings are now
195
- measured from the cached payload that replaced the LLM call. The 2,000 placeholder survives only
196
- in `stats.json` for dashboard continuity and is explicitly **barred from the ledger**: a guess
197
- must not become part of a net-position claim.
198
- - **`pruneHistoryMessages` counted chars as tokens**, inflating history-prune savings ~4x. It now
199
- converts with the same `chars / 4` heuristic used everywhere else.
200
- - **A cache *miss* is not charged.** The lookup is local, so a miss costs latency, not tokens.
201
- Charging it an invented figure would repeat the exact error this release exists to correct.
202
-
203
- **Also fixed**: `reportSessionOverhead()` ran *after* `await trySamplingContext()`, which blocks on
204
- a `sampling/createMessage` round-trip that clients without sampling support never answer — so the
205
- overhead charge was stalled until the SDK timeout, or dropped entirely. It now runs first.
206
-
207
- **TURBOMODE prompt rewritten** at the top: it no longer promises to "multiply your LLM membership
208
- 50x" or tell the model to poll `token_budget` every 5 turns (a scheduled call that produces a
209
- report instead of work, and costs tokens each time). It now states the real goal — reduce what
210
- enters context without costing a correct answer — and warns that a tool call which saves less than
211
- its own round-trip is a net loss.
212
-
213
- ---
214
-
215
- ### v1.5.0 — Command output stops being the biggest unoptimized token sink
216
-
217
- `run_workspace_command` returned raw stdout/stderr in full — a failing `npm test` put thousands of
218
- lines into context to communicate three broken assertions. Long output is now distilled by
219
- deterministic per-format parsers (no LLM summarization: a summarizer that invents a test name is
220
- worse than the dump it replaced).
221
-
222
- | Format | What survives distillation |
223
- | :--- | :--- |
224
- | jest / vitest | Failing test titles, assertion reason and diff, project-local source location. Code frames and `node_modules` stack frames dropped. |
225
- | tsc | Grouped by file; a repeated diagnostic printed once with its positions (`TS2322 ×40 … at 1:7, 2:7, …`) instead of forty identical lines. |
226
- | eslint (stylish) | Grouped by file with a rule-frequency header, capped per file. |
227
- | anything else | Head, tail, and the error/failure lines from the middle, each with its line number, plus an explicit count of what was withheld. |
228
-
229
- Measured on this repo: a 30-failure jest run went from 32,324 → 7,183 chars (78% withheld); a
230
- 65-error `tsc --noEmit` from 5,597 → 527 (91%).
231
-
232
- **Lossless, not lossy.** The complete output is written to disk *before* anything is trimmed and
233
- the reply carries a handle; the footer always states how much was withheld. `output_region` *(new
234
- tool)* retrieves stored output verbatim — the whole run, one named section (a failing test title or
235
- file path), or a line range. Small outputs pass through untouched with no handle.
236
-
237
- **Also fixed**: stderr was discarded on success. `execSync` leaves stderr attached to the parent
238
- unless `stdio` is overridden, so a *passing* jest or tsc run — both report on stderr — returned an
239
- empty "Output:". Switched to `spawnSync`, which also raises the output limit to 20MB.
28
+ ```bash
29
+ npm install -g @nxuss/lemma
30
+ lemma init # auto-configures MCP for your IDE
31
+ lemma start # gateway + dashboard on http://localhost:8081
32
+ ```
240
33
 
241
34
  ---
242
35
 
243
- ### v1.4.0 Correctness-first patching, search, and memory freshness
36
+ ## What Lemma actually does
244
37
 
245
- An audit of the everyday MCP path read a file, search the workspace, patch it, remember the
246
- answer found the same failure mode repeating: a tool that looked done but silently degraded
247
- correctness or wasted tokens the moment reality diverged from the happy path. This release fixes
248
- that path end to end.
38
+ - **Shared Semantic Memory ("The Brain")** — a zero-dependency local index (BM25 + Jaccard, no
39
+ ChromaDB/Ollama required) that persists solutions, fixes, and decisions across every project and
40
+ every session, with claim- and symbol-level freshness so a stale answer can't hide behind a fresh one.
41
+ - **Verifiable caching, not marketing numbers** — `state_hash_cache` only hits when the files an
42
+ answer depends on are byte-identical; `token_receipt` gives a real per-session breakdown of how
43
+ each answer was produced instead of an invented "% saved."
44
+ - **Privacy Firewall** — API keys, credentials, and PII are scrubbed automatically from every file
45
+ read and workspace search, before anything leaves your machine.
46
+ - **Zero-token static intelligence** — dependency graphs, entropy/coupling/risk scores, and an AST
47
+ symbol index, computed locally with the TypeScript Compiler API. No LLM calls, no tokens.
48
+ - **Command output distillation** — a failing `npm test`/`tsc` run is parsed by deterministic
49
+ per-format rules (jest, tsc, eslint) down to the failures that matter; the full output is never
50
+ lost, just stored and retrievable on demand.
51
+ - **Surgical, AST-based patching** — `surgical_ast_insert` and `refactor` edit or rename by
52
+ compiler-verified AST location instead of asking the model to output a full-file rewrite.
53
+ - **Infrastructure Command Center** — 22 free tools for Jenkins, OKD/OpenShift, and Terraform:
54
+ discover, connect, deploy, diagnose, and detect drift, all via MCP.
55
+ - **Scoped tool surface** — of the 96 registered tools, only the ones your project shows evidence
56
+ of needing are advertised to the model each turn; the rest stay one `lemma_toolbox` call away.
249
57
 
250
- | Tool | What changed | Why |
251
- | :--- | :--- | :--- |
252
- | `apply_workspace_patch` | Cascading match: exact → whitespace-normalized → indent-anchored → fuzzy (similarity-scored, with an anti-tie margin). On total failure, the error now includes a line-diff against the closest candidate block instead of a generic "not found". | A patch built from a `read_workspace_file(compact:true)` view (comments/imports stripped, whitespace collapsed) could never byte-match the file on disk — a guaranteed failure on the most common read→edit flow, forcing an expensive full re-read every time. |
253
- | `search_workspace` | Respects `.gitignore`, skips binaries and files over 500KB, supports comma-separated multi-extension filters, caps results with `maxResults`, and groups matches by file (capped per file) instead of one repeated-path line per hit. Code files (`.ts/.tsx/.js/.jsx`) get symbol-level grouping — matches inside the same function/class collapse into one entry with its signature and full line list instead of raw duplicate lines. Repeating an identical query while the workspace is unchanged (tracked via a cheap mtime/size fingerprint, no content re-reads) returns the cached result instantly. | A single broad query could read 300+ files (2.6MB+) unfiltered and return 15,000+ tokens of flat, path-repeated text — often more expensive than just reading the files directly. |
254
- | `read_workspace_file` | Tracks the content hash last sent for each `(file, compact)` pair for the life of the MCP session. Re-reading an unchanged file returns a short `UNCHANGED` marker instead of the full content again; `force:true` bypasses it. | Re-reading the same file to verify an edit — one of the most common steps in a multi-turn coding session — was resending the full file every time, even when nothing had changed since the last read. |
255
- | `store_memory` / `search_memory` | `store_memory` accepts an optional `filePaths` array and records a sha256 per file. `search_memory` now splits results into **fresh** (safe to reuse) and **stale** (a tracked file changed since it was stored) — a stale hit is never returned as if it were current. | The Brain's semantic match (BM25 + Jaccard) is intentionally fuzzy so differently-phrased questions still hit — but with no invalidation, a fuzzy hit could resurface a stale answer about code that had since changed, with no signal that it was stale. |
256
-
257
- **Net effect**: the four tools an agent reaches for by default — read, search, patch, remember —
258
- now fail closed (a diff instead of a dead-end error) and skip redundant work automatically instead
259
- of requiring the calling model to remember to check first.
260
-
261
- ### Files changed
262
- - `src/utils/PatchMatcher.ts` *(new)* — cascading match strategies + line-diff generator
263
- - `src/utils/WorkspaceSearch.ts` *(new)* — gitignore-aware, capped, grouped search
264
- - `src/utils/StructuralSearch.ts` *(new)* — AST-based symbol grouping for code file matches
265
- - `src/utils/SearchCache.ts` *(new)* — session-scoped, fingerprint-invalidated search cache
266
- - `src/utils/ReadWorkspaceCache.ts` *(new)* — session-scoped read-dedup
267
- - `src/subconscious/TheBrainV2.ts` — `fileHashes` on entries, `checkEntryFreshness`, `fresh`/`staleFiles` on search results
268
- - `src/mcp/tools.ts` — wired all of the above into `apply_workspace_patch`, `search_workspace`, `read_workspace_file`, `store_memory`, `search_memory`
58
+ See [`CHANGELOG.md`](CHANGELOG.md) for the full, per-version history.
269
59
 
270
60
  ---
271
61
 
272
- ### v1.3.0 Verifiable Caching
273
-
274
- Two new tools built around a single rule: don't ask the model to trust a similarity score or a
275
- savings estimate — give it something it can actually verify.
276
-
277
- | Tool | Description |
278
- | :--- | :--- |
279
- | `state_hash_cache` | Reasoning cache keyed to the sha256 of the files an answer depends on. A hit only fires when those files are byte-identical to when the answer was cached — changing one line forces a guaranteed MISS, no similarity guessing. |
280
- | `token_receipt` | Per-session auditable ledger of how each answer was produced (exact cache hit, semantic cache hit, file read, fresh reasoning) — a real breakdown instead of a marketing "% saved" number. |
281
-
282
- Also in this release: `smarter_cache`'s match threshold moved from 0.75 → 0.8 to cut down false
283
- hits, `turbosqueeze` no longer touches code shown to the user (internal context only), and file
284
- insertions default to symbol-level `surgical_ast_insert` patches instead of full-file rewrites.
285
-
286
- ### v1.2.0 — Infrastructure Command Center
287
-
288
- **22 new tools, all FREE**, for managing Jenkins, OKD/OpenShift, and Terraform deployments:
62
+ ## 💎 Free vs Pro
289
63
 
290
- #### 🆓 Infrastructure Tools Added in v1.2.0
64
+ 46 of the 96 registered tools work with no license; 49 require Pro. Enforced by one allowlist in
65
+ code (`FREE_TOOLS` in `src/mcp/tools.ts`), not by narrative. A session without a license doesn't
66
+ even advertise the Pro tools — they stay registered and discoverable via `lemma_toolbox`.
291
67
 
292
- | Tool | Category | Description |
68
+ | | Free (46) | Pro (49) |
293
69
  | :--- | :--- | :--- |
294
- | `infra_discover` | Discovery | Auto-detect Jenkins, OKD, and Terraform in the environment |
295
- | `infra_connect` | Discovery | Connect to an infrastructure provider with credentials |
296
- | `infra_status` | Monitoring | Consolidated status of all connected providers |
297
- | `infra_health_check` | Monitoring | Detailed health check with latency and version info |
298
- | `infra_diagnose` | Troubleshooting | Analyze issues and suggest fixes (caches solutions in TheBrain) |
299
- | `infra_analyze_monolith` | Migration | Analyze monolith codebase for microservice migration |
300
- | `infra_suggest_split` | Migration | Suggest microservice split points based on coupling analysis |
301
- | `jenkins_generate_pipeline` | CI/CD | Generate Jenkinsfile (standard or multibranch) |
302
- | `jenkins_trigger_build` | CI/CD | Trigger Jenkins build (semi-automated) |
303
- | `jenkins_build_status` | Monitoring | Get Jenkins build status, duration, and URL |
304
- | `jenkins_logs` | Troubleshooting | Get last 80 lines of Jenkins build console output |
305
- | `okd_generate_manifests` | Deploy | Generate OKD manifests (DC, BC, IS, Route, Service) |
306
- | `okd_apply` | Deploy | Apply OKD manifests (semi-automated with dry-run) |
307
- | `okd_status` | Monitoring | Compact pod/build/route status summary |
308
- | `okd_logs` | Troubleshooting | Get pod logs filtered by severity |
309
- | `okd_events` | Troubleshooting | Recent cluster events for debugging |
310
- | `okd_describe` | Troubleshooting | Describe any OKD resource |
311
- | `okd_route_url` | Deploy | Get external URL for an OKD route |
312
- | `terraform_plan` | IaC | Run terraform plan (returns only changes) |
313
- | `terraform_apply` | IaC | Run terraform apply (semi-automated) |
314
- | `terraform_state_list` | Monitoring | List resources in Terraform state |
315
- | `terraform_drift` | Troubleshooting | Detect configuration drift |
316
-
317
- #### CLI Commands
318
-
319
- ```bash
320
- lemma infra discover # Auto-detect providers
321
- lemma infra connect <provider> # Connect with credentials
322
- lemma infra status # Dashboard of all providers
323
- lemma infra health # Detailed health check
324
- lemma infra deploy jenkins --project <name> # Deploy via Jenkins
325
- lemma infra deploy okd --project <ns> # Deploy via OKD
326
- lemma infra logs <provider> <target> # Get logs
327
- lemma infra diagnose # General diagnosis
328
- lemma infra terraform plan # Terraform plan
329
- lemma infra terraform apply # Terraform apply
330
- lemma infra analyze monolith # Analyze monolith for migration
331
- ```
332
-
333
- #### Configuration
70
+ | **Caching & memory** | `smarter_cache`, `state_hash_cache`, `token_receipt`, `search_memory`, `store_memory`, `token_budget` | `get_telepathic_hints`, `query_hybrid_consensus`, `semantic_dedup_guard`, `local_semantic_autofix` |
71
+ | **Reading & context** | `read_workspace_file`, `scrub_privacy`, `import_tree_context`, `bulk_file_digest`, `auto_context_bundle`, `git_blame_heat`, `type_coverage_report` | `get_ast_hologram`, `smart_file_slice`, `get_symbol_surgical_context`, `diff_only` |
72
+ | **Writing & workspace** | | `write_workspace_file`, `apply_workspace_patch`, `multi_file_patch`, `search_workspace`, `run_workspace_command`, `validate_patch_sandbox`, `surgical_ast_insert` |
73
+ | **Static analysis** | | `entropy_score`, `coupling_radar`, `pattern_fossil`, `precrime_static`, `dead_export_necromancer`, `depgraph`, `refactor`, `ast_flow_visualizer`, `cognitive_map` |
74
+ | **Infrastructure** | All 22: `infra_*`, `jenkins_*`, `okd_*`, `terraform_*` | |
75
+ | **Automation & PR review** | `conversation_checkpoint`, `test_autofix_interceptor`, `prompt_pattern_cache` | `review_diff`, `review_pr`, `pr_status`, `test_oracle`, `auto_heal`, AutoPilot, Silent Patch Watcher |
334
76
 
335
- Add to `lemma.config.json`:
77
+ Get Pro: `lemma activate <key>` → [lemma.nxus.studio/upgrade](https://lemma.nxus.studio/upgrade)
336
78
 
337
- ```json
338
- {
339
- "infra": {
340
- "jenkins": {
341
- "url": "https://jenkins.example.com",
342
- "credentialsId": "github-creds"
343
- },
344
- "okd": {
345
- "server": "https://api.okd.example.com:6443",
346
- "project": "my-namespace",
347
- "route": { "tls": true, "hostname": "app.example.com" }
348
- },
349
- "terraform": {
350
- "backend": "s3",
351
- "bucket": "my-terraform-state",
352
- "region": "us-east-1"
353
- }
354
- }
355
- }
356
- ```
357
-
358
- Or use environment variables: `JENKINS_URL`, `JENKINS_USERNAME`, `JENKINS_API_TOKEN`, `OKD_SERVER`, `OKD_TOKEN`, `OKD_PROJECT`, `TF_BACKEND`, `TF_BUCKET`, `TF_REGION`.
359
-
360
- **Optimized for token savings**: Infrastructure tools use TheBrain caching, compressed responses, lazy loading, and semantic dedup to minimize context usage.
361
-
362
- ---
363
-
364
- ### v1.1.0 — Token Avalanche
365
-
366
- **11 new tools, all FREE**, focused on maximizing token savings without requiring Pro:
367
-
368
- #### 🆓 Free Tools Added in v1.1.0
369
-
370
- | Tool | Token Savings | Description |
371
- | :--- | :--- | :--- |
372
- | `file_fingerprint` | -60-70% re-reads | SHA256 hash cache per file. Returns 'unchanged' when hash matches, skipping full re-reads. |
373
- | `git_blame_heat` | -1000-2000 tok/session | Git blame + risk scoring per line. Identifies hotspots and high-risk authors. Zero LLM cost. |
374
- | `type_coverage_report` | -1000 tok/review | TypeScript type safety score via AST. Reports typed vs untyped declarations, `any` count, score 0-100. |
375
- | `import_tree_context` | -3000 tok/exploration | Bidirectional import graph. Shows what imports what, external deps, reverse dependencies. |
376
- | `read_token_budgeted` | -70-90% file reads | Read file with hard token limit. Returns only most relevant sections via AST-based scoring. |
377
- | `bulk_file_digest` | -80% round-trips | Read N files in one call, return compressed digest. Saves round-trip overhead. |
378
- | `auto_context_bundle` | -75% round-trips | One-call context: content + imports + schema types + Brain hints. Replaces 4-5 separate tool calls. |
379
- | `repeat_guard` | -10-15% output | Jaccard similarity check against recent outputs. Prevents duplicate explanations. |
380
- | `conversation_checkpoint` | -3000-5000 tok/session | Save/load session state to `.lemma/session/`. Prevents re-explaining context across turns. |
381
- | `test_autofix_interceptor` | -5000 tok/debugging | Run tests + search Brain for matching fixes. Returns failures with suggested fixes from past sessions. |
382
- | `prompt_pattern_cache` | -20-30% prompts | Find/store optimized prompt templates. Auto-merges similar patterns. Tracks hit counts. |
383
-
384
- **Updated TURBOMODE prompt** with 6 new automatic behaviors (rules 4b-4d, 8-12).
385
-
386
- #### Other v1.1.0 Changes
387
- - 199 tests passing (28 new test files)
388
- - Zero new npm dependencies
389
- - All new tools are FREE (no Pro license required)
79
+ Full per-tool listing: `lemma_toolbox { "action": "list" }`.
390
80
 
391
81
  ---
392
82
 
393
83
  ## 🎚️ Tool profiles
394
84
 
395
- Every tool schema an MCP server advertises is injected into the model's system prompt and re-sent
396
- on **every request** of the session. Advertising all 95 tools costs ~11,600 tokens per turn — much
397
- of it schemas for tools a given project can never use.
398
-
399
- Lemma advertises a scoped surface instead. Nothing is removed: every tool stays registered and
400
- callable, and `lemma_toolbox` reaches the ones whose schemas were withheld.
401
-
402
- | Profile | Advertises |
403
- | :--- | :--- |
404
- | `auto` *(default)* | Core tools, plus situational groups the repo shows evidence for |
405
- | `core` | Core tools only |
406
- | `full` | Everything, as before v1.7.0 |
85
+ Every advertised tool schema is re-sent on **every request** of the session advertising all 96
86
+ costs ~11,600 tokens/turn. Lemma advertises a scoped surface instead: core tools always, situational
87
+ groups (e.g. infrastructure) only when the repo shows evidence for them. Nothing is removed —
88
+ everything stays registered and reachable via `lemma_toolbox`.
407
89
 
408
90
  ```jsonc
409
91
  // lemma.config.json
410
- { "mcp": { "toolProfile": "full" } } // or set LEMMA_TOOL_PROFILE=full
92
+ { "mcp": { "toolProfile": "full" } } // "auto" (default) | "core" | "full"
411
93
  ```
412
94
 
413
- **Core** covers workspace reading and navigation, the patch/validate write path, AST context,
414
- caching (`state_hash_cache`, `smarter_cache`, `search_memory`, `store_memory`), routing advice, and
415
- the ledger. **Situational groups** are advertised on evidence — the infrastructure group when a
416
- `Jenkinsfile`, `kustomization.yaml`, `.openshift/`, or a `.tf` file is present, or a provider is
417
- already connected.
418
-
419
- Reaching anything else:
420
-
421
95
  ```jsonc
422
96
  lemma_toolbox { "action": "list", "query": "terraform drift" } // what exists
423
97
  lemma_toolbox { "action": "schema", "tool": "terraform_drift" } // its inputs
424
98
  lemma_toolbox { "action": "call", "tool": "terraform_drift", "args": {} }
425
99
  ```
426
100
 
427
- `token_budget` reports the profile in use, advertised vs. hidden counts, and what the advertised
428
- schemas actually cost this session.
101
+ `token_budget` reports the profile in use and what the advertised schemas actually cost this session.
429
102
 
430
103
  ---
431
104
 
432
- ## 💾 Session checkpoints
433
-
434
- `conversation_checkpoint` saves what a session established so the next one doesn't re-derive it —
435
- but it only runs if the assistant remembers to call it at the end, which is not something to build
436
- on. `lemma-checkpoint` derives a checkpoint from repository state instead:
105
+ ## 🛠️ CLI reference
437
106
 
438
- ```bash
439
- lemma-checkpoint [projectRoot] [--summary "text"]
440
- ```
107
+ | Command | Action |
108
+ | :--- | :--- |
109
+ | `lemma init` | Bootstraps config and auto-configures MCP for OpenCode, Claude Desktop, Cursor, Windsurf, Kiro, VS Code. |
110
+ | `lemma start` | Launches proxy, cache engine, and dashboard at `http://localhost:8081`. |
111
+ | `lemma stop` / `lemma status` / `lemma stats` | Stop, health check, and net token/cost report (reports `NET COST` when a session is underwater). |
112
+ | `lemma mcp` | Starts the stdin/stdout MCP server for IDE integration. |
113
+ | `lemma heal` / `lemma autopilot` / `lemma watch` | Diagnose+repair the last crash / toggle autonomous fix-apply / silent patch-only watcher. |
114
+ | `lemma patches` / `lemma apply <id>` / `lemma discard <id>` | List, apply, or discard a pending Silent Patch Watcher fix. |
115
+ | `lemma activate <key>` | Activate a Pro license. |
116
+ | `lemma-checkpoint [projectRoot]` | Derive a session checkpoint from repo state (branch, changed files, commits) with no assistant call. |
117
+ | `lemma-brain-ingest [projectRoot] [--changelog]` | Feed The Brain from git commits and `CHANGELOG.md`, incrementally. |
441
118
 
442
- It records the branch, changed files, and recent commits to `<project>/.lemma/session/`, exits 0
443
- even outside a git repository, and is meant to be wired to your host's session-end event:
119
+ Wire the standalone bins into hooks so memory doesn't depend on the assistant remembering to call a tool:
444
120
 
445
121
  ```jsonc
446
122
  // ~/.claude/settings.json
@@ -448,410 +124,39 @@ even outside a git repository, and is meant to be wired to your host's session-e
448
124
  "command": "lemma-checkpoint \"${CLAUDE_PROJECT_DIR:-$PWD}\"" }] }] } }
449
125
  ```
450
126
 
451
- Decisions made and tasks left pending exist only in the conversation, so an automatic capture
452
- leaves those fields empty rather than inventing them — a checkpoint saved by the assistant stays
453
- the richer record when one exists.
454
-
455
- ---
456
-
457
- ## 🧠 Feeding The Brain from project history
458
-
459
- `store_memory` also depends on the assistant remembering to call it. `lemma-brain-ingest` pulls
460
- memories from sources that already exist and don't need an assistant in the loop:
461
-
462
- ```bash
463
- lemma-brain-ingest [projectRoot] [--max N] [--changelog] [--no-commits]
464
- ```
465
-
466
- - Every git commit (message + files touched) becomes one Brain entry, so `search_memory` and
467
- `get_telepathic_hints` can recall *why* a change happened, not just what the code looks like now.
468
- - `--changelog` also ingests `CHANGELOG.md` (falls back to `docs/CHANGELOG.md`) — one entry per release, parsed
469
- directly, no LLM involved.
470
-
471
- A marker file under `<project>/.lemma/session/` tracks the last commit and changelog version
472
- ingested, so this is safe to run after every commit and safe to run by hand for a one-time
473
- backfill of existing history — both take the same incremental path and never double-store.
474
- Wire it to a post-commit hook to keep it current automatically:
475
-
476
127
  ```bash
477
128
  echo 'lemma-brain-ingest "$(git rev-parse --show-toplevel)" &' >> .git/hooks/post-commit
478
129
  chmod +x .git/hooks/post-commit
479
130
  ```
480
131
 
481
- ---
482
-
483
- ## 💎 Free vs Pro
484
-
485
- Of the 95 registered tools, 46 work with no license and 49 require Pro. This split is enforced by
486
- one allowlist in code (`FREE_TOOLS` in `src/mcp/tools.ts`), not by narrative — if a tool isn't in
487
- that list, it's Pro, regardless of what a description elsewhere implies.
488
-
489
- Since v1.9.0, a session without a license does not *advertise* the Pro tools either. Sending their
490
- schemas every turn only to refuse the call charged roughly 3k tokens per turn for capabilities the
491
- session could not use. They remain registered and discoverable through `lemma_toolbox`, which is
492
- where you find out a capability exists and what unlocks it.
493
-
494
- ### 🆓 Free (46 Tools)
495
-
496
- These tools work **without a Pro license**. Activate them with just `lemma init`:
497
-
498
- | Tool | What It Does |
499
- | :--- | :--- |
500
- | `smarter_cache` | Semantic cache lookup before reasoning from scratch |
501
- | `state_hash_cache` | Reasoning cache keyed to file content hashes — exact invalidation |
502
- | `token_receipt` | Auditable per-session ledger of how each answer was produced |
503
- | `search_memory` | Semantic search across The Brain, all projects |
504
- | `store_memory` | Persist verified solutions/fixes/decisions into The Brain |
505
- | `get_project_history` | Git log + checkpoints + Brain memories in one call |
506
- | `token_budget` | Session token/cost dashboard, including Lemma's own overhead |
507
- | `squeeze_prompt` | Compress code blocks before they enter your own context |
508
- | `turbosqueeze` | Extreme internal-context compression (never shown to the user) |
509
- | `read_workspace_file` | Read a file (or a line range) with auto-compression, privacy scrubbing, and real line numbers |
510
- | `scrub_privacy` | Mask PII, API keys, and secrets from any text block |
511
- | `summarize_long_text` | Summarize via local Ollama, falls back to truncation |
512
- | `lemma_toolbox` | List, inspect, and call tools whose schemas were withheld |
513
- | `file_fingerprint` | File hash cache — avoid re-reads |
514
- | `git_blame_heat` | Git blame + risk scoring |
515
- | `type_coverage_report` | TypeScript type safety score |
516
- | `import_tree_context` | Bidirectional import graph |
517
- | `read_token_budgeted` | Token-budgeted file reader |
518
- | `bulk_file_digest` | Multi-file digest in one call |
519
- | `auto_context_bundle` | Full context bundle per file |
520
- | `repeat_guard` | Duplicate output detector |
521
- | `conversation_checkpoint` | Session state save/load |
522
- | `test_autofix_interceptor` | Test failure → Brain auto-fix |
523
- | `prompt_pattern_cache` | Reusable prompt templates |
524
- | `infra_discover` | Auto-detect Jenkins, OKD, Terraform |
525
- | `infra_connect` | Connect to infrastructure providers |
526
- | `infra_status` | Consolidated infrastructure status |
527
- | `infra_health_check` | Detailed provider health check |
528
- | `infra_diagnose` | Analyze and fix infrastructure issues |
529
- | `infra_analyze_monolith` | Analyze monolith for microservice migration |
530
- | `infra_suggest_split` | Suggest microservice split points |
531
- | `jenkins_generate_pipeline` | Generate Jenkinsfile |
532
- | `jenkins_trigger_build` | Trigger Jenkins builds |
533
- | `jenkins_build_status` | Jenkins build status |
534
- | `jenkins_logs` | Jenkins build logs |
535
- | `okd_generate_manifests` | Generate OKD manifests |
536
- | `okd_apply` | Apply OKD manifests |
537
- | `okd_status` | OKD pod/build/route status |
538
- | `okd_logs` | OKD pod logs |
539
- | `okd_events` | OKD cluster events |
540
- | `okd_describe` | Describe OKD resources |
541
- | `okd_route_url` | Get OKD route URL |
542
- | `terraform_plan` | Terraform plan |
543
- | `terraform_apply` | Terraform apply |
544
- | `terraform_state_list` | List Terraform state resources |
545
- | `terraform_drift` | Detect Terraform drift |
546
-
547
- ### 💎 Pro (49 Tools)
548
-
549
- All remaining tools require a Pro license. Activate with `lemma activate <key>` → [Get Pro](https://lemma.nxus.studio/upgrade)
550
-
551
- | Category | Tools |
552
- | :--- | :--- |
553
- | **AI Proxy** | OpenAI/Anthropic/Gemini proxy, exact-match cache, complexity router |
554
- | **The Brain (advanced)** | `get_telepathic_hints`, `query_hybrid_consensus`, `semantic_dedup_guard`, `local_semantic_autofix` — basic search/store/smarter_cache are Free |
555
- | **Zero-Token Static** | `entropy_score`, `coupling_radar`, `pattern_fossil`, `git_heatmap_risk`, `precrime_static`, `dead_export_necromancer` |
556
- | **Architecture** | `depgraph`, `refactor`, `ast_flow_visualizer`, `imports_skeleton_resolver`, `cognitive_map`, `file_intent_index` |
557
- | **Code Intelligence** | `get_ast_hologram`, `validate_patch_sandbox`, `surgical_ast_insert`, `get_symbol_surgical_context`, `smart_file_slice`, `diff_only` |
558
- | **Workspace writes** | `write_workspace_file`, `create_workspace_file`, `apply_workspace_patch`, `multi_file_patch`, `search_workspace`, `list_workspace_dir`, `run_workspace_command`, `output_region` |
559
- | **Optimization (advanced)** | `wormhole_squeeze`, `compress_context`, `prune_conversation_history` — `turbosqueeze`, `squeeze_prompt`, `token_budget` are Free |
560
- | **PR Review** | `review_diff`, `review_pr`, `pr_status`, `generate_pr_workflow` |
561
- | **Session & Automation** | `test_oracle`, `schema_extract`, `changelog_auto`, `env_snapshot`, `migration_tracer`, `spec_to_stub`, `batch_tool_calls`, `get_routing_advice`, `get_project_onboarding`, `auto_heal`, `semantic_grep` |
562
- | **Automation (background)** | AutoPilot, Auto-Heal, Silent Patch Watcher |
563
-
564
- > **The MCP server itself is Pro.** All 49 Pro tools — the advanced Brain layer, PreCrime, AST
565
- > Hologram, `depgraph`, `refactor`, every workspace-write tool, and every PR review tool — require a
566
- > Pro license. The 46 Free tools above (including all 22 Infrastructure tools and `read_workspace_file`
567
- > with its automatic privacy scrubbing) are accessible without activation.
568
-
569
- ---
570
-
571
- ## ⚡ What's in the Pro MCP
572
-
573
- ### 🏗️ Infrastructure Command Center *(NEW in v1.2.0)*
574
- **Lemma is now your single pane of glass for Jenkins, OKD/OpenShift, and Terraform.** All 22 infrastructure tools are FREE and integrate with TheBrain for intelligent caching of deploy patterns and troubleshooting solutions.
575
-
576
- - **Jenkins**: Generate Jenkinsfiles, trigger builds, check status, get logs — all via MCP
577
- - **OKD/OpenShift**: Generate DeploymentConfig, BuildConfig, ImageStream, Route manifests. Apply with dry-run. Monitor pods, builds, events
578
- - **Terraform**: Plan, apply, list state resources, detect configuration drift
579
- - **Monolith Analysis**: Analyze your codebase for microservice migration — identifies modules, coupling, and suggests split points
580
- - **Token-Optimized**: TheBrain caches successful deploys and troubleshooting patterns. Compressed responses. Lazy provider loading
581
-
582
- ```bash
583
- # Quick start
584
- lemma infra connect jenkins -u https://jenkins.example.com
585
- lemma infra connect okd -u https://api.okd.example.com:6443 -t $OKD_TOKEN
586
- lemma infra status
587
- lemma infra deploy okd -n my-app -i my-image:latest
588
- ```
589
-
590
- ### 🧠 Shared Semantic Memory — The Brain (Zero-Dependency)
591
- Lemma maintains a persistent semantic cache index (`TheBrainV2`) using Okapi BM25 + Jaccard re-ranking and Bloom Filters that runs entirely on your local machine with NO external ML dependencies (no ChromaDB, no Ollama required). Every solution, bug fix, and architecture decision you work through gets stored and semantically indexed globally across all your projects. Future sessions can retrieve this knowledge in milliseconds (<10ms) — saving you thousands of tokens.
592
-
593
- ### 🛡️ Privacy Firewall (Semantic Scrubber)
594
- **Enterprise-Grade Privacy.** Prevents API keys, credentials, and PII from ever leaving your machine. Applied automatically to every file read and workspace search via MCP.
595
-
596
- ### 🔮 PreCrime Static Analyzer — Zero Tokens
597
- **Minority Report for your code.** Combines cyclomatic complexity, git churn history, and module coupling into a composite risk score per file. Predicts which files are most likely to produce a bug before you touch them — using only the TypeScript Compiler API and git log. No LLM. No Ollama. No tokens.
598
-
599
- ### 🕸️ Coupling Radar — Zero Tokens
600
- Builds a full import/export dependency graph of your codebase using the TypeScript Compiler. Detects circular dependencies, god modules (imported by everything), dead islands (no importers), and fan-in/fan-out per module. Essential before any large refactor.
601
-
602
- ### 🧮 Entropy Score — Zero Tokens
603
- Mathematical chaos score (0-100) per file using the TS Compiler API. Measures cyclomatic complexity, nesting depth, `any` ratio, and average function size. Tells you exactly where refactor debt is accumulating.
604
-
605
- ### 🗺️ AST Hologram — Zero Tokens
606
- Scans the workspace and returns a dense JSON index of exported symbols with file paths and line numbers. Lemma now routes this through an internal language adapter layer: TypeScript keeps full compiler-backed behavior, `.NET` uses a native adapter path, and unsupported languages return an explicit fallback index instead of pretending semantic parity.
607
-
608
- ### 📡 `depgraph` — Real-Time Dependency Graph
609
- **Architecture-aware blast radius analysis.** Builds a real-time, bidirectional dependency graph for any file in the workspace using the TypeScript Compiler API — zero LLM calls, zero tokens. Shows exactly what a file imports, what imports it (reverse dependencies), and what symbols it exports.
610
-
611
- ```
612
- 📦 src/services/pantry.ts
613
- ├── importa:
614
- │ ├── src/lib/utils/ingredient-parser.ts → parseIngredientString, normalizeUnit
615
- │ └── src/db/prisma.ts → PrismaClient
616
- ├── es importado por:
617
- │ ├── src/app/actions/generate-recipe.ts
618
- │ └── src/components/PantryWidget.tsx
619
- └── exporta:
620
- ├── applyRecipeDeductions
621
- └── getPantryBalance
622
- ```
623
-
624
- Supports `--depth` (1-5), `--format text|mermaid|json`, `--reverse`, `--circular` (cycle detection), and `--external` (include node_modules).
625
-
626
- ### 🔧 `refactor` — Declarative Codemod Engine
627
- **Multi-file refactoring with surgical precision.** Rename any symbol across the entire workspace or move files updating all importers — using the TypeScript Compiler API for accurate AST-based reference detection. Zero LLM calls.
628
-
629
- **`rename`** — Finds every reference to a symbol (via AST, not text search) and renames it everywhere:
630
- ```bash
631
- # Preview first
632
- lemma refactor --operation rename --from "applyRecipeDeductions" --to "deductPantryIngredients" \
633
- --file src/services/pantry.ts --dryRun
634
-
635
- # Apply with TypeScript verification
636
- lemma refactor --operation rename --from "applyRecipeDeductions" --to "deductPantryIngredients" \
637
- --file src/services/pantry.ts --tscCheck
638
- ```
639
-
640
- **`move`** — Moves a file physically and rewires every import path in the workspace:
641
- ```bash
642
- lemma refactor --operation move \
643
- --from src/lib/validation/recipe.schema.ts \
644
- --to src/lib/schemas/recipe.ts \
645
- --tscCheck
646
- ```
647
-
648
- Supports `--dryRun` (unified diff preview), `--tscCheck` (post-refactor type verification), and `--backup` (`.bak` files).
649
-
650
- ## 🌐 Multi-Language Semantic Runtime
651
-
652
- Lemma now separates universal MCP tools from language-specific semantic tooling.
653
-
654
- | Capability Tier | Meaning |
655
- | :--- | :--- |
656
- | `full` | Native semantic adapter with language-aware guarantees. |
657
- | `partial` | Some language awareness exists, but not full semantic parity. |
658
- | `fallback` | Safe read-only or heuristic response. No semantic safety claim. |
659
- | `unsupported` | Mutation is refused until a real adapter exists. |
660
-
661
- ### Current semantic support
662
-
663
- | Tool | TypeScript / JavaScript | .NET | Python / Go / Java (today) |
664
- | :--- | :--- | :--- | :--- |
665
- | `get_ast_hologram` | `full` | `full` | `fallback` |
666
- | `validate_patch_sandbox` | `full` via `tsc` | `full` via `dotnet build` when CLI is available | `fallback` |
667
- | `depgraph` | `full` | `full` | `fallback` |
668
- | `refactor` | `full` | `unsupported` | `unsupported` |
669
-
670
- Universal tools such as file reads, workspace search, memory, onboarding, prompt compression, and privacy scrubbing remain language-agnostic. Semantic tools keep the same MCP names, but are now routed through adapter and runtime registries internally.
671
-
672
- ### 🚦 Complexity Router
673
- Intelligently evaluates each prompt and routes it to the most cost-effective model. Reserves premium models for complex reasoning, uses smaller models for simple tasks. Slashes your AI bill without sacrificing quality.
674
-
675
- ### ✂️ Context Squeezer & TurboMode
676
- Dynamically squeezes outgoing code payloads, strips comments, collapses whitespace, and compacts JSON. Saves up to 90% on token consumption. Automatically injected via the `lemma-turbomode` system prompt on MCP handshake.
677
-
678
- ### 🛸 Autonomous Workspace Control
679
- Exposes `write_workspace_file`, smart `apply_workspace_patch` (collision-safe search-and-replace), and `run_workspace_command` (with allowlist security) to any IDE via MCP. Any standard chat instantly becomes a fully-featured autonomous multi-file editor.
680
-
681
- ### 🩺 AutoPilot & Auto-Heal
682
- Lemma's background file watcher detects TypeScript compilation errors on every save, parses the error, and calls the auto-heal agent to apply a fix — automatically. When Autopilot succeeds, the fix is stored in The Brain for future sessions.
683
-
684
- ### 🕵️ Silent Patch Watcher
685
- **Magia negra, no invasiva.** Like Autopilot, but **never touches your code**. Lemma watches your project silently, detects TypeScript errors on save, generates fixes, and stores them as patches in `.lemma/patches/`. You review with `lemma patches` and apply with `lemma apply <id>`.
686
-
687
- ```
688
- lemma watch ← starts silently watching src/
689
- [youse save a file with a bug]
690
- 📬 macOS notification ← "Lemma: TS2322 in route.ts:42"
691
- lemma patches ← shows 1 pending fix
692
- lemma apply ts2322-... ← applies the fix
693
- npm run build ← ✅ passes
694
- ```
695
-
696
- ### 🧬 `get_symbol_surgical_context` — Surgical Symbol Context
697
- **Saves up to 90% input tokens.** Instead of reading complete dependency source files, this tool parses your workspace via TS Compiler AST and extracts ONLY the targeted symbol implementation along with the precise function/class signatures of all its direct workspace imports.
698
-
699
- ### ⚙️ `surgical_ast_insert` — AST Surgical Code Injector
700
- **Saves up to 95% output tokens.** Removes the need for the LLM to output massive file diffs or rewrite entire files. The LLM only outputs the exact function snippet, and Lemma compiles it surgically into the class/scope AST at the specified anchor point.
701
-
702
- ### 🩹 `local_semantic_autofix` — Offline Self-Healing
703
- **Resolves compilation/runtime crashes in <15ms with 0 tokens.** When your tests or compilers crash, Lemma queries the global error index in `TheBrainV2`. If a matching traceback fix is found in memory (solved in this or any other repo on your machine), it applies the resolution instantly.
704
-
705
- ### 💰 `generate_executive_roi_report` — Corporate ROI Ledger
706
- Generates a complete executive Markdown/PDF-ready report of total direct API dollars saved, developer hours reclaimed from caching, security masking events, and scalability financial projections for engineering managers.
707
-
708
- ### 🌀 `wormhole_squeeze` — Reversible Code Compression
709
- Compresses your source code using non-colliding mathematical unicode symbols (like `⨃`, `⨂`, `⨁`) and temporary aliases to shrink file sizes by up to 70% while keeping it 100% reversible.
710
-
711
- ### 📐 `smart_file_slice` — Context Slicing
712
- Reads only the relevant lines of a file around a keyword or query, avoiding sending the entire file to the LLM. Saves ~85% of input tokens.
713
-
714
- ### 🧪 `test_oracle` — Smart Test Failure Filter
715
- Executes unit tests locally and returns ONLY the failing test cases with compressed stack traces, keeping successful test logs out of the prompt. Saves ~90% tokens.
716
-
717
- ### 📄 `schema_extract` — High-Level Type Extractor
718
- Extracts TS interfaces, types, Zod schemas, or Prisma schemas via AST, stripping out all execution and implementation code. Saves ~80% tokens.
719
-
720
- ### 📜 `changelog_auto` — Zero-Token conventional changelogs
721
- Generates a conventional commit changelog directly from git history logs with 0 LLM queries.
722
-
723
- ### 🪚 `spec_to_stub` — Spec Mock Stub Creator
724
- Parses interfaces and types to output a mock stub template object configuration using pure AST.
725
-
726
- ### 📋 `env_snapshot` — Env Dependency Capture
727
- Captures node/npm versions, package.json dependencies, and present `.env` keys (hiding private values/credentials) for instant environment onboarding.
728
-
729
- ### 🧭 `migration_tracer` — Prisma Migration Analyst
730
- Traces recent schema modifications (creates, alters, drops) from local Prisma migration files without reading the full SQL code.
731
-
732
- ### 🩹 `multi_file_patch` — Multi-File Search-and-Replace
733
- Applies search-and-replace patches to multiple files in a single call. Eliminates round-trips for multi-file refactoring.
734
-
735
- ### 📁 `file_intent_index` — Codebase Categorizer
736
- Automatically groups workspace files by domain intent (auth, routing, config, schemas) for lightning fast navigation.
737
-
738
- ### 🧠 `cognitive_map` — Auto-Cognitive Knowledge Graph
739
- A persistent, auto-updating structural knowledge graph representing codebase domains, patterns, decisions, and known bugs at `~/.lemma-cache/cog_map.json`.
740
-
741
- ### 🔍 `semantic_grep` — BM25 Concept Search
742
- Token relevance concept searching across your codebase, allowing natural language queries instead of strict substring matches.
743
-
744
- ### 📦 `imports_skeleton_resolver` — Import Signature Mapper
745
- Scans imports inside a file and retrieves exported TypeScript signatures from local dependencies in a unified reference sheet. Saves ~85% reading tokens.
746
-
747
- ### 🎨 `ast_flow_visualizer` — Flowchart Generator
748
- Compiles any TS function's control flow statements (loops, ifs, try-catches) into an interactive visual Mermaid diagram rendered directly in markdown.
749
-
750
- ---
751
-
752
- ## 🚀 Quick Start (Zero Config)
753
-
754
- ```bash
755
- # Install globally
756
- npm install -g @nxuss/lemma
757
-
758
- # Initialize (auto-configures local DB and MCP for your IDEs)
759
- lemma init
760
-
761
- # Start the gateway + dashboard
762
- lemma start
763
- ```
764
-
765
- ---
766
-
767
- ## 🛠️ CLI Reference
768
-
769
- | Command | Action |
770
- | :--- | :--- |
771
- | `lemma init` | Bootstraps config and auto-configures MCP for OpenCode, Claude Desktop, Cursor, Windsurf, Kiro, VS Code. |
772
- | `lemma start` | Launches proxy, cache engine, and dashboard at `http://localhost:8081`. |
773
- | `lemma stop` | Gracefully shuts down the background proxy. |
774
- | `lemma status` | Health of all modules and active connections. |
775
- | `lemma stats` | Real-time token and cost metrics — savings, Lemma's own overhead, and the net position between them. Reports `NET COST` when the session is underwater. |
776
- | `lemma mcp` | Starts the stdin/stdout MCP server for IDE integration. |
777
- | `lemma heal` | Auto-diagnose and repair the latest server crash from live context logs. |
778
- | `lemma autopilot` | Toggle autonomous background watcher mode (auto-applies fixes). |
779
- | `lemma watch` | Silent background watcher — saves patches without touching code. |
780
- | `lemma patches` | List available patches (`--all`, `--pending`). |
781
- | `lemma apply <id>` | Apply a pending fix patch. |
782
- | `lemma discard <id>` | Discard a pending fix patch. |
783
- | `lemma activate <key>` | Activate Pro license for full MCP access. |
784
- | `lemma-checkpoint [projectRoot]` | Standalone bin: derive a session checkpoint from repo state (branch, changed files, recent commits) without an assistant call. See [Session checkpoints](#-session-checkpoints). |
785
- | `lemma-brain-ingest [projectRoot]` | Standalone bin: feed The Brain from git commits and `CHANGELOG.md`, incrementally. See [Feeding The Brain from project history](#-feeding-the-brain-from-project-history). |
786
-
787
- ### Customizing via `lemma.config.json`
132
+ Customize via `lemma.config.json`:
788
133
 
789
134
  ```json
790
135
  {
791
- "system": {
792
- "clipboardWatcher": { "disabled": false }
793
- },
794
- "mcp": {
795
- "allowedCommandPrefixes": ["npm", "git", "tsc", "your-custom-tool"]
796
- }
136
+ "system": { "clipboardWatcher": { "disabled": false } },
137
+ "mcp": { "allowedCommandPrefixes": ["npm", "git", "tsc", "your-custom-tool"] }
797
138
  }
798
139
  ```
799
140
 
800
141
  ---
801
142
 
802
- ## 🔌 MCP Integration
803
-
804
- Add Lemma to any MCP-compatible IDE in seconds:
143
+ ## 🔌 MCP integration
805
144
 
806
- ### OpenCode (Terminal AI)
807
- Just run `lemma init`. Lemma automatically registers its MCP server in your `~/.opencode.json` and injects its autonomous rules so OpenCode works with zero configuration.
808
-
809
- ### Cursor / Windsurf / Kiro / Antigravity
810
- 1. Go to **Settings MCP**
811
- 2. Add new server: **Command** = `lemma mcp`
812
-
813
- ### Claude Desktop
814
- ```json
815
- {
816
- "mcpServers": {
817
- "lemma": {
818
- "command": "npx",
819
- "args": ["-y", "@nxuss/lemma", "mcp"]
820
- }
821
- }
822
- }
823
- ```
145
+ | Client | Setup |
146
+ | :--- | :--- |
147
+ | OpenCode | `lemma init` — registers itself in `~/.opencode.json`, zero config. |
148
+ | Cursor / Windsurf / Kiro / Antigravity | Settings → MCP → add server, command `lemma mcp`. |
149
+ | Claude Desktop | Add to `mcpServers`: `{ "lemma": { "command": "npx", "args": ["-y", "@nxuss/lemma", "mcp"] } }` |
824
150
 
825
- Once connected, your IDE gains access to all **95 MCP tools** (46 Free + 49 Pro — see
826
- [Free vs Pro](#-free-vs-pro) for the full, current split) and Lemma auto-injects the TurboMode
827
- system prompt on handshake. By default only the tools your project shows evidence of needing are
828
- *advertised* each turn see [Tool profiles](#-tool-profiles) but every tool is registered and
829
- reachable via `lemma_toolbox` regardless of profile.
830
-
831
- ### ⚡ TurboMode Auto-Injection
832
-
833
- When connected via `lemma mcp`, Lemma auto-injects its system prompt on handshake. The real,
834
- current prompt (`LEMMA_TURBOMODE_PROMPT` in `src/mcp/prompts.ts`) states the goal — reduce what
835
- enters context without ever costing a correct answer — and enforces it with rules including:
836
-
837
- - A tool call costs tokens too: expect a call to save more than its own round-trip, or skip it.
838
- - `lemma_toolbox` reaches every tool whose schema was withheld from this session — check it
839
- before saying a capability is missing.
840
- - Compression (`turbosqueeze`, `wormhole_squeeze`, `squeeze_prompt`) is for the model's own
841
- context only; the user always gets the real, uncompressed file.
842
- - `smarter_cache` hits must be disclosed as cached, never presented as freshly reasoned, and
843
- re-verified before acting on them.
844
- - `state_hash_cache` (exact file-hash invalidation) is preferred over `smarter_cache` (semantic
845
- similarity) whenever the answer depends on specific files.
846
- - `store_memory` only after a solution is actually verified — an unverified fix stored here
847
- becomes a false cache hit later.
848
- - `get_routing_advice` before assuming a mechanical task needs the biggest available model.
849
- - `surgical_ast_insert` by default for adding to an existing file, instead of rewriting it whole.
850
- - `token_receipt` for "how much did we save," never an invented estimate.
151
+ Once connected, Lemma auto-injects its TurboMode system prompt on handshake states the goal
152
+ (reduce what enters context without ever costing a correct answer) and enforces it: a tool call
153
+ must save more than its own round-trip, `smarter_cache` hits are disclosed as cached and
154
+ re-verified before being acted on, `store_memory` only fires after a solution is verified, and
155
+ compression is always for the model's own context — the user gets the real file.
851
156
 
852
157
  ---
853
158
 
854
- ## 📡 MCP Resources
159
+ ## 📡 MCP resources
855
160
 
856
161
  | Resource URI | Description |
857
162
  | :--- | :--- |
@@ -865,57 +170,25 @@ enters context without ever costing a correct answer — and enforces it with ru
865
170
 
866
171
  ## 🔒 Security
867
172
 
868
- ### Network Binding
869
- By default, Lemma binds only to `127.0.0.1` (localhost). Not network-accessible unless explicitly configured:
870
- ```env
871
- LEMMA_BIND_HOST=0.0.0.0
872
- AUTH_ENABLED=true
873
- AUTH_REQUIRE_API_KEY=true
874
- AUTH_ALLOWED_ORIGINS=https://yourdomain.com
875
- ```
876
-
877
- ### MCP Command Allowlist
878
- `run_workspace_command` only executes commands from an allowlist. It is deny-by-default, but the
879
- defaults cover the toolchains a normal repo builds and tests with — JS/TS (`npm`, `npx`, `pnpm`,
880
- `tsc`, `jest`, `vitest`, `eslint`), Python (`python`, `pytest`, `ruff`), Go, Rust, Ruby, JVM,
881
- `make`, version control (`git`, `gh`), read-only shell utilities (`ls`, `grep`, `rg`, `sed`, `awk`,
882
- `find`), and container/infra CLIs (`docker`, `kubectl`, `terraform`).
173
+ **Network binding.** Binds only to `127.0.0.1` by default — not network-accessible unless you set
174
+ `LEMMA_BIND_HOST=0.0.0.0` and enable `AUTH_ENABLED`/`AUTH_REQUIRE_API_KEY`/`AUTH_ALLOWED_ORIGINS`.
883
175
 
884
- A command missing from this list is not a command prevented: the agent gets a refusal, then runs the
885
- same thing through an unrestricted shell where Lemma can neither distil the output nor account for
886
- it. The list is scoped to keep that from happening for ordinary development work.
887
-
888
- Extend for your project in `lemma.config.json`:
889
- ```json
890
- {
891
- "mcp": {
892
- "allowedCommandPrefixes": ["your-tool", "another-cmd"]
893
- }
894
- }
895
- ```
896
-
897
- See [`.env.security.example`](.env.security.example) for all security-related environment variables.
176
+ **Command allowlist.** `run_workspace_command` is deny-by-default, with defaults covering normal
177
+ JS/TS, Python, Go, Rust, Ruby, JVM, `make`, git/gh, read-only shell utilities, and container/infra
178
+ CLIs. Extend via `lemma.config.json` `mcp.allowedCommandPrefixes`. See
179
+ [`.env.security.example`](.env.security.example) for every security-related env var.
898
180
 
899
181
  ---
900
182
 
901
- ## 🦜 SDK Integrations
183
+ ## 🦜 SDK integrations & proxy mode
902
184
 
903
- ### CrewAI
904
185
  ```typescript
905
186
  import { LemmaCrewAIProvider } from '@nxuss/lemma/crewai';
906
-
907
187
  const crew = new LemmaCrewAIProvider({ agents: [...] });
908
188
  ```
909
189
 
910
- ---
911
-
912
- ## 🔄 Using as a Proxy
913
-
914
- Point any OpenAI-compatible tool to Lemma's local proxy for transparent caching and privacy:
915
-
916
- - **Cursor:** `Settings > Models > OpenAI API > Override Base URL` → `http://localhost:8081/v1`
917
- - **VS Code (Continue):** Set `apiBase` to `http://localhost:8081/v1`
918
- - **Custom apps:** Replace `https://api.openai.com/v1` with `http://localhost:8081/v1`
190
+ Point any OpenAI-compatible tool at `http://localhost:8081/v1` for transparent caching and privacy
191
+ (Cursor: Settings → Models → Override Base URL; VS Code/Continue: `apiBase`).
919
192
 
920
193
  ---
921
194