@nxuss/lemma 1.5.0 → 1.7.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.
- package/README.md +182 -6
- package/bin/checkpoint.js +49 -0
- package/bin/init.js +21 -2
- package/dist/cjs/cli/lemma-proxy.d.ts.map +1 -1
- package/dist/cjs/cli/lemma-proxy.js +50 -6
- package/dist/cjs/cli/lemma-proxy.js.map +1 -1
- package/dist/cjs/mcp/index.js +23 -0
- package/dist/cjs/mcp/index.js.map +1 -1
- package/dist/cjs/mcp/prompts.d.ts +1 -2
- package/dist/cjs/mcp/prompts.d.ts.map +1 -1
- package/dist/cjs/mcp/prompts.js +34 -129
- package/dist/cjs/mcp/prompts.js.map +1 -1
- package/dist/cjs/mcp/resources.d.ts.map +1 -1
- package/dist/cjs/mcp/resources.js +4 -4
- package/dist/cjs/mcp/resources.js.map +1 -1
- package/dist/cjs/mcp/tool-profiles.d.ts +55 -0
- package/dist/cjs/mcp/tool-profiles.d.ts.map +1 -0
- package/dist/cjs/mcp/tool-profiles.js +204 -0
- package/dist/cjs/mcp/tool-profiles.js.map +1 -0
- package/dist/cjs/mcp/tools.d.ts +14 -0
- package/dist/cjs/mcp/tools.d.ts.map +1 -1
- package/dist/cjs/mcp/tools.js +190 -27
- package/dist/cjs/mcp/tools.js.map +1 -1
- package/dist/cjs/subconscious/TheBrainV2.d.ts +36 -2
- package/dist/cjs/subconscious/TheBrainV2.d.ts.map +1 -1
- package/dist/cjs/subconscious/TheBrainV2.js +104 -23
- package/dist/cjs/subconscious/TheBrainV2.js.map +1 -1
- package/dist/cjs/utils/AutoContextBundle.d.ts.map +1 -1
- package/dist/cjs/utils/AutoContextBundle.js +17 -20
- package/dist/cjs/utils/AutoContextBundle.js.map +1 -1
- package/dist/cjs/utils/ContextSqueezer.d.ts.map +1 -1
- package/dist/cjs/utils/ContextSqueezer.js +5 -3
- package/dist/cjs/utils/ContextSqueezer.js.map +1 -1
- package/dist/cjs/utils/ConversationCheckpoint.d.ts +13 -0
- package/dist/cjs/utils/ConversationCheckpoint.d.ts.map +1 -1
- package/dist/cjs/utils/ConversationCheckpoint.js +58 -0
- package/dist/cjs/utils/ConversationCheckpoint.js.map +1 -1
- package/dist/cjs/utils/SavingsLedger.d.ts +38 -1
- package/dist/cjs/utils/SavingsLedger.d.ts.map +1 -1
- package/dist/cjs/utils/SavingsLedger.js +89 -13
- package/dist/cjs/utils/SavingsLedger.js.map +1 -1
- package/dist/cjs/utils/TestAutofixInterceptor.d.ts.map +1 -1
- package/dist/cjs/utils/TestAutofixInterceptor.js +15 -26
- package/dist/cjs/utils/TestAutofixInterceptor.js.map +1 -1
- package/dist/cjs/utils/reportSavings.d.ts +15 -0
- package/dist/cjs/utils/reportSavings.d.ts.map +1 -1
- package/dist/cjs/utils/reportSavings.js +13 -1
- package/dist/cjs/utils/reportSavings.js.map +1 -1
- package/dist/esm/cli/lemma-proxy.d.ts.map +1 -1
- package/dist/esm/cli/lemma-proxy.js +50 -6
- package/dist/esm/cli/lemma-proxy.js.map +1 -1
- package/dist/esm/mcp/index.js +24 -1
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/prompts.d.ts +1 -2
- package/dist/esm/mcp/prompts.d.ts.map +1 -1
- package/dist/esm/mcp/prompts.js +33 -128
- package/dist/esm/mcp/prompts.js.map +1 -1
- package/dist/esm/mcp/resources.d.ts.map +1 -1
- package/dist/esm/mcp/resources.js +4 -4
- package/dist/esm/mcp/resources.js.map +1 -1
- package/dist/esm/mcp/tool-profiles.d.ts +55 -0
- package/dist/esm/mcp/tool-profiles.d.ts.map +1 -0
- package/dist/esm/mcp/tool-profiles.js +196 -0
- package/dist/esm/mcp/tool-profiles.js.map +1 -0
- package/dist/esm/mcp/tools.d.ts +14 -0
- package/dist/esm/mcp/tools.d.ts.map +1 -1
- package/dist/esm/mcp/tools.js +188 -29
- package/dist/esm/mcp/tools.js.map +1 -1
- package/dist/esm/subconscious/TheBrainV2.d.ts +36 -2
- package/dist/esm/subconscious/TheBrainV2.d.ts.map +1 -1
- package/dist/esm/subconscious/TheBrainV2.js +103 -23
- package/dist/esm/subconscious/TheBrainV2.js.map +1 -1
- package/dist/esm/utils/AutoContextBundle.d.ts.map +1 -1
- package/dist/esm/utils/AutoContextBundle.js +17 -20
- package/dist/esm/utils/AutoContextBundle.js.map +1 -1
- package/dist/esm/utils/ContextSqueezer.d.ts.map +1 -1
- package/dist/esm/utils/ContextSqueezer.js +5 -3
- package/dist/esm/utils/ContextSqueezer.js.map +1 -1
- package/dist/esm/utils/ConversationCheckpoint.d.ts +13 -0
- package/dist/esm/utils/ConversationCheckpoint.d.ts.map +1 -1
- package/dist/esm/utils/ConversationCheckpoint.js +57 -0
- package/dist/esm/utils/ConversationCheckpoint.js.map +1 -1
- package/dist/esm/utils/SavingsLedger.d.ts +38 -1
- package/dist/esm/utils/SavingsLedger.d.ts.map +1 -1
- package/dist/esm/utils/SavingsLedger.js +89 -13
- package/dist/esm/utils/SavingsLedger.js.map +1 -1
- package/dist/esm/utils/TestAutofixInterceptor.d.ts.map +1 -1
- package/dist/esm/utils/TestAutofixInterceptor.js +15 -26
- package/dist/esm/utils/TestAutofixInterceptor.js.map +1 -1
- package/dist/esm/utils/reportSavings.d.ts +15 -0
- package/dist/esm/utils/reportSavings.d.ts.map +1 -1
- package/dist/esm/utils/reportSavings.js +12 -1
- package/dist/esm/utils/reportSavings.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const LEMMA_TURBOMODE_PROMPT = "You are operating in LEMMA TURBOMODE. Your goal: multiply the user's LLM membership 50x by spending 50x fewer tokens per task. Every token counts. Every cache hit is a membership extension.\n\n## MANDATORY TURBOMODE RULES \u2014 VIOLATE THESE AND YOU WASTE THE USER'S MONEY\n\n### 0. Before ANYTHING \u2192 check token_budget\nEvery 5 turns, call `token_budget` to check your consumption. If multiplier drops below 10x, optimize harder.\n\n### 1. turbosqueeze is for YOUR internal context only \u2014 never for code shown to the user\nUse `turbosqueeze` to compress code before feeding it into your own reasoning/context window.\nNEVER apply it to a code block you are about to show or hand to the user \u2014 they get the real,\ncomplete file (comments, imports, formatting intact) so it stays copy-pasteable and correct.\nIf a squeezed version was used for reasoning, re-fetch or reconstruct the untouched original\nbefore presenting it.\n\n### 2. smarter_cache (threshold 0.8) is a hint, not an answer\nCall `smarter_cache` with the user's question before reasoning from scratch \u2014 a hit can save\ntime. But NEVER return a cache hit verbatim as if freshly reasoned:\n- Require similarity >= 0.8 (raised from 0.75 \u2014 0.75 was matching questions that weren't\n actually the same question).\n- Always tell the user the answer came from cache (e.g. \"from a cached earlier answer:\").\n- If the user is about to act on the answer (run a command, apply a patch, ship code), verify\n it against current file/tool state before using it \u2014 cached answers can be stale.\n- On a MISS, or on any doubt, reason normally.\n\n### 3. Call compress_context only when actually approaching the context limit\nDon't compress on a fixed schedule (\"every new turn\") \u2014 most hosts already manage context\nwindow pressure themselves, so an unconditional call wastes a round-trip most of the time.\nCall `compress_context` when you have concrete signal you're actually close to the limit.\nWhen you do compress, tell the user it happened and keep enough of the summary that a decision\nor constraint from earlier in the conversation isn't silently lost \u2014 \"2 sentences\" is a floor\nfor genuinely small talk, not a fixed size for everything that came before.\n\n### 4. Before reading files \u2192 call get_ast_hologram\nNEVER read files blindly. Always call `get_ast_hologram` first to locate the exact symbols you need. Then read only those specific files. Each unnecessary file read wastes 1000+ tokens.\n\n### 4b. Before re-reading a file \u2192 call file_fingerprint\nBefore calling read_workspace_file, check if the file hash has changed since last read. If status is 'unchanged', skip the read entirely. Only read when hash differs.\n\n### 4c. Before deep file analysis \u2192 use import_tree_context + type_coverage_report\nInstead of reading full files to understand architecture, call import_tree_context (import graph) and type_coverage_report (type safety). Both are zero-token tools.\n\n### 4d. Before investigating code ownership \u2192 call git_blame_heat\nFor questions about who wrote code, why it's risky, or change history, call git_blame_heat instead of reasoning. Zero LLM cost.\n\n### 5. After every VERIFIED solution \u2192 call store_memory automatically\nStore via `store_memory` once you've confirmed the fix/answer actually worked (tests pass,\nthe user confirmed, the build succeeded) \u2014 not the first thing you tried. A wrong answer stored\nhere becomes a \"cache hit\" served to a future session, and unwinding that costs far more than\nthe tokens it saved. Verified answers are still free to cache aggressively.\n\n### 6. Answer concisely \u2014 no fluff, but never at the cost of a required disclosure\n- No \"Sure, I can help you with that\" \u2014 just do it.\n- No unnecessary explanation of what you did \u2014 unless asked.\n- No markdown formatting in internal responses.\n- No repeating the user's question back to them.\n- Exception: disclosures required elsewhere in these rules (cache-hit source per rule 2,\n a context-compression event per rule 3, a risky/irreversible action) are never fluff \u2014 say\n them in one short line. Conciseness trims filler, not information the user needs to trust the answer.\n\n### 7. Use batch_tool_calls aggressively\nAny set of independent operations (read 3 files, search 2 patterns, check cache for 2 questions) \u2014 use `batch_tool_calls` to run them in parallel. Single round-trip > multiple sequential calls.\n\n### 8. Before multi-file operations \u2192 use auto_context_bundle or bulk_file_digest\nInstead of reading files one by one, use `auto_context_bundle` (one file, everything included) or `bulk_file_digest` (multiple files, one call). Both save 75-80% round-trips.\n\n### 9. Before outputting long responses \u2192 check repeat_guard\nCall `repeat_guard` with your draft output to avoid repeating yourself. Saves 10-15% of output tokens.\n\n### 9b. For questions tied to specific files \u2192 prefer state_hash_cache over smarter_cache\nIf the question depends on the current content of specific files (not just \"similar wording\"),\ncall `state_hash_cache` (action=\"lookup\") instead of `smarter_cache`. It only returns a hit\nwhen the referenced files' content hashes are unchanged \u2014 a guaranteed-valid answer, not a\nsimilarity guess. After answering, call it again with action=\"store\" to cache it. Use\n`smarter_cache` only for file-independent questions (explanations, general how-tos).\n\n### 9c. Route model choice through get_routing_advice, don't assume the biggest model\nBefore a mechanical/low-complexity task (formatting, boilerplate, simple lookups), call\n`get_routing_advice` with the task prompt. If it recommends a cheaper model and the current\nprovider supports switching, say so instead of silently burning a large-model budget on trivial work.\n\n### 9d. Default all file edits to symbol-level patches via surgical_ast_insert\nWhen adding a method/function/property to an existing class, interface, or file, prefer\n`surgical_ast_insert` over regenerating and rewriting the whole file. Only fall back to a full\n`write_workspace_file` when the change isn't a clean insertion (renames, structural rewrites,\nnew files).\n\n### 9e. When asked \"how much did we actually save\" \u2192 call token_receipt, don't estimate\n`token_receipt` returns a real, auditable log of what happened this session (exact cache hits,\nsemantic cache hits, file reads, fresh reasoning) \u2014 not a projected percentage. Use it instead of\ninventing a savings number, and show the byType breakdown so the user can verify it themselves.\n\n### 10. When resuming work \u2192 load conversation_checkpoint\nAt session start or when user says \"continuemos\", call `conversation_checkpoint` with action \"load\" to restore context without re-explaining.\n\n### 11. When tests fail \u2192 use test_autofix_interceptor, but verify the suggested fix before applying it\nCall `test_autofix_interceptor` to get failures + Brain-suggested fixes in one call \u2014 that part\nsaves real tokens. But treat the suggested fix as a candidate, not a verdict: check it actually\naddresses the failing assertion before applying it. Applying a wrong auto-fix blind costs far\nmore (a broken build, a confused user, a debugging round-trip) than the tokens saved skipping the check.\n\n### 12. For common prompt patterns \u2192 use prompt_pattern_cache\nBefore generating repetitive prompts (\"explain this\", \"review this\", \"write tests\"), check `prompt_pattern_cache` action \"find\" for cached templates.\n\n## TURBOMODE SCORING\nCorrectness first, then cost \u2014 a fast wrong answer is more expensive than a slow right one once\nyou count the round-trip to find and fix it.\n- Verified cache hit (state_hash_cache, or a disclosed smarter_cache hit above threshold) = best outcome: correct AND ~0 tokens spent.\n- Cache MISS + reasoning from scratch = the normal, GOOD outcome whenever no verified cache exists. Reasoning is not a failure mode \u2014 it's what you do when you don't already have a trustworthy answer.\n- Reading full files without checking get_ast_hologram/file_fingerprint first = wasteful, avoid it when a cheaper lookup would've told you what you needed.\n- Any answer delivered without required disclosure (rule 6's exception), or a cached/auto-fixed result used without verification = FAIL, regardless of tokens saved \u2014 it can cost the user far more than tokens once it's wrong.\n\nRemember: the goal is spending fewer tokens on the SAME quality of answer, not a lower-quality answer for fewer tokens.";
|
|
2
|
+
export declare const LEMMA_TURBOMODE_PROMPT = "You are operating in LEMMA TURBOMODE. Your goal: reduce what enters the model's context \u2014 file reads, command output, and repeated reasoning \u2014 without ever costing the user a correct answer. Every reduction is recorded in an auditable ledger that also records what Lemma spent to achieve it.\n\nThere is no fixed multiplier to hit. Lemma's own overhead (this prompt plus every tool schema) is charged to that ledger before a single token is saved, so a session only comes out ahead if the reductions below actually exceed it. Optimize for real net savings, not for a number.\n\n## MANDATORY TURBOMODE RULES \u2014 VIOLATE THESE AND YOU WASTE THE USER'S MONEY\n\n### 0. Every tool call costs tokens too\nA tool call and its result both stay in the transcript and are re-sent on every later turn. Before calling a Lemma tool, expect it to save more than that round-trip costs \u2014 on a small file or a short command, reading it directly is cheaper. Never call a reporting tool on a schedule: a report is not work. Call one only when the user asks how the session is going.\n\n### 0b. The tool list you see is not everything Lemma has\nSchemas for situational tools are withheld from this session to keep the per-turn cost down. When\nno advertised tool fits, call `lemma_toolbox` (action=\"list\" with a query) before concluding\nLemma can't do it, then action=\"call\" to run what you find. Never tell the user a capability is\nmissing without checking the toolbox first.\n\n### 1. Compression is for YOUR context only \u2014 never for code shown to the user\nLemma's compressors (turbosqueeze, wormhole_squeeze, squeeze_prompt \u2014 via the toolbox) exist to\nshrink code before it enters your own reasoning window. NEVER hand a compressed version to the\nuser: they get the real, complete file (comments, imports, formatting intact) so it stays\ncopy-pasteable and correct. If you reasoned over a squeezed version, re-fetch the untouched\noriginal before presenting it.\n\n### 2. smarter_cache (threshold 0.8) is a hint, not an answer\nCall `smarter_cache` with the user's question before reasoning from scratch \u2014 a hit can save\ntime. But NEVER return a cache hit verbatim as if freshly reasoned:\n- Require similarity >= 0.8 (raised from 0.75 \u2014 0.75 was matching questions that weren't\n actually the same question).\n- Always tell the user the answer came from cache (e.g. \"from a cached earlier answer:\").\n- If the user is about to act on the answer (run a command, apply a patch, ship code), verify\n it against current file/tool state before using it \u2014 cached answers can be stale.\n- On a MISS, or on any doubt, reason normally.\n\n### 3. Before reading files \u2192 call get_ast_hologram\nNEVER read files blindly. Always call `get_ast_hologram` first to locate the exact symbols you need. Then read only those specific files. Each unnecessary file read wastes 1000+ tokens.\n\n### 4. After every VERIFIED solution \u2192 call store_memory automatically\nStore via `store_memory` once you've confirmed the fix/answer actually worked (tests pass,\nthe user confirmed, the build succeeded) \u2014 not the first thing you tried. A wrong answer stored\nhere becomes a \"cache hit\" served to a future session, and unwinding that costs far more than\nthe tokens it saved. Verified answers are still free to cache aggressively.\n\n### 5. Answer concisely \u2014 no fluff, but never at the cost of a required disclosure\n- No \"Sure, I can help you with that\" \u2014 just do it.\n- No unnecessary explanation of what you did \u2014 unless asked.\n- No repeating the user's question back to them.\n- Exception: disclosures required elsewhere in these rules (cache-hit source per rule 2,\n a risky/irreversible action) are never fluff \u2014 say them in one short line. Conciseness trims\n filler, not information the user needs to trust the answer.\n\n### 6. For questions tied to specific files \u2192 prefer state_hash_cache over smarter_cache\nIf the question depends on the current content of specific files (not just \"similar wording\"),\ncall `state_hash_cache` (action=\"lookup\") instead of `smarter_cache`. It only returns a hit\nwhen the referenced files' content hashes are unchanged \u2014 a guaranteed-valid answer, not a\nsimilarity guess. After answering, call it again with action=\"store\" to cache it. Use\n`smarter_cache` only for file-independent questions (explanations, general how-tos).\n\n### 7. Route model choice through get_routing_advice, don't assume the biggest model\nBefore a mechanical/low-complexity task (formatting, boilerplate, simple lookups), call\n`get_routing_advice` with the task prompt. If it recommends a cheaper model and the current\nprovider supports switching, say so instead of silently burning a large-model budget on trivial work.\n\n### 8. Default all file edits to symbol-level patches via surgical_ast_insert\nWhen adding a method/function/property to an existing class, interface, or file, prefer\n`surgical_ast_insert` over regenerating and rewriting the whole file. Only fall back to a full\n`write_workspace_file` when the change isn't a clean insertion (renames, structural rewrites,\nnew files).\n\n### 9. When asked \"how much did we actually save\" \u2192 call token_receipt, don't estimate\n`token_receipt` returns a real, auditable log of what happened this session (exact cache hits,\nsemantic cache hits, file reads, fresh reasoning) \u2014 not a projected percentage. Use it instead of\ninventing a savings number, and show the byType breakdown so the user can verify it themselves.\n\n### 10. Anything the toolbox hands you is still a candidate, not a verdict\nTools reached via `lemma_toolbox` (auto-fixes for failing tests, cached prompt patterns,\nBrain-suggested patches) return suggestions. Check a suggested fix actually addresses the failing\nassertion before applying it \u2014 a wrong auto-fix applied blind costs far more (broken build,\ndebugging round-trip) than the tokens saved by skipping the check.\n\n## TURBOMODE SCORING\nCorrectness first, then cost \u2014 a fast wrong answer is more expensive than a slow right one once\nyou count the round-trip to find and fix it.\n- Verified cache hit (state_hash_cache, or a disclosed smarter_cache hit above threshold) = best outcome: correct AND ~0 tokens spent.\n- Cache MISS + reasoning from scratch = the normal, GOOD outcome whenever no verified cache exists. Reasoning is not a failure mode \u2014 it's what you do when you don't already have a trustworthy answer.\n- Reading full files without checking get_ast_hologram first = wasteful, avoid it when a cheaper lookup would've told you what you needed.\n- Any answer delivered without required disclosure (rule 6's exception), or a cached/auto-fixed result used without verification = FAIL, regardless of tokens saved \u2014 it can cost the user far more than tokens once it's wrong.\n\nRemember: the goal is spending fewer tokens on the SAME quality of answer, not a lower-quality answer for fewer tokens.";
|
|
4
3
|
export declare function setupPromptsHandlers(server: Server): void;
|
|
5
4
|
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/mcp/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/mcp/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,eAAO,MAAM,sBAAsB,23NAsFqF,CAAC;AAEzH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA8BzD"}
|
package/dist/esm/mcp/prompts.js
CHANGED
|
@@ -1,68 +1,25 @@
|
|
|
1
1
|
import { GetPromptRequestSchema, ListPromptsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
-
export const
|
|
3
|
-
|
|
4
|
-
to
|
|
5
|
-
|
|
6
|
-
## MANDATORY AUTOMATIC BEHAVIORS
|
|
7
|
-
|
|
8
|
-
### 1. Before reading ANY file → call get_ast_hologram first
|
|
9
|
-
When you need to understand the structure of a codebase or navigate files, ALWAYS call
|
|
10
|
-
\`get_ast_hologram\` first (with the relevant dirPath, e.g. "src"). Use the returned symbol
|
|
11
|
-
map to pinpoint exactly which files to read. NEVER blindly read every file one by one.
|
|
12
|
-
|
|
13
|
-
### 2. Before answering ANY technical question → call query_hybrid_consensus first
|
|
14
|
-
BEFORE making any reasoning or cloud LLM call, ALWAYS call \`query_hybrid_consensus\` with
|
|
15
|
-
the user's question. If similarity ≥ 80%, return the cached answer immediately — no cloud
|
|
16
|
-
call needed. Only proceed with your own reasoning if the Brain returns a MISS.
|
|
17
|
-
|
|
18
|
-
### 3. When you start working on ANY file → call get_telepathic_hints automatically
|
|
19
|
-
Whenever the user mentions a file or you are about to read/edit a file, IMMEDIATELY call
|
|
20
|
-
\`get_telepathic_hints\` with that file's path. Surface the results to the user as relevant
|
|
21
|
-
context BEFORE doing any work. Do not ask permission — just do it.
|
|
22
|
-
|
|
23
|
-
### 4. Before applying ANY code patch → call validate_patch_sandbox first
|
|
24
|
-
NEVER call \`write_workspace_file\` or \`apply_workspace_patch\` without FIRST calling
|
|
25
|
-
\`validate_patch_sandbox\` with the proposed content. Only proceed with the write if the
|
|
26
|
-
verdict is "✅ SAFE TO APPLY". If it fails, fix the issues and re-validate.
|
|
27
|
-
|
|
28
|
-
### 5. After solving any technical problem → call store_memory automatically
|
|
29
|
-
After resolving a bug, implementing a feature, or answering a significant technical question,
|
|
30
|
-
ALWAYS call \`store_memory\` to persist the solution. Use a descriptive query key so it can
|
|
31
|
-
be retrieved in future sessions across ALL projects.
|
|
32
|
-
|
|
33
|
-
### 6. Workspace navigation → always use Lemma tools, NEVER guess file contents
|
|
34
|
-
- Use \`list_workspace_dir\` to navigate structure
|
|
35
|
-
- Use \`read_workspace_file\` (auto-compresses + scrubs secrets) instead of asking the user
|
|
36
|
-
- Use \`search_workspace\` for text search across files
|
|
37
|
-
- Use \`run_workspace_command\` for builds, tests, linters — long output comes back distilled
|
|
38
|
-
(failing tests / diagnostics with locations). It is a real view of the run, not a guess, but it
|
|
39
|
-
is not the whole output: call \`output_region\` with the reported handle whenever you need the
|
|
40
|
-
rest, and never tell the user a run was clean based on a distilled view you didn't read.
|
|
41
|
-
|
|
42
|
-
### 7. Privacy is automatic
|
|
43
|
-
\`read_workspace_file\` and \`search_workspace\` automatically scrub API keys and PII.
|
|
44
|
-
You never need to manually sanitize file content.
|
|
45
|
-
|
|
46
|
-
## LEMMA RESOURCES (auto-subscribe when available)
|
|
47
|
-
- \`lemma://runtime/context\` — live crash logs. Read this FIRST when the user reports a bug.
|
|
48
|
-
- \`lemma://multiverse/timeline\` — AST history. Use when the user says "it was working before".
|
|
49
|
-
- \`lemma://project/onboarding\` — architecture map. Read at session start in new repos.
|
|
50
|
-
- \`lemma://stats/usage\` — token savings report.
|
|
51
|
-
|
|
52
|
-
Remember: the user hired YOU to be autonomous. Act like it.`;
|
|
53
|
-
export const LEMMA_TURBOMODE_PROMPT = `You are operating in LEMMA TURBOMODE. Your goal: multiply the user's LLM membership 50x by spending 50x fewer tokens per task. Every token counts. Every cache hit is a membership extension.
|
|
2
|
+
export const LEMMA_TURBOMODE_PROMPT = `You are operating in LEMMA TURBOMODE. Your goal: reduce what enters the model's context — file reads, command output, and repeated reasoning — without ever costing the user a correct answer. Every reduction is recorded in an auditable ledger that also records what Lemma spent to achieve it.
|
|
3
|
+
|
|
4
|
+
There is no fixed multiplier to hit. Lemma's own overhead (this prompt plus every tool schema) is charged to that ledger before a single token is saved, so a session only comes out ahead if the reductions below actually exceed it. Optimize for real net savings, not for a number.
|
|
54
5
|
|
|
55
6
|
## MANDATORY TURBOMODE RULES — VIOLATE THESE AND YOU WASTE THE USER'S MONEY
|
|
56
7
|
|
|
57
|
-
### 0.
|
|
58
|
-
|
|
8
|
+
### 0. Every tool call costs tokens too
|
|
9
|
+
A tool call and its result both stay in the transcript and are re-sent on every later turn. Before calling a Lemma tool, expect it to save more than that round-trip costs — on a small file or a short command, reading it directly is cheaper. Never call a reporting tool on a schedule: a report is not work. Call one only when the user asks how the session is going.
|
|
10
|
+
|
|
11
|
+
### 0b. The tool list you see is not everything Lemma has
|
|
12
|
+
Schemas for situational tools are withheld from this session to keep the per-turn cost down. When
|
|
13
|
+
no advertised tool fits, call \`lemma_toolbox\` (action="list" with a query) before concluding
|
|
14
|
+
Lemma can't do it, then action="call" to run what you find. Never tell the user a capability is
|
|
15
|
+
missing without checking the toolbox first.
|
|
59
16
|
|
|
60
|
-
### 1.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
complete file (comments, imports, formatting intact) so it stays
|
|
64
|
-
If a squeezed version
|
|
65
|
-
before presenting it.
|
|
17
|
+
### 1. Compression is for YOUR context only — never for code shown to the user
|
|
18
|
+
Lemma's compressors (turbosqueeze, wormhole_squeeze, squeeze_prompt — via the toolbox) exist to
|
|
19
|
+
shrink code before it enters your own reasoning window. NEVER hand a compressed version to the
|
|
20
|
+
user: they get the real, complete file (comments, imports, formatting intact) so it stays
|
|
21
|
+
copy-pasteable and correct. If you reasoned over a squeezed version, re-fetch the untouched
|
|
22
|
+
original before presenting it.
|
|
66
23
|
|
|
67
24
|
### 2. smarter_cache (threshold 0.8) is a hint, not an answer
|
|
68
25
|
Call \`smarter_cache\` with the user's question before reasoning from scratch — a hit can save
|
|
@@ -74,91 +31,58 @@ time. But NEVER return a cache hit verbatim as if freshly reasoned:
|
|
|
74
31
|
it against current file/tool state before using it — cached answers can be stale.
|
|
75
32
|
- On a MISS, or on any doubt, reason normally.
|
|
76
33
|
|
|
77
|
-
### 3.
|
|
78
|
-
Don't compress on a fixed schedule ("every new turn") — most hosts already manage context
|
|
79
|
-
window pressure themselves, so an unconditional call wastes a round-trip most of the time.
|
|
80
|
-
Call \`compress_context\` when you have concrete signal you're actually close to the limit.
|
|
81
|
-
When you do compress, tell the user it happened and keep enough of the summary that a decision
|
|
82
|
-
or constraint from earlier in the conversation isn't silently lost — "2 sentences" is a floor
|
|
83
|
-
for genuinely small talk, not a fixed size for everything that came before.
|
|
84
|
-
|
|
85
|
-
### 4. Before reading files → call get_ast_hologram
|
|
34
|
+
### 3. Before reading files → call get_ast_hologram
|
|
86
35
|
NEVER read files blindly. Always call \`get_ast_hologram\` first to locate the exact symbols you need. Then read only those specific files. Each unnecessary file read wastes 1000+ tokens.
|
|
87
36
|
|
|
88
|
-
###
|
|
89
|
-
Before calling read_workspace_file, check if the file hash has changed since last read. If status is 'unchanged', skip the read entirely. Only read when hash differs.
|
|
90
|
-
|
|
91
|
-
### 4c. Before deep file analysis → use import_tree_context + type_coverage_report
|
|
92
|
-
Instead of reading full files to understand architecture, call import_tree_context (import graph) and type_coverage_report (type safety). Both are zero-token tools.
|
|
93
|
-
|
|
94
|
-
### 4d. Before investigating code ownership → call git_blame_heat
|
|
95
|
-
For questions about who wrote code, why it's risky, or change history, call git_blame_heat instead of reasoning. Zero LLM cost.
|
|
96
|
-
|
|
97
|
-
### 5. After every VERIFIED solution → call store_memory automatically
|
|
37
|
+
### 4. After every VERIFIED solution → call store_memory automatically
|
|
98
38
|
Store via \`store_memory\` once you've confirmed the fix/answer actually worked (tests pass,
|
|
99
39
|
the user confirmed, the build succeeded) — not the first thing you tried. A wrong answer stored
|
|
100
40
|
here becomes a "cache hit" served to a future session, and unwinding that costs far more than
|
|
101
41
|
the tokens it saved. Verified answers are still free to cache aggressively.
|
|
102
42
|
|
|
103
|
-
###
|
|
43
|
+
### 5. Answer concisely — no fluff, but never at the cost of a required disclosure
|
|
104
44
|
- No "Sure, I can help you with that" — just do it.
|
|
105
45
|
- No unnecessary explanation of what you did — unless asked.
|
|
106
|
-
- No markdown formatting in internal responses.
|
|
107
46
|
- No repeating the user's question back to them.
|
|
108
47
|
- Exception: disclosures required elsewhere in these rules (cache-hit source per rule 2,
|
|
109
|
-
a
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
### 7. Use batch_tool_calls aggressively
|
|
113
|
-
Any set of independent operations (read 3 files, search 2 patterns, check cache for 2 questions) — use \`batch_tool_calls\` to run them in parallel. Single round-trip > multiple sequential calls.
|
|
48
|
+
a risky/irreversible action) are never fluff — say them in one short line. Conciseness trims
|
|
49
|
+
filler, not information the user needs to trust the answer.
|
|
114
50
|
|
|
115
|
-
###
|
|
116
|
-
Instead of reading files one by one, use \`auto_context_bundle\` (one file, everything included) or \`bulk_file_digest\` (multiple files, one call). Both save 75-80% round-trips.
|
|
117
|
-
|
|
118
|
-
### 9. Before outputting long responses → check repeat_guard
|
|
119
|
-
Call \`repeat_guard\` with your draft output to avoid repeating yourself. Saves 10-15% of output tokens.
|
|
120
|
-
|
|
121
|
-
### 9b. For questions tied to specific files → prefer state_hash_cache over smarter_cache
|
|
51
|
+
### 6. For questions tied to specific files → prefer state_hash_cache over smarter_cache
|
|
122
52
|
If the question depends on the current content of specific files (not just "similar wording"),
|
|
123
53
|
call \`state_hash_cache\` (action="lookup") instead of \`smarter_cache\`. It only returns a hit
|
|
124
54
|
when the referenced files' content hashes are unchanged — a guaranteed-valid answer, not a
|
|
125
55
|
similarity guess. After answering, call it again with action="store" to cache it. Use
|
|
126
56
|
\`smarter_cache\` only for file-independent questions (explanations, general how-tos).
|
|
127
57
|
|
|
128
|
-
###
|
|
58
|
+
### 7. Route model choice through get_routing_advice, don't assume the biggest model
|
|
129
59
|
Before a mechanical/low-complexity task (formatting, boilerplate, simple lookups), call
|
|
130
60
|
\`get_routing_advice\` with the task prompt. If it recommends a cheaper model and the current
|
|
131
61
|
provider supports switching, say so instead of silently burning a large-model budget on trivial work.
|
|
132
62
|
|
|
133
|
-
###
|
|
63
|
+
### 8. Default all file edits to symbol-level patches via surgical_ast_insert
|
|
134
64
|
When adding a method/function/property to an existing class, interface, or file, prefer
|
|
135
65
|
\`surgical_ast_insert\` over regenerating and rewriting the whole file. Only fall back to a full
|
|
136
66
|
\`write_workspace_file\` when the change isn't a clean insertion (renames, structural rewrites,
|
|
137
67
|
new files).
|
|
138
68
|
|
|
139
|
-
###
|
|
69
|
+
### 9. When asked "how much did we actually save" → call token_receipt, don't estimate
|
|
140
70
|
\`token_receipt\` returns a real, auditable log of what happened this session (exact cache hits,
|
|
141
71
|
semantic cache hits, file reads, fresh reasoning) — not a projected percentage. Use it instead of
|
|
142
72
|
inventing a savings number, and show the byType breakdown so the user can verify it themselves.
|
|
143
73
|
|
|
144
|
-
### 10.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
saves real tokens. But treat the suggested fix as a candidate, not a verdict: check it actually
|
|
150
|
-
addresses the failing assertion before applying it. Applying a wrong auto-fix blind costs far
|
|
151
|
-
more (a broken build, a confused user, a debugging round-trip) than the tokens saved skipping the check.
|
|
152
|
-
|
|
153
|
-
### 12. For common prompt patterns → use prompt_pattern_cache
|
|
154
|
-
Before generating repetitive prompts ("explain this", "review this", "write tests"), check \`prompt_pattern_cache\` action "find" for cached templates.
|
|
74
|
+
### 10. Anything the toolbox hands you is still a candidate, not a verdict
|
|
75
|
+
Tools reached via \`lemma_toolbox\` (auto-fixes for failing tests, cached prompt patterns,
|
|
76
|
+
Brain-suggested patches) return suggestions. Check a suggested fix actually addresses the failing
|
|
77
|
+
assertion before applying it — a wrong auto-fix applied blind costs far more (broken build,
|
|
78
|
+
debugging round-trip) than the tokens saved by skipping the check.
|
|
155
79
|
|
|
156
80
|
## TURBOMODE SCORING
|
|
157
81
|
Correctness first, then cost — a fast wrong answer is more expensive than a slow right one once
|
|
158
82
|
you count the round-trip to find and fix it.
|
|
159
83
|
- Verified cache hit (state_hash_cache, or a disclosed smarter_cache hit above threshold) = best outcome: correct AND ~0 tokens spent.
|
|
160
84
|
- Cache MISS + reasoning from scratch = the normal, GOOD outcome whenever no verified cache exists. Reasoning is not a failure mode — it's what you do when you don't already have a trustworthy answer.
|
|
161
|
-
- Reading full files without checking get_ast_hologram
|
|
85
|
+
- Reading full files without checking get_ast_hologram first = wasteful, avoid it when a cheaper lookup would've told you what you needed.
|
|
162
86
|
- Any answer delivered without required disclosure (rule 6's exception), or a cached/auto-fixed result used without verification = FAIL, regardless of tokens saved — it can cost the user far more than tokens once it's wrong.
|
|
163
87
|
|
|
164
88
|
Remember: the goal is spending fewer tokens on the SAME quality of answer, not a lower-quality answer for fewer tokens.`;
|
|
@@ -166,34 +90,15 @@ export function setupPromptsHandlers(server) {
|
|
|
166
90
|
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
|
167
91
|
return {
|
|
168
92
|
prompts: [
|
|
169
|
-
{
|
|
170
|
-
name: "lemma-autopilot",
|
|
171
|
-
description: "Lemma Autopilot: mandatory behavioral instructions for the AI assistant. Load this prompt to make all Lemma tools fire automatically with zero user friction.",
|
|
172
|
-
arguments: [],
|
|
173
|
-
},
|
|
174
93
|
{
|
|
175
94
|
name: "lemma-turbomode",
|
|
176
|
-
description: "
|
|
95
|
+
description: "LEMMA TURBOMODE: reduce context spend on file reads, command output, and repeated reasoning. Savings and Lemma's own overhead are both recorded in an auditable ledger. Use for long sessions on large repos.",
|
|
177
96
|
arguments: [],
|
|
178
97
|
},
|
|
179
98
|
],
|
|
180
99
|
};
|
|
181
100
|
});
|
|
182
101
|
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
|
183
|
-
if (request.params.name === "lemma-autopilot") {
|
|
184
|
-
return {
|
|
185
|
-
description: "Lemma Autopilot System Instructions",
|
|
186
|
-
messages: [
|
|
187
|
-
{
|
|
188
|
-
role: "user",
|
|
189
|
-
content: {
|
|
190
|
-
type: "text",
|
|
191
|
-
text: LEMMA_SYSTEM_PROMPT,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
102
|
if (request.params.name === "lemma-turbomode") {
|
|
198
103
|
return {
|
|
199
104
|
description: "Lemma TurboMode — Extreme Token Optimization",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/mcp/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAEtG,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../../src/mcp/prompts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAEtG,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wHAsFkF,CAAC;AAEzH,MAAM,UAAU,oBAAoB,CAAC,MAAc;IACjD,MAAM,CAAC,iBAAiB,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;QAC5D,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,iBAAiB;oBACvB,WAAW,EAAE,+MAA+M;oBAC5N,SAAS,EAAE,EAAE;iBACd;aACF;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACjE,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;YAC9C,OAAO;gBACL,WAAW,EAAE,8CAA8C;gBAC3D,QAAQ,EAAE;oBACR;wBACE,IAAI,EAAE,MAAM;wBACZ,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,sBAAsB;yBAC7B;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/mcp/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../../src/mcp/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AASnE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CA2D3D"}
|
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
import os from "os";
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
import { getProxyPort, logError } from "./utils";
|
|
7
|
+
import { getBrain, deriveProjectId } from "../subconscious/TheBrainV2";
|
|
7
8
|
export function setupResourcesHandlers(server) {
|
|
8
9
|
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
9
10
|
return {
|
|
@@ -128,10 +129,9 @@ async function handleProjectContext(uri) {
|
|
|
128
129
|
}
|
|
129
130
|
catch { }
|
|
130
131
|
try {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
132
|
+
// Counted files in <project>/.lemma/memory, which nothing writes — so this resource
|
|
133
|
+
// always advertised 0 memories regardless of what the Brain actually held.
|
|
134
|
+
memoryCount = getBrain().getEntriesForProject(deriveProjectId(projectPath)).length;
|
|
135
135
|
}
|
|
136
136
|
catch { }
|
|
137
137
|
const markdown = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/mcp/resources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAA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,MAAM,CAAC;oBACzC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;wBACd,QAAQ,IAAI,oDAAoD,IAAI,CAAC,IAAI,gBAAgB,CAAC;oBAC5F,CAAC;gBACH,CAAC,CAAC,CAAC;gBAEH,QAAQ,IAAI,WAAW,CAAC;YAC1B,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,QAAQ,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;QACvC,OAAO;YACL,QAAQ,EAAE;gBACR;oBACE,GAAG;oBACH,QAAQ,EAAE,eAAe;oBACzB,IAAI,EAAE,0DAA0D,KAAK,CAAC,OAAO,2BAA2B;iBACzG;aACF;SACF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool surface control.
|
|
3
|
+
*
|
|
4
|
+
* Every tool schema Lemma advertises is injected into the model's system prompt and
|
|
5
|
+
* re-sent on every single request of the session. At 76 tools that is ~11.4k tokens
|
|
6
|
+
* per turn, charged before Lemma has saved anything — and it is charged even for tools
|
|
7
|
+
* the project can never use (Terraform schemas in a repo with no `.tf` files).
|
|
8
|
+
*
|
|
9
|
+
* So the advertised list is narrowed to what this project can actually use. Nothing is
|
|
10
|
+
* removed: every handler stays registered, and `lemma_toolbox` exposes the rest by name
|
|
11
|
+
* on demand — a one-time ~1.2k token catalog instead of ~8k every turn.
|
|
12
|
+
*
|
|
13
|
+
* The list is resolved once at startup and never mutated mid-session. It lives in the
|
|
14
|
+
* cached prefix of every request; changing it (e.g. lazily "unlocking" tools via
|
|
15
|
+
* notifications/tools/list_changed) invalidates that cache and re-charges the whole
|
|
16
|
+
* context at full price, which costs far more than the schemas it would defer.
|
|
17
|
+
*/
|
|
18
|
+
export type ToolProfile = "auto" | "core" | "full";
|
|
19
|
+
/**
|
|
20
|
+
* Tools that pay for their schema in an ordinary coding session: reading, searching,
|
|
21
|
+
* patching, AST context, exact-hash caching, and the ledger. Everything else is
|
|
22
|
+
* situational and reachable through `lemma_toolbox`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const CORE_TOOL_NAMES: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Code review is a mode the user enters, not a property of the repo — and it cannot be
|
|
27
|
+
* detected at startup. Gating these on `.git` advertised them in every git repo, which is
|
|
28
|
+
* every repo: ~670 tokens per turn for tools most sessions never touch. They stay
|
|
29
|
+
* registered and `lemma_toolbox` finds them by query the moment a review actually starts.
|
|
30
|
+
*/
|
|
31
|
+
export declare const REVIEW_TOOL_NAMES: string[];
|
|
32
|
+
export interface ResolvedToolSurface<T extends {
|
|
33
|
+
name: string;
|
|
34
|
+
}> {
|
|
35
|
+
profile: ToolProfile;
|
|
36
|
+
/** Schemas advertised in tools/list. */
|
|
37
|
+
advertised: T[];
|
|
38
|
+
/** Registered and callable, but not advertised — reachable through `lemma_toolbox`. */
|
|
39
|
+
hidden: T[];
|
|
40
|
+
/** Situational groups that matched this project. */
|
|
41
|
+
activeGroups: string[];
|
|
42
|
+
}
|
|
43
|
+
export declare function resolveToolSurface<T extends {
|
|
44
|
+
name: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
}>(allDefinitions: T[], cwd?: string): ResolvedToolSurface<T>;
|
|
47
|
+
/**
|
|
48
|
+
* One-line-per-tool catalog of everything not advertised, so the model can find and
|
|
49
|
+
* invoke a hidden tool without its schema having been resident all session.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildToolboxCatalog(hidden: Array<{
|
|
52
|
+
name: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
}>, query?: string): string;
|
|
55
|
+
//# sourceMappingURL=tool-profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-profiles.d.ts","sourceRoot":"","sources":["../../../src/mcp/tool-profiles.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnD;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,EA0BnC,CAAC;AA4DF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,UAAoE,CAAC;AAkBnG,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;IAC7D,OAAO,EAAE,WAAW,CAAC;IACrB,wCAAwC;IACxC,UAAU,EAAE,CAAC,EAAE,CAAC;IAChB,uFAAuF;IACvF,MAAM,EAAE,CAAC,EAAE,CAAC;IACZ,oDAAoD;IACpD,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,wBAAgB,kBAAkB,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EACjF,cAAc,EAAE,CAAC,EAAE,EACnB,GAAG,GAAE,MAAsB,GAC1B,mBAAmB,CAAC,CAAC,CAAC,CAmCxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EACrD,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,CAuDR"}
|