Repository navigation
Description
Per docs/research/architecture_audit.md §3.6, §3.11, §4.3 (combined because both are IPC-type-boundary concerns).
Problem A: hand-written types.ts mirror has drifted
apps/desktop/src/types.ts is a hand-written TS mirror of specta bindings. The "SHA-256" vs BLAKE3 drift documented in §3.6 is proof the pattern produces latent bugs. Today's flow is a three-layer drift pipeline:
core type → specta wire-type → hand-written TS mirror
The #[cfg(debug_assertions)] gate on specta bindings export is Spacedrive's v1 anti-pattern; bindings.ts is ungit'd and unreviewable.
Fix A
- Delete
apps/desktop/src/types.tsentirely. Re-export frombindings.ts. - Always export bindings (drop
cfg(debug_assertions)gate). Commitbindings.tsto git. Add CI step that fails ifbindings.tshas a diff after a rebuild. - Unify the 8 wire types with the 7 domain types via feature-gated specta derives on
coredomain types:#[cfg_attr(feature = "specta", derive(specta::Type))]. This is the challenge to the "core has zero framework deps" hard exclusion — see §4.3; every Tauri 2 codebase surveyed (Cap, Hyprnote, AppFlowy, TauRPC) does this. - Eliminates ~300 LOC of wire-type duplication + hand-written
Fromimpls.
Problem B: Result<T, String> flattens typed errors at IPC
Tauri commands return Result<T, String> — loses the typed CoreError taxonomy at the frontend boundary. neverthrow gets a string, can't pattern-match, has to parse.
Fix B
Typed CoreError as a serde-tagged discriminated union via specta:
#[derive(Debug, thiserror::Error, Serialize, specta::Type)]
#[serde(tag = "kind", content = "data")]
pub enum CoreError {
#[error("not found: {0}")]
NotFound(String),
#[error("invalid input: {field}: {reason}")]
InvalidInput { field: String, reason: String },
// ...
}Tauri commands return Result<T, CoreError> directly — specta generates the TS discriminated union — the invoke call returns a typed union. Wrap once:
// ipc/invoke.ts
export const invokeResult = <T>(
cmd: (...args: any[]) => Promise<T>,
...args: any[]
): ResultAsync<T, CoreError> =>
ResultAsync.fromPromise(cmd(...args), (e) => e as CoreError);Dual-derive note
For HTTP (Phase 6), DTOs get #[derive(Serialize, Deserialize, specta::Type, ToSchema)] — accept the two-macro tax. specta-rs's JSON-schema export is experimental.
Rejected alternatives
- TauRPC — pins to specific specta RC; router abstraction duplicates AppContainer (see issue for
crates/appextract). - rspc — more ambitious; overkill for 13 Tauri commands.
- Switch specta → ts-rs — the keep-or-switch question is distraction; the correctness fix is architectural (re-export, don't mirror).
Source
docs/research/architecture_audit.md §3.6, §3.11, §4.3.
Execution hint
Can be split:
- A) Delete types.ts + always-export bindings + CI diff check (mechanical; wave-3 candidate).
- B) Typed CoreError union at IPC (brainstorm + plan; blocks on
crates/appextract for cleanest landing).
Activity