semantic-sift 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. semantic_sift-0.2.1/LICENSE.md +201 -0
  2. semantic_sift-0.2.1/PKG-INFO +267 -0
  3. semantic_sift-0.2.1/README.md +231 -0
  4. semantic_sift-0.2.1/pyproject.toml +86 -0
  5. semantic_sift-0.2.1/semantic_sift/__init__.py +3 -0
  6. semantic_sift-0.2.1/semantic_sift/cli.py +69 -0
  7. semantic_sift-0.2.1/semantic_sift/hook.py +5 -0
  8. semantic_sift-0.2.1/semantic_sift/hook_injector.py +526 -0
  9. semantic_sift-0.2.1/semantic_sift/kernel.py +5 -0
  10. semantic_sift-0.2.1/semantic_sift/onboarding.py +128 -0
  11. semantic_sift-0.2.1/semantic_sift/onboarding_cli.py +57 -0
  12. semantic_sift-0.2.1/semantic_sift/server.py +5 -0
  13. semantic_sift-0.2.1/semantic_sift/telemetry.py +5 -0
  14. semantic_sift-0.2.1/semantic_sift/telemetry_cli.py +83 -0
  15. semantic_sift-0.2.1/semantic_sift/tools.py +288 -0
  16. semantic_sift-0.2.1/semantic_sift.egg-info/PKG-INFO +267 -0
  17. semantic_sift-0.2.1/semantic_sift.egg-info/SOURCES.txt +37 -0
  18. semantic_sift-0.2.1/semantic_sift.egg-info/dependency_links.txt +1 -0
  19. semantic_sift-0.2.1/semantic_sift.egg-info/entry_points.txt +5 -0
  20. semantic_sift-0.2.1/semantic_sift.egg-info/requires.txt +20 -0
  21. semantic_sift-0.2.1/semantic_sift.egg-info/top_level.txt +5 -0
  22. semantic_sift-0.2.1/server.py +39 -0
  23. semantic_sift-0.2.1/setup.cfg +4 -0
  24. semantic_sift-0.2.1/sift_hook.py +349 -0
  25. semantic_sift-0.2.1/sift_kernel.py +366 -0
  26. semantic_sift-0.2.1/telemetry_core.py +466 -0
  27. semantic_sift-0.2.1/tests/test_extraction_and_compaction.py +79 -0
  28. semantic_sift-0.2.1/tests/test_hook_injector.py +234 -0
  29. semantic_sift-0.2.1/tests/test_hook_integration.py +216 -0
  30. semantic_sift-0.2.1/tests/test_hook_routing.py +63 -0
  31. semantic_sift-0.2.1/tests/test_kernel_ranking.py +40 -0
  32. semantic_sift-0.2.1/tests/test_kernel_semantic.py +61 -0
  33. semantic_sift-0.2.1/tests/test_module_wrappers.py +35 -0
  34. semantic_sift-0.2.1/tests/test_onboarding.py +29 -0
  35. semantic_sift-0.2.1/tests/test_platform_gateways.py +26 -0
  36. semantic_sift-0.2.1/tests/test_security.py +88 -0
  37. semantic_sift-0.2.1/tests/test_server_tools.py +223 -0
  38. semantic_sift-0.2.1/tests/test_sieve.py +29 -0
  39. semantic_sift-0.2.1/tests/test_telemetry.py +111 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Luis Kobayashi
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.4
2
+ Name: semantic-sift
3
+ Version: 0.2.1
4
+ Summary: Reasoning-first MCP middleware for context distillation
5
+ Author: Luis Kobayashi
6
+ License: Apache-2.0
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE.md
18
+ Requires-Dist: mcp>=1.0
19
+ Requires-Dist: numpy>=1.24
20
+ Requires-Dist: opentelemetry-api>=1.20
21
+ Requires-Dist: opentelemetry-sdk>=1.20
22
+ Requires-Dist: psutil>=5.9
23
+ Provides-Extra: neural
24
+ Requires-Dist: llmlingua; extra == "neural"
25
+ Requires-Dist: torch; extra == "neural"
26
+ Requires-Dist: transformers; extra == "neural"
27
+ Requires-Dist: sentence-transformers; extra == "neural"
28
+ Provides-Extra: multi-modal
29
+ Requires-Dist: markitdown>=0.1; extra == "multi-modal"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest; extra == "dev"
32
+ Requires-Dist: pytest-cov; extra == "dev"
33
+ Requires-Dist: ruff; extra == "dev"
34
+ Requires-Dist: mypy; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # 🔍 Semantic-Sift
38
+
39
+ **The Reasoning-First Middleware for High-Fidelity Agentic Workflows.**
40
+
41
+ [![CI](https://github.com/luismichio/semantic-sift/actions/workflows/ci.yml/badge.svg)](https://github.com/luismichio/semantic-sift/actions/workflows/ci.yml)
42
+ [![Tests](https://img.shields.io/badge/Tests-84%20Passing-brightgreen)](tests/)
43
+ [![Coverage](https://img.shields.io/badge/Coverage-measured-blue)](https://github.com/luismichio/semantic-sift/actions)
44
+ [![PyPI](https://img.shields.io/pypi/v/semantic-sift)](https://pypi.org/project/semantic-sift/)
45
+ [![Python](https://img.shields.io/pypi/pyversions/semantic-sift)](https://pypi.org/project/semantic-sift/)
46
+ [![Security](https://img.shields.io/badge/Security-Bandit%20Inspected-brightgreen)](SECURITY.md)
47
+ [![License](https://img.shields.io/badge/License-Apache--2.0-blue)](LICENSE.md)
48
+ [![OSI](https://img.shields.io/badge/OSI-Approved-brightgreen)](https://opensource.org/licenses/Apache-2.0)
49
+
50
+ > **"It saves tokens while preserving context - maximizing reasoning, minimizing hallucination."**
51
+
52
+ Semantic-Sift is a local [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that acts as an intelligent "Sanitation Tier" between your raw data and your AI’s context window.
53
+
54
+ While modern LLMs have massive context windows, their reasoning accuracy often degrades as noise increases. Semantic-Sift solves this by distilling technical logs, long-form documents, and chat histories into high-density context. It treats your context window as a precious resource—optimizing for **Signal-to-Noise Ratio (SNR)** so your models spend more time reasoning and less time navigating boilerplate.
55
+
56
+ ### 🧠 Philosophy: The Studio of Two
57
+ Semantic-Sift is grounded in the **Studio of Two** philosophy: the belief that the future of engineering is a high-fidelity partnership between a human architect and a sovereign AI sidecar. By managing the friction of raw data ingestion, Sift allows this "Studio" to focus on building *systems*, not just applying *patches*. It acts as a cognitive filter that ensures both you and your agent are collaborating on the cleanest, most relevant representation of the technical truth.
58
+
59
+ ---
60
+
61
+ ## 🏛️ Multidisciplinary Value
62
+
63
+ Semantic-Sift is a strategic layer designed to manage attention across four key professional personas:
64
+
65
+ * **For the Senior Engineer:** A local-first, low-latency middleware using a dual-engine approach (Heuristic Sieve + Neural Reranker). It refined timestamps, repetitive boilerplate, and redundant JSON before they hit the wire, reducing latency and preventing "Lost in the Middle" reasoning failures.
66
+ * **For the Project Manager:** "Context Insurance." By reducing token overhead by 30-70%, Sift provides direct ROI on API costs and reduces the "retry loop" caused by model hallucinations in messy data environments.
67
+ * **For the Researcher:** Data integrity at scale. Supports **MarkItDown** (via the `[multi-modal]` optional extra) to convert complex `.pdf`, `.docx`, and `.xlsx` into structured, distilled Markdown, allowing for the rapid synthesis of massive technical repositories without losing critical semantic anchors.
68
+ * **For the Knowledge Partner:** Cognitive Load Management. Sift manages the friction of raw data ingestion, allowing the human-AI partnership to focus on high-level strategy and architectural decisions rather than manual data triage.
69
+
70
+ ---
71
+
72
+ ## 💰 Value Engineering: Operational vs. Economic ROI
73
+
74
+ Semantic-Sift provides a dual-layer of value. While the economic benefits depend on your billing plan, the operational benefits apply to every professional workflow.
75
+
76
+ #### 1. The Economic ROI (Direct Savings)
77
+ *Target: Users on Per-Token API plans (GPT-4o, Claude 3.5).*
78
+ * **Wallet Protection:** Sift acts as a local filter, typically reducing outgoing token volume by 30-70%.
79
+ * **Compound Interest:** In iterative agentic loops, these savings compound rapidly. Every character pruned is money that stays in your budget.
80
+
81
+ #### 2. The Operational ROI (Quality & Performance)
82
+ *Target: EVERYONE (including "Unlimited" or Per-Request subscription users).*
83
+ * **Attention Precision:** Even with "infinite" context, LLMs suffer from "Lost in the Middle" syndrome. By removing noise, you ensure the model's full reasoning power is focused on the technical signal, resulting in higher-quality code and fewer hallucinations.
84
+ * **Latency Reduction:** Smaller prompts = Faster "Time to First Token" (TTFT). You spend less time waiting for the "cloud" to process boilerplate and more time in your flow state.
85
+ * **Context Insurance:** Prevents "Context length exceeded" errors on complex tasks. Sift ensures that 100% of your model's limit is filled with **information**, not formatting.
86
+
87
+ ---
88
+
89
+ ## 📚 Master Documentation Index
90
+
91
+ All technical details, architectural logic, and integration guides are strictly maintained in the `doc/` directory to prevent data loss through summarization.
92
+
93
+ * **[doc/INDEX.md](doc/INDEX.md)**: The navigational roadmap and source of truth for the documentation structure.
94
+ * **[doc/ARCHITECTURE.md](doc/ARCHITECTURE.md)**: Specifications of the Sift Hook Interceptor, the Distillation Kernel (Heuristic/Semantic/Ranking engines), and Caching.
95
+ * **[doc/TOOL_REFERENCE.md](doc/TOOL_REFERENCE.md)**: Exhaustive operator's manual for all FastMCP tools (e.g., `sift_read_file`, `sift_logs`, `sift_chat`, `sift_rank`).
96
+ * **[doc/INTEGRATION_ENCYCLOPEDIA.md](doc/INTEGRATION_ENCYCLOPEDIA.md)**: Master Compatibility Map, Hook Injector logic, Payload Structures, and the **Master Configuration Matrix** for connecting IDEs (Cursor, Gemini, VS Code, OpenCode, etc.).
97
+ * **[doc/TELEMETRY_SPEC.md](doc/TELEMETRY_SPEC.md)**: Design of the OpenTelemetry tracing, Echo-Detector (Double-Sifting Prevention), Audit Headers, and Privacy controls.
98
+ * **[doc/ORCHESTRATION_BLUEPRINTS.md](doc/ORCHESTRATION_BLUEPRINTS.md)**: Actionable workflows for AI agents, including File Ingestion decision trees, Multi-Document RAG, and History Compaction.
99
+
100
+ ---
101
+
102
+ ## 🎯 High-Impact Use Cases
103
+
104
+ ### 📚 The Knowledge Hunter (Researchers & Architects)
105
+ * **The Pain**: Reading 50-page PDFs, complex Word specs, or cluttered documentation sites.
106
+ * **The Sift**: Supports **MarkItDown** via the `[multi-modal]` optional extra to natively ingest `.pdf`, `.docx`, and `.xlsx`. It converts corporate "noise" into structured Markdown, allowing your agent to synthesize multiple 14MB documents in a single turn.
107
+
108
+ ### 🛠️ The Log Hunter (DevOps & SREs)
109
+ * **The Pain**: Finding a single error in 100,000 lines of technical logs.
110
+ * **The Sift**: The **Heuristic Sieve** refines timestamps and boilerplate in milliseconds. The **Subconscious Hook** automatically reranks results, so your agent only sees the most relevant data blocks.
111
+
112
+ ### 🧠 The Context Strategist (AI Engineers)
113
+ * **The Pain**: LLM hallucination and reasoning degradation caused by messy data streams.
114
+ * **The Sift**: By delivering high-density context with 95% of the meaning preserved, Sift acts as a **Cognitive Bridge**. It ensures your LLM's attention is focused exclusively on the signal.
115
+
116
+ ---
117
+
118
+ ## 🚀 Quick Start
119
+
120
+ ### 1. Installation
121
+ Clone the repository and install:
122
+ ```bash
123
+ git clone https://github.com/luismichio/semantic-sift.git
124
+ cd semantic-sift
125
+ # Dedicated environment (Recommended)
126
+ python -m venv venv
127
+ .\venv\Scripts\activate
128
+ pip install .
129
+ ```
130
+
131
+ ### 🐍 Python Environment Guidance
132
+
133
+ Choosing the right Python path for your MCP configuration is critical for stability:
134
+
135
+ | Setup Type | Path Example | Pros | Cons |
136
+ | :--- | :--- | :--- | :--- |
137
+ | **Dedicated Venv** | `.../semantic-sift/venv/Scripts/python.exe` | **Isolated dependencies**, no version conflicts with other tools. | Slightly more disk space. |
138
+ | **Global Python** | `C:/Users/User/AppData/Local/.../python.exe` | Shared libraries, fast setup. | High risk of version conflicts (e.g., `transformers` mismatches). |
139
+
140
+ **Recommendation:** Always use the **Dedicated Venv** path in your `mcp_config.json` to ensure the sifting kernel is isolated and reliable.
141
+
142
+ For full semantic/reranking features (LLMLingua, Transformers, sentence-transformers):
143
+ ```bash
144
+ pip install .[neural]
145
+ ```
146
+
147
+ > **Note on Orchestration:** Semantic-Sift is an "Intelligence Kernel." For complex multi-tool workflows, we strongly recommend installing [Context-Pipe](https://github.com/luismichio/context-pipe), the universal switchboard that natively routes data to Semantic-Sift without blocking your IDE.
148
+
149
+ For development tools (mypy, pytest):
150
+ ```bash
151
+ pip install .[dev]
152
+ ```
153
+
154
+ ### 2. Connect the MCP
155
+
156
+ > **CRITICAL**: For exact configuration paths for Cursor, Gemini, OpenCode, VS Code, and Claude, reference the **[Master Configuration Matrix](doc/MCP_CONFIG_EXAMPLES.md)**.
157
+
158
+ ### 3. Auto-Onboard
159
+ Once connected, ask your AI Assistant:
160
+ > *"Run `sift_onboard()` to configure this project."*
161
+
162
+ ---
163
+
164
+ ## 📊 Telemetry & Management Commands
165
+
166
+ Semantic-Sift operates invisibly, but you can always audit its performance and token savings without burning LLM tokens to do so.
167
+
168
+ * **Terminal CLI**:
169
+ * Run `semantic-sift-stats` to print a global dashboard of your token savings, latency, and cache hits.
170
+ * Run `semantic-sift-onboard` to manually initialize Sift in any project (supports `--env` and `--dry-run`).
171
+ * **MCP Prompts**: Compatible clients (Claude Desktop, Cursor, Zed) will surface a `sift_dashboard` prompt in their UI (often via a slash command or button) to instantly inject your telemetry stats into the chat.
172
+ * **OpenCode & Gemini CLI**: The `sift_onboard()` tool automatically injects native `/sift-stats` and `/sift-onboard` custom slash commands into your IDE configuration.
173
+
174
+ ---
175
+
176
+ ## 🦀 Native Rust Sidecar (Meechi & Desktop Apps)
177
+
178
+ For high-performance, local-first applications (like [Meechi](https://meechi.me)), Semantic-Sift provides a native Rust binary (`sift-core`). This sidecar is optimized for portability and speed, with zero Python dependencies.
179
+
180
+ ### 🔀 The Hybrid Engine (`semantic-sift-cli`)
181
+ To provide the best of both worlds, installing the Python package also exposes the `semantic-sift-cli` command. This acts as an **Intelligent Router**:
182
+ - For **short tasks** (<30,000 chars), it instantly shells out to the low-latency Rust `sift-core` (ONNX).
183
+ - For **massive batch tasks**, it dynamically loads the high-throughput PyTorch framework with Flash Attention to prevent memory explosion.
184
+
185
+ ### Feature Comparison
186
+
187
+ | Feature | Python MCP Server | Rust Sift-Core (Sidecar) |
188
+ | :--- | :---: | :---: |
189
+ | **Heuristic Log Sifting** | ✅ | ✅ (Native) |
190
+ | **Semantic Compression** | ✅ (PyTorch) | ✅ (ONNX) |
191
+ | **Multi-Modal Ingestion** | ✅ (via `[multi-modal]`) | ❌ (Text Only) |
192
+ | **Supported Formats** | .pdf, .xlsx, .docx, .html, .txt | .txt, .log, .out (Text) |
193
+ | **Startup Latency** | 3-5 seconds | **~10ms** |
194
+ | **Binary Size** | ~1.5GB (with models) | **~15MB** |
195
+
196
+ > **Note**: For native apps like Meechi, we recommend a **Tiered Ingestion** strategy: use the app's frontend (e.g., `pdf.js`) to extract text, then pipe it to the Rust sidecar for high-speed semantic sifting.
197
+
198
+ **[✨ View Native Sidecar Demo](./demo/)**
199
+
200
+ **Usage:**
201
+ ```bash
202
+ # Sift a log file instantly
203
+ cat app.log | sift-core logs
204
+
205
+ # Perform neural semantic compression
206
+ cat document.txt | sift-core semantic --model ./models/llmlingua2 --rate 0.4
207
+ ```
208
+
209
+ ---
210
+
211
+ ## 🤖 For AI Agents: Operational Protocol
212
+
213
+ If you are an AI Agent (e.g., Gemini CLI, Cursor, Claude Code) reading this repository, follow this protocol:
214
+
215
+ 1. **Initialization**: Call `sift_onboard()` to register background hooks. Use `sift_onboard(dry_run=True)` to preview all planned actions without writing any files.
216
+ 2. **Context Advisory**: Before reading large files (>1,000 chars), call `sift_analyze_file(path)` to determine the noise ratio.
217
+ 3. **Mandatory Sifting**: If noise > 15%, pipe data through `sift_logs` or `sift_chat` before inclusion in reasoning. For documents, use `sift_doc(text, rate=0.4)` — adjust `rate` (0.1–0.9) to trade compression depth against fidelity.
218
+ 4. **Ranking**: Use `sift_rank` to identify the most semantically relevant chunks for the user's prompt.
219
+ 5. **Extraction**: When distilling PDFs or scraped content, use `sift_extraction(content, show_diff=True)` to see exactly what was removed and verify faithfulness.
220
+
221
+ ---
222
+
223
+ ## 🛡️ Security & Testing
224
+
225
+ Semantic-Sift is built on a **Zero-Vulnerability Baseline**:
226
+ - **Pytest**: 100% pass rate on heuristic integrity.
227
+ - **Bandit (SAST)**: Automated static analysis for Python patterns.
228
+ - **Pip-Audit (SCA)**: Real-time supply chain monitoring for 0 known vulnerabilities.
229
+
230
+ Privacy and telemetry controls:
231
+ - Set `SIFT_TELEMETRY_DISABLED=true` to disable telemetry entirely.
232
+ - Set `SIFT_TELEMETRY_URL=https://your-endpoint` to route metadata pulses to your own endpoint.
233
+ - Set `SIFT_PULSE_RATE_LIMIT_S=10` (default) to control async telemetry pulse frequency.
234
+
235
+ Security controls:
236
+ - Set `SIFT_ALLOW_GLOBAL_READS=true` to permit `sift_read_file` / `sift_analyze_file` outside the workspace root (path traversal guard is on by default).
237
+
238
+ Performance controls:
239
+ - Set `SIFT_HOOK_TIMEOUT_MS=3000` to cap hook semantic latency before heuristic fallback.
240
+ - Set `SIFT_MODEL_READY_WAIT_MS=1200` to control semantic model warm-up wait time before returning heuristic-mode output.
241
+ - Set `SIFT_COMPACTION_FIDELITY_THRESHOLD=0.3` (default) to control the vocabulary-overlap threshold below which a low-fidelity compaction warning is emitted.
242
+
243
+ Hook logging controls:
244
+ - Set `SIFT_LOG_FILE` to override the hook log path (default: `.gemini/sift_debug.log`).
245
+ - Set `SIFT_LOG_LEVEL` (`DEBUG`, `INFO`, `WARNING`, `ERROR`) to control hook log verbosity.
246
+
247
+ See [SECURITY.md](SECURITY.md) for our full security policy.
248
+
249
+ Telemetry schema and endpoint details are documented in [doc/TELEMETRY_SPEC.md](doc/TELEMETRY_SPEC.md).
250
+
251
+ ---
252
+
253
+ ## 🔗 The Ecosystem (Studio of Two)
254
+
255
+ Semantic-Sift is a flagship member of the **Studio of Two** infrastructure. It is designed to work in high-fidelity harmony with:
256
+
257
+ * **[Context-Pipe](https://github.com/luismichio/context-pipe)**: The universal switchboard for context engineering. While Sift provides the intelligence, Context-Pipe provides the orchestration. We highly recommend using Context-Pipe to chain Sift nodes with masking, search, and multi-modal ingestion tools.
258
+
259
+ ---
260
+
261
+ ## ⚖️ Licensing
262
+ Semantic-Sift is licensed under the **Apache License 2.0**. See [LICENSE.md](LICENSE.md) for details.
263
+
264
+ ## 🤝 Contributing
265
+ **Semantic-Sift is Open Source, but Closed to Contributions.**
266
+
267
+ To maintain the strict architectural vision of the "Studio of Two" and keep maintenance overhead at absolute zero, this repository does not accept external pull requests. We encourage you to use, embed, and fork the code under the permissive Apache 2.0 license, but please do not submit PRs for new features or bug fixes. See [CONTRIBUTING.md](CONTRIBUTING.md) for details.