openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

refactor(memory): route Obsidian deep link through workspace-link layer (#2492)

Open YOMXXX opened this issue 6 months ago • 4 comments

Summary

  • New Tauri command resolve_workspace_absolute_path exposes the workspace-link resolver introduced in #2476 so renderers can derive canonical absolute paths through the same guard as open_workspace_path / reveal_workspace_path / preview_workspace_text.
  • New TS wrapper resolveWorkspaceAbsolutePath in utils/tauriCommands/workspacePaths.ts.
  • ObsidianVaultSection now resolves the vault's absolute path through that wrapper before building the obsidian://open?path=<abs> URL, replacing the last Memory-tab surface that was constructing the deep link straight from a graph-export RPC field.
  • User-visible behavior is unchanged — click still opens Obsidian to the vault, same toast copy — but the absolute path is now derived from the Rust-side resolver, not from a prop fed by RPC.

Problem

Issue #2492 (Phase 3 cleanup of #1402) requires every Memory surface that constructs an on-disk path to compose with the shared workspace-link layer rather than hand-rolling its own resolution.

MemoryGraph was migrated in PR #2638. The remaining offender was ObsidianVaultSection, which built obsidian://open?path=${encodeURIComponent(contentRootAbs)} directly from the content_root_abs field returned by memory_tree_obsidian_vault_status — no canonicalize, no workspace-containment recheck, no shared error surface. Acceptance criterion from the issue:

Obsidian behavior is preserved intentionally — Obsidian launch remains available where it is a user-facing feature, but it is composed with the shared workspace-link layer rather than replacing it.

Solution

Three layers, kept thin:

  1. Rust (app/src-tauri/src/workspace_paths.rs): new resolve_workspace_absolute_path #[tauri::command] that wraps the existing internal resolve_workspace_path helper (same canonicalize + workspace-containment + non-leaky error surface as the other three commands). Registered in lib.rs and added to the allow-workspace-files permission manifest. Two new unit tests cover the happy-path (memory_tree/content resolves inside the workspace root) and the empty-input rejection; the existing resolver test suite already covers absolute-path / .. / URI-scheme / symlink escapes.
  2. TypeScript (app/src/utils/tauriCommands/workspacePaths.ts): resolveWorkspaceAbsolutePath(path) wrapper mirroring the style of the other workspace wrappers (assertTauri guard + plain invoke<string>).
  3. Component (app/src/components/intelligence/ObsidianVaultSection.tsx): fireDeepLink now awaits resolveWorkspaceAbsolutePath('memory_tree/content') and builds the URL from the returned absolute path. The contentRootAbs prop is preserved for display (button tooltip, guidance-panel code block, toast message text) so no cascading prop changes are needed — only the deep-link URL is rerouted.

Tests

Updated ObsidianVaultSection.test.tsx:

  • Mock the new wrapper in the existing workspacePaths mock block.
  • New test: deep link URL is composed from the resolver output (not from contentRootAbs).
  • New test: resolver rejection surfaces an error toast and keeps the guidance panel expanded.
  • All 7 existing tests still pass (9 total).

Updated MemoryWorkspace.test.tsx:

  • Mock resolveWorkspaceAbsolutePath to return the same path the assertion expects so the existing 'View vault in Obsidian' triggers the deep link test stays stable. All 20 tests pass.

Submission Checklist

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • [x] Diff coverage ≥ 80% — every new line is exercised by the two new Vitest cases plus the existing happy-path test (now stricter via the resolver-call assertion) and the two new Rust unit tests. Resolver internals already covered by the prior resolve_workspace_path_* test suite.
  • [x] N/A: Coverage matrix update — this is a behaviour-preserving refactor of an existing matrix entry, not an added/removed/renamed feature row.
  • [x] N/A: No new feature IDs from the matrix affected.
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy)
  • [x] N/A: Manual smoke checklist — no release-cut surface touched; deep-link UX is unchanged from the user's point of view.
  • [x] Linked issue closed via Closes #2492 in the ## Related section.

Impact

  • Runtime/platform: desktop only (#[tauri::command] lives in the Tauri shell; iOS client does not hit this code path). No change to JSON-RPC surface.
  • Security: net positive — the Obsidian deep link now goes through the same workspace-containment guard as the other workspace commands, so a malicious content_root_abs value from the RPC (or a future scenario where the field is user-influenced) can no longer slip out of the workspace.
  • Migration / compatibility: none; the URL shape is identical.

Related

  • Closes #2492
  • Builds on #2476 (workspace-link layer) and #2638 (MemoryGraph migration)
  • Follow-up PR(s)/TODOs: none — this is the final Memory-tab surface called out in #2492.

AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A (GitHub issue only)
  • URL: https://github.com/tinyhumansai/openhuman/issues/2492

Commit & Branch

  • Branch: fix/2492-memory-workspace-link-migration
  • Commit SHA: 3682a02d (tip), 910d8097, 8ff810ba

Validation Run

  • [x] pnpm --filter openhuman-app format:check — equivalent: pnpm exec prettier --check on changed files, clean.
  • [x] pnpm typecheck — ran pnpm exec tsc --noEmit inside app/, clean.
  • [x] Focused tests: pnpm debug unit ObsidianVaultSection → 9 passed; pnpm debug unit MemoryWorkspace → 20 passed.
  • [x] Rust fmt/check (if changed): cargo fmt --manifest-path app/src-tauri/Cargo.toml --check clean; GGML_NATIVE=OFF cargo check --manifest-path app/src-tauri/Cargo.toml --lib clean (GGML_NATIVE=OFF is the documented macOS Tahoe + whisper-rs workaround).
  • [x] Tauri fmt/check (if changed): same as above.

Validation Blocked

  • command: n/a — all validation passed.
  • error: n/a
  • impact: n/a

Behavior Changes

  • Intended behavior change: deep-link absolute path is now derived from the workspace-link resolver instead of trusted RPC output.
  • User-visible effect: none. Same click, same Obsidian URL shape, same toast copy. The vault path printed in the guidance panel / toast still comes from contentRootAbs (RPC) because it is a display concern.

Parity Contract

  • Legacy behavior preserved: the obsidian://open?path=<abs> URL shape is byte-for-byte unchanged when the resolver returns the same path the RPC reports (normal case). MemoryWorkspace.test.tsx's existing assertion proves it.
  • Guard/fallback/dispatch parity checks: resolver failure now surfaces an error toast and keeps the guidance panel expanded — covered by a new test. Existing detection failure degrades gracefully to the guidance panel test still passes.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none
  • Canonical PR: this
  • Resolution: n/a

Summary by CodeRabbit

  • New Features

    • Added a workspace-path resolver that returns canonical absolute paths for constructing vault deep links.
  • Bug Fixes

    • Deep-link generation now uses resolved canonical workspace paths; on resolution failure it surfaces an error and does not attempt a fallback.
  • Tests

    • Added/updated tests for path resolution success, failure, canonicalization, and deep-link behavior.
  • Chores

    • Updated runtime permissions to allow workspace-path resolution.

Review Change Stack

YOMXXX avatar May 26 '26 15:05 YOMXXX

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9cbf5908-6e62-471e-89f8-0cfd17d46033

📥 Commits

Reviewing files that changed from the base of the PR and between a56c7f784a6ae2c18c8a22254d7d5d559b15e8d4 and b3288b3e3a5e8872778932336493047314c8cb3a.

📒 Files selected for processing (2)
  • app/src-tauri/src/workspace_paths.rs
  • app/src/components/intelligence/ObsidianVaultSection.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src-tauri/src/workspace_paths.rs

📝 Walkthrough

Walkthrough

This PR adds a new Tauri command resolve_workspace_absolute_path to canonicalize workspace-relative paths and uses it in ObsidianVaultSection to construct Obsidian deep links with normalized paths instead of relying on the contentRootAbs prop directly.

Changes

Workspace Absolute Path Resolver

Layer / File(s) Summary
Rust command implementation and permissions
app/src-tauri/permissions/allow-workspace-files.toml, app/src-tauri/src/workspace_paths.rs, app/src-tauri/src/lib.rs
Permission config allows resolve_workspace_absolute_path command. New Rust command loads workspace root, resolves input path via existing helpers, logs the mapping, and returns canonical absolute path. Tauri handler registration exposes it to IPC. Unit tests assert canonical path return and empty-input rejection.
TypeScript Tauri command wrapper
app/src/utils/tauriCommands/workspacePaths.ts, app/src/utils/tauriCommands/workspacePaths.test.ts
New exported resolveWorkspaceAbsolutePath function asserts Tauri runtime and invokes the Rust-side command, returning the resolved absolute path string. Tests cover success, invoke rejection propagation, and non-Tauri early rejection.
Obsidian deep-link resolution and tests
app/src/components/intelligence/ObsidianVaultSection.tsx, app/src/components/intelligence/__tests__/MemoryWorkspace.test.tsx, app/src/components/intelligence/__tests__/ObsidianVaultSection.test.tsx
ObsidianVaultSection now resolves MEMORY_CONTENT_WORKSPACE_PATH via the new command before constructing obsidian://open?path=... URLs. Tests mock the resolver and verify resolver invocation, correct deep-link URL composition, and error handling (error toast, no openUrl call, guidance panel visible on failure).

Sequence Diagram

sequenceDiagram
  participant User
  participant ObsidianVaultSection
  participant resolveWorkspaceAbsolutePath
  participant resolve_workspace_absolute_path
  participant ObsidianApp as openUrl
  User->>ObsidianVaultSection: click deep-link
  ObsidianVaultSection->>resolveWorkspaceAbsolutePath: resolve(MEMORY_CONTENT_WORKSPACE_PATH)
  resolveWorkspaceAbsolutePath->>resolve_workspace_absolute_path: invoke
  resolve_workspace_absolute_path-->>resolveWorkspaceAbsolutePath: canonical absolute path
  ObsidianVaultSection->>ObsidianApp: openUrl("obsidian://open?path="+resolvedPath)
  ObsidianApp-->>User: open vault

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • tinyhumansai/openhuman#1402: Matches the workspace-link Tauri command surface and frontend integration for canonicalizing workspace paths.

Possibly related PRs

  • tinyhumansai/openhuman#2476: Extends the same workspace_paths IPC surface; #2476 added open/reveal/preview commands that this PR builds upon.

Suggested labels

memory

Suggested reviewers

  • graycyrus
  • senamakel

Poem

🐰 I hop from path to path, precise and neat,
Canonical crumbs beneath my feet.
Deep links now find vaults with ease,
Tests nod in chorus, errors appease—
A rabbit's cheer for tidy trees.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: routing Obsidian deep-link URL composition through a shared workspace-link resolver instead of direct RPC usage, with reference to the related issue (#2492).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

[!WARNING] There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 26 '26 15:05 coderabbitai[bot]

Addressed CodeRabbit feedback in cffa53a5 + a8a11f6f:

  • Coverage Gate: added Vitest cases for resolveWorkspaceAbsolutePath in app/src/utils/tauriCommands/workspacePaths.test.ts covering the happy-path invoke call, an invoke rejection bubbling back to the caller, and the isTauri() guard short-circuiting before invoke is touched. That brings the new wrapper lines (workspacePaths.ts:56-58) under test.
  • PII log nit: routed the resolve_workspace_absolute_path debug log through the existing workspace_path_label(workspace, target) helper instead of target.display(), matching the redaction pattern the other workspace-path commands already use so the canonical absolute workspace root no longer leaks into logs.

Local verification: cargo fmt --check, cargo check --lib (Tauri shell), prettier --check, pnpm debug unit workspacePaths (12 passed), pnpm typecheck — all green.

YOMXXX avatar May 27 '26 00:05 YOMXXX

@YOMXXX unresolved review feedback — please address before we review.

graycyrus avatar May 27 '26 19:05 graycyrus

Unresolved review feedback from coderabbitai[bot] — please address before we review.

graycyrus avatar May 27 '26 19:05 graycyrus