Skip to content

Commit 0d366f1

Browse files
committed
fix(opencode): refactor native plugin to be shape-aware (anomalyco/opencode#25918)
1 parent 6de331a commit 0d366f1

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ test_sift.py
4747
.pipe_identity
4848
.pipe_telemetry.json
4949
.pipe_cache/
50+
doc/posts/

‎BACKLOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ data = detector.inject(data, sifted, sift_notification) if detector else data
127127
- [ ] **Knapsack Context Optimizer (`sift_pack`)**: 0/1 Knapsack DP algorithm to select the optimal combination of text chunks maximising semantic relevance within a token limit.
128128
- [ ] **`reranker-core` (Rust/ONNX)**: Port the BGE-Reranker to a standalone Rust sidecar to complete the zero-Python Intelligence Tier.
129129

130+
### Native Mobile Integration (Capacitor)
131+
**Observation**: Meechi is a multi-platform digital space (Desktop/Mobile). On Desktop, it uses `sift-core` as a sidecar, but OS security on mobile (iOS/Android) prevents this architectural pattern.
132+
133+
- [ ] **Native Mobile Plugin**: Refactor `sift-core` to be compiled as a static library (`.a` for iOS) or dynamic library (`.so` for Android).
134+
- [ ] **UniFFI Bindings**: Use UniFFI to generate Swift and Kotlin bindings for the `SemanticEngine` and `apply_heuristic_sieve`.
135+
- [ ] **Capacitor Bridge**: Implement a Capacitor Native Plugin that wraps the Rust library, enabling zero-Python context distillation in the mobile version of Meechi.
136+
- [ ] **Mobile Execution Providers**: Enable `CoreML` (iOS) and `NNAPI` (Android) execution providers in the `ort` crate configuration to leverage mobile NPUs.
137+
130138
### Multi-Parser Registry
131139
- [ ] Implement dynamic discovery engine in both Python and Rust to support `markitdown`, `pandoc`, and `LlamaIndex` as swappable ingestion nodes.
132140

@@ -147,6 +155,10 @@ data = detector.inject(data, sifted, sift_notification) if detector else data
147155
## ✅ Completed
148156

149157
### v0.3.0 (unreleased — next publish target)
158+
- [x] **crates.io Publication**: `semantic-sift-core` v0.3.0 published as a standalone high-performance primitive.
159+
- [x] **Native Engine Documentation**: Created comprehensive `crates/sift-core/README.md` with hybrid architecture details, Meechi origin story, and promotion-ready badges.
160+
- [x] **Tauri Promotion Manifest**: Drafted engineering-focused community promotion material in `doc/posts/tauri_show_and_tell.md`.
161+
- [x] **OpenCode Plugin Shape-Awareness**: Refactored the generated OpenCode TypeScript plugin to be "shape-aware," handling both Native tool (`output.result`) and MCP tool (`output.content`) response formats. Resolves silent failures for MCP tools (sst/opencode#25918).
150162
- [x] **Root-Module Inversion**: Canonical implementations moved to `semantic_sift/`; root stub files (`sift_kernel.py`, `sift_hook.py`, `telemetry_core.py`) deleted. All test imports updated. Zero DeprecationWarnings.
151163
- [x] **Telemetry Consent UX**: `_build_telemetry_disclosure()` surfaces opt-in/opt-out notice in every `apply_onboarding()` response.
152164
- [x] **Telemetry Fallback URL**: `SIFT_TELEMETRY_FALLBACK_URL` env var; silent retry on primary endpoint failure.

‎semantic_sift/hook_injector.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,40 @@ def update_instruction_files(
224224
return {{
225225
hooks: {{
226226
"tool.execute.after": async (input, output) => {{
227-
const rawContent = output.result;
228-
if (typeof rawContent !== 'string' || rawContent.length < 500) return;
227+
let rawContent = "";
228+
let isMCP = false;
229+
230+
// 1. Detect Shape (Resolves upstream bug: sst/opencode#25918)
231+
if (output.content && Array.isArray(output.content)) {{
232+
isMCP = true;
233+
rawContent = output.content.map((c: any) => c.text || "").join("\\n");
234+
}} else if (typeof output.result === 'string') {{
235+
rawContent = output.result;
236+
}} else if (typeof output.output === 'string') {{
237+
rawContent = output.output;
238+
}}
239+
240+
if (!rawContent || rawContent.length < 500) return;
229241
if (rawContent.includes("--- [Semantic-Sift: Native Execution] ---")) return;
242+
230243
try {{
231244
const pythonExe = "{python_exe}";
232245
const siftScript = "{hook_script}";
233246
const payload = {{ hook_event_name: "AfterTool", tool_name: input.tool, tool_args: input.args, tool_response: {{ llmContent: rawContent }} }};
234247
const response = await $`${{pythonExe}} ${{siftScript}}`.input(JSON.stringify(payload)).text();
235248
const siftedData = JSON.parse(response);
236-
if (siftedData?.tool_response?.llmContent) output.result = siftedData.tool_response.llmContent;
249+
250+
// 3. Mutate specific shape
251+
if (siftedData?.tool_response?.llmContent) {{
252+
const sifted = siftedData.tool_response.llmContent;
253+
if (isMCP) {{
254+
output.content = [{{ type: 'text', text: sifted }}];
255+
}} else if (typeof output.result === 'string') {{
256+
output.result = sifted;
257+
}} else if (typeof output.output === 'string') {{
258+
output.output = sifted;
259+
}}
260+
}}
237261
}} catch (error) {{ console.error("[Semantic-Sift Plugin] failed:", error); }}
238262
}}
239263
}}

0 commit comments

Comments
 (0)