|
| 1 | +# Rust OXC Service |
| 2 | + |
| 3 | +## Traceability |
| 4 | +- Spec ID: rust-oxc-service |
| 5 | +- Status: Implemented |
| 6 | +- Request: split OXC into an XPC service; all extracted capability services must be written in Rust. |
| 7 | +- AI involvement: Codex implementation and local validation. |
| 8 | + |
| 9 | +## Intent |
| 10 | +Move desktop OXC native parsing and transformation into a supervised Rust |
| 11 | +executable. Preserve AgentReact profile checks, ABI extraction, semantic index, |
| 12 | +diagnostics and browser CLI compatibility. |
| 13 | + |
| 14 | +## Acceptance Scenarios |
| 15 | +- AC-1: Desktop uses the Rust service for every OXC parse/transform, with no OXC NAPI library loaded in the Studio process. A typed compiler factory passes through production artifact routes; the browser CLI retains its worker adapter. |
| 16 | +- AC-2: A versioned, strict, bounded JSONL stdio protocol carries request ids and parse/transform results. Invalid requests, unknown fields, oversized sources/frames and unsupported protocol versions fail closed. Native code receives source text, not filesystem authority. |
| 17 | +- AC-3: Deadline, crash, malformed output and close settle pending calls. Timeout/cancellation kills the affected process; a later compile starts a fresh process. Queues and buffers are bounded; no automatic replay of the failed request. |
| 18 | +- AC-4: Valid TSX (including non-ASCII text), refused profile examples, ABI/semantic index and source maps match the existing kernel. Profile refusal happens before requesting transformation. Compiler identity and outer artifact caches distinguish transports. |
| 19 | +- AC-5: Cargo locks OXC to 0.147.0; target-native Rust binaries ship outside ASAR. Native tests and the packaged macOS app prove real service calls and process separation. Windows/Linux build and smoke are wired into CI; unrun platforms remain unverified. |
| 20 | + |
| 21 | +## Design and Capability Matrix |
| 22 | +| Capability | Decision | |
| 23 | +| --- | --- | |
| 24 | +| Parse and transform | Rust service using pinned OXC crates | |
| 25 | +| Profile, ABI, semantic index | Existing JS semantic kernel, using a private backend port | |
| 26 | +| AST transfer | Bounded ESTree JSON inside the kernel/backend boundary only; never exposed to business callers or renderer. UTF-8 spans converted to UTF-16 for parity. | |
| 27 | +| Cancellation | Kill dedicated compiler process; synchronous native work cannot consume cancel messages while executing | |
| 28 | +| XPC transport | Cross-platform child process + framed JSONL stdio; native macOS NSXPC is not claimed | |
| 29 | +| Other future capability services | Rust executables; Studio remains the existing Node host runtime | |
| 30 | + |
| 31 | +## Non-goals |
| 32 | +No ACP extraction, semantic-rule rewrite, generic RPC registry, UI changes, |
| 33 | +macOS-only NSXPC bridge, signing, publication or auto-update changes. |
| 34 | + |
| 35 | +## Plan and Tasks |
| 36 | +1. Separate the native backend from semantic compilation without changing the |
| 37 | + existing default adapter. Keep constants available without importing NAPI. |
| 38 | +2. Add Rust parse/transform service and a supervised Node transport adapter. |
| 39 | +3. Inject compiler factory from desktop through Studio production routes; |
| 40 | + partition caches by factory and retain current OxcCompilerPort output. |
| 41 | +4. Package the Rust binary as an external resource; add Cargo/native/protocol |
| 42 | + parity checks and extend desktop smoke with actual Rust proof. |
| 43 | + |
| 44 | +## Test and Review Evidence |
| 45 | +Local macOS arm64 evidence on 2026-09-07: |
| 46 | + |
| 47 | +| Acceptance | Receipt | |
| 48 | +| --- | --- | |
| 49 | +| AC-1 | Packaged-app smoke records separate main, Studio and Rust PIDs; Studio process.report sharedObjects contains no OXC NAPI. Native HTTP test proves both build and preview routes call the injected compiler. | |
| 50 | +| AC-2 | Five Rust tests cover UTF-16 spans, TSX transform/source map, unknown methods/fields/versions, source limits, oversized/truncated frames and parse errors. Cargo.lock pins native dependencies. | |
| 51 | +| AC-3 | Native adapter tests exercise a hung child, exit code zero, malformed JSON, oversized stdout, cancellation, use after close and recovery with a real Rust process. Desktop tracks active compilers and closes them before stopping Studio. | |
| 52 | +| AC-4 | Seven native integration tests include parity with NAPI over valid and refused inputs, Unicode, generated code and parsed source maps; profile refusal makes zero transform calls. Artifact cache regression proves different factories cannot share cached builds. | |
| 53 | +| AC-5 | Full desktop build/stage/pack and packaged macOS arm64 smoke pass. Binary ships outside ASAR. Cargo tests, native integration tests and packaged smoke are wired into the three-platform CI matrix. | |
| 54 | +| Regression | AgentReact/artifact/auth selection: 182 passing tests before adding the cache case. Final artifact/project/server selection: 70 passing tests including that new case. These overlap and are not additive. Six desktop lifecycle tests and eight docs-link tests also pass. | |
| 55 | + |
| 56 | +Commands: `npm run test:rust -w @qoder-ai/harness-desktop`, |
| 57 | +`npm run test:native -w @qoder-ai/harness-desktop`, |
| 58 | +`npm exec -w @qoder-ai/harness-studio -- vitest run test/agent-react test/artifact-compile-runtime.test.ts test/desktop-authorization.test.ts`, |
| 59 | +`npm exec -w @qoder-ai/harness-studio -- vitest run test/artifact-compile-runtime.test.ts test/project-server.test.ts test/server.test.ts`, |
| 60 | +`CSC_IDENTITY_AUTO_DISCOVERY=false npm run harness-desktop:pack`, |
| 61 | +`npm run smoke -w @qoder-ai/harness-desktop -- --packaged`. |
| 62 | + |
| 63 | +Generated native and screenshot/JSON receipts live under the desktop package's |
| 64 | +ignored `dist/`. Windows/Linux jobs have not run here; no signed release or |
| 65 | +native Apple NSXPC acceptance is claimed. Existing Studio npm dependencies retain |
| 66 | +NAPI for browser/CLI compatibility, but the desktop does not load or fall back |
| 67 | +to those modules. AST serialization adds bounded transport overhead; no speedup |
| 68 | +is claimed. Source-map object content matches; JSON property ordering is not a |
| 69 | +semantic equality requirement. |
| 70 | + |
| 71 | +Review Readiness Check: user request and spec confirmed; no Story supplied. |
| 72 | +The Electron baseline is committed as 3920fd1. This Rust slice is reviewed separately from the baseline: native service/lockfile, semantic-backend seam, supervised |
| 73 | +adapter, factory routing/cache isolation, desktop packaging/smoke, architecture |
| 74 | +rule and tests. No ACP implementation or UI change is included. No generated |
| 75 | +runtime artifacts are staged; no publication is performed. |
0 commit comments