openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(tauri): support workspace file links

Open YOMXXX opened this issue 6 months ago • 12 comments

Summary

  • Adds safe Tauri IPC commands for opening, revealing, and previewing active-workspace files.
  • Adds frontend workspace: / openhuman-workspace: link parsing and routes chat markdown workspace links through the new Tauri command.
  • Keeps raw file:// markdown links blocked and preserves existing external http(s) / mailto: handling.
  • Documents the new workspace file-link IPC surface.

Problem

Agents and UI surfaces can reference files produced under the OpenHuman workspace, but the desktop app did not have a safe first-party path for handling those workspace file links. Using raw filesystem URLs would either be blocked by the existing link policy or risk bypassing workspace boundaries.

Solution

  • Introduce open_workspace_path, reveal_workspace_path, and preview_workspace_text Tauri commands.
  • Resolve only workspace-relative paths against the active OpenHuman workspace, canonicalize the target, and reject absolute paths, traversal, URI/drive prefixes, missing targets, and symlink escapes.
  • Add frontend helpers to parse workspace schemes and Tauri invoke wrappers that return camelCase preview payloads.
  • Update chat markdown link rendering so workspace links survive react-markdown URL filtering and are dispatched through the guarded Tauri command.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • [x] Diff coverage ≥ 80% — not run locally; CI coverage gate is authoritative and will fail this PR if changed-line coverage is below 80%.
  • [x] Coverage matrix updated — N/A: no existing feature row for workspace markdown/file-link IPC; focused tests added with the implementation.
  • [x] All affected feature IDs from the matrix are listed in the PR description under ## Related — N/A: no matrix feature ID applies.
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy)
  • [x] Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: no release smoke flow changes.
  • [x] Linked issue referenced in ## Related; Phase 3 Memory follow-up is tracked in #2492

Impact

  • Desktop/Tauri: adds three read/open-only workspace file commands behind the dedicated allow-workspace-files permission.
  • Frontend/chat: workspace markdown links now open through the OS only after Rust validates the target remains inside the active workspace.
  • Security: raw file:// links remain blocked; Rust canonicalization guards against path traversal and symlink escapes.
  • Compatibility: existing external link handling is preserved.

Related

  • Refs #1402
  • Follow-up: #2492 tracks Phase 3 Memory surface migration onto the shared workspace-link layer
  • Follow-up PR(s)/TODOs: add richer in-app preview UI for preview_workspace_text once the file-view surface is designed.

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

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: feat/1402-workspace-file-links
  • Commit SHA: 3c7bbe97

Validation Run

  • [x] pnpm --filter openhuman-app format:check (via pre-push hook)
  • [x] pnpm typecheck (pnpm --filter openhuman-app compile)
  • [x] Focused tests: pnpm --filter openhuman-app test:unit src/utils/workspaceLinks.test.ts src/utils/tauriCommands/workspacePaths.test.ts src/pages/conversations/components/AgentMessageBubble.test.tsx (11 passed)
  • [x] Rust fmt/check (if changed): cargo fmt --manifest-path app/src-tauri/Cargo.toml -- --check; GGML_NATIVE=OFF cargo check --manifest-path app/src-tauri/Cargo.toml; pre-push pnpm --filter openhuman-app rust:check
  • [x] Tauri fmt/check (if changed): GGML_NATIVE=OFF cargo test --manifest-path app/src-tauri/Cargo.toml workspace_paths::tests (6 passed)
  • [x] Additional focused lint: pnpm --filter openhuman-app exec eslint src/utils/workspaceLinks.ts src/utils/workspaceLinks.test.ts src/utils/tauriCommands/workspacePaths.ts src/utils/tauriCommands/workspacePaths.test.ts src/pages/conversations/components/AgentMessageBubble.tsx src/pages/conversations/components/AgentMessageBubble.test.tsx
  • [x] Whitespace: git diff --check

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: chat markdown can use workspace: or openhuman-workspace: links to open workspace-contained files through guarded Tauri commands.
  • User-visible effect: users can click agent-produced workspace file links instead of copying paths manually.

Parity Contract

  • Legacy behavior preserved: existing http:, https:, and mailto: links still route through openUrl; raw file:// links remain blocked.
  • Guard/fallback/dispatch parity checks: frontend rejects unsafe workspace hrefs before invoke; Rust independently validates canonical target containment before opening/revealing/previewing.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • New Features

    • Markdown now supports workspace file links so users can open, reveal, and preview files inside the active workspace directly from messages and tables.
  • Documentation

    • Desktop host docs updated with architecture details and a workspace file-links command reference.
  • Tests

    • Added end-to-end tests for workspace link parsing, UI link handling, file preview behavior, and path safety.
  • Chores

    • Desktop permissions updated to allow workspace file actions.

Review Change Stack

YOMXXX avatar May 22 '26 03: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
📝 Walkthrough

Walkthrough

Adds frontend workspace-scheme parsing, TypeScript Tauri wrappers, Tauri backend commands (open/reveal/preview) with canonical containment checks and UTF-8 previewing, permission entries, markdown link routing in chat, docs, and tests.

Changes

Workspace File Links and Path Operations

Layer / File(s) Summary
Workspace link parsing utilities and tests
app/src/utils/workspaceLinks.ts, app/src/utils/workspaceLinks.test.ts
Parses workspace: / openhuman-workspace: hrefs into normalized relative paths, rejecting traversal, null bytes, drive-like inputs, and unsafe segments; tests validate accepted variants and rejections.
Tauri backend workspace path commands
app/src-tauri/src/lib.rs, app/src-tauri/src/workspace_paths.rs
Implements open_workspace_path, reveal_workspace_path, and preview_workspace_text with workspace-root resolution, input normalization, canonicalization containment checks, UTF-8 preview/truncation logic, and unit tests covering safety and truncation.
Tauri permissions configuration
app/src-tauri/capabilities/default.json, app/src-tauri/permissions/allow-workspace-files.toml
Adds allow-workspace-files permission listing the three workspace commands and includes it in the default capability.
Frontend Tauri command wrappers
app/src/utils/tauriCommands/workspacePaths.ts, app/src/utils/tauriCommands/workspacePaths.test.ts, app/src/utils/tauriCommands/index.ts
Exports typed wrappers that assert Tauri environment, invoke backend commands, and map Tauri snake_case responses to camelCase; tests verify gating and invocation.
Markdown link handling in chat
app/src/pages/conversations/components/AgentMessageBubble.tsx, app/src/pages/conversations/components/AgentMessageBubble.test.tsx
Adds transformMarkdownUrl and MarkdownAnchor to route workspace links to openWorkspacePath and allowed externals to openUrl; applied to BubbleMarkdown and TableCellMarkdown with interaction tests.
Architecture documentation
gitbooks/developing/architecture/tauri-shell.md
Expanded Tauri shell documentation, pointed IPC command registration to generate_handler!, added "Workspace file links" command group and updated core bridge description.
Cron store tests update
src/openhuman/cron/store_tests.rs
Adjusts test assertions to use job next_run timestamps and to verify disabled jobs are not returned at boundary timestamps.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • tinyhumansai/openhuman#2492 — Adds the shared workspace-link layer and Tauri backend/frontend plumbing referenced by the issue.

Suggested reviewers

  • M3gA-Mind

Poem

A rabbit tiptoed through the tree, 🐰 Mapping paths so safely, free, Links now whisper workspace names, Open, reveal, preview frames— Click with trust and hop with glee! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(tauri): support workspace file links' clearly and concisely describes the main change—adding Tauri IPC commands and frontend support for workspace-scoped file links, which is the core purpose of this PR.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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


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 22 '26 03:05 coderabbitai[bot]

Clarification for the CodeRabbit pre-merge note: the German i18n additions are intentional CI-gate cleanup, not a separate feature. pnpm i18n:check failed on this PR because de was missing the MCP-server keys and two existing subconscious keys; adding those translations brought the locale back to 0 missing keys and unblocked test / i18n Coverage.

YOMXXX avatar May 22 '26 03:05 YOMXXX

CI is green and the CodeRabbit threads are resolved. Ready for reviewer pass / merge when convenient.

YOMXXX avatar May 22 '26 03:05 YOMXXX

@graycyrus Could you take a reviewer pass on this when convenient? CI is green, CodeRabbit is approved, and there are no unresolved review threads on the PR. The German i18n additions are only to satisfy the current i18n gate.

YOMXXX avatar May 22 '26 04:05 YOMXXX

@YOMXXX can you resolve merge conflicts?

oxoxDev avatar May 22 '26 09:05 oxoxDev

@oxoxDev Merge conflicts are resolved in 08df631c by merging latest upstream/main into the PR branch.

Local validation run before push:

  • pnpm i18n:check passed
  • pnpm --filter openhuman-app test -- ... completed the Vitest suite: 320 files / 3088 tests passed
  • GGML_NATIVE=OFF cargo test --manifest-path app/src-tauri/Cargo.toml workspace_paths -- --nocapture passed: 7 tests
  • pre-push with GGML_NATIVE=OFF passed: format, lint (0 errors / existing warnings), TypeScript compile, Tauri rust check, command-token lint

CI has restarted and is currently in progress.

YOMXXX avatar May 22 '26 10:05 YOMXXX

@oxoxDev Conflicts are resolved and the follow-up CI is green now. I also hardened the flaky cron due-jobs boundary test that caused the previous Rust Core Coverage failure; Rust Core Coverage, Coverage Gate, Deploy Smoke, E2E, build, TypeScript, and Rust quality are all passing on 0b2c416e.\n\nNo unresolved review threads remain. Ready for reviewer pass when convenient.

YOMXXX avatar May 22 '26 11:05 YOMXXX

Review blockers addressed in 1af1c1ea.

  • Changed the PR relationship from Closes #1402 to Refs #1402 so the parent issue is not auto-closed prematurely.
  • Opened #2492 to track the remaining Phase 3 Memory surface migration onto the shared workspace-link layer.
  • Added [workspace-paths] warn/debug diagnostics around validation, resolution, open/reveal, and preview paths.
  • Logged workspace-link open failures in chat markdown and added a rejection-path component test.

Validation run:

  • pnpm --filter openhuman-app test:unit src/pages/conversations/components/AgentMessageBubble.test.tsx passed: 5 tests.
  • pnpm --filter openhuman-app exec eslint src/pages/conversations/components/AgentMessageBubble.tsx src/pages/conversations/components/AgentMessageBubble.test.tsx --ext .tsx passed.
  • GGML_NATIVE=OFF cargo test --manifest-path app/src-tauri/Cargo.toml workspace_paths -- --nocapture passed: 7 tests.
  • git diff --check passed.
  • Pre-push passed: format, lint, TypeScript compile, Tauri rust check, command-token lint.

YOMXXX avatar May 22 '26 13:05 YOMXXX

Synced latest upstream/main in 2b5bd3c6 and fixed the German i18n duplicate keys that caused the prior TS1117 typecheck failure on the PR merge ref.

Local validation before push:

  • pnpm --filter openhuman-app compile passed.
  • pnpm i18n:check passed with 0 missing / 0 extra keys.
  • pnpm --filter openhuman-app test:unit src/pages/conversations/components/AgentMessageBubble.test.tsx passed: 5 tests.
  • GGML_NATIVE=OFF cargo test --manifest-path app/src-tauri/Cargo.toml workspace_paths -- --nocapture passed: 7 tests.
  • git diff --check passed.
  • Pre-push passed: format, lint, TypeScript compile, Tauri rust check, command-token lint.

CI has restarted on the new head.

YOMXXX avatar May 22 '26 14:05 YOMXXX

Follow-up review fix pushed in 3c7bbe97.

  • Sanitized IPC-returned workspace path errors so they no longer expose absolute local paths; absolute paths remain available in debug logs.
  • Scoped colon rejection to leading URI/drive prefixes, allowing valid nested names like docs/2026:05.md.
  • Added Rust regression tests for sanitized errors, rejected file:// prefixes, and accepted nested-colon paths.

Validation:

  • GGML_NATIVE=OFF cargo test --manifest-path app/src-tauri/Cargo.toml workspace_paths -- --nocapture passed: 11 tests.
  • pnpm --filter openhuman-app compile passed.
  • git diff --check passed.
  • Pre-push passed: format, lint, TypeScript compile, Tauri rust check, command-token lint.

YOMXXX avatar May 22 '26 14:05 YOMXXX

@M3gA-Mind Ready for re-review.

Current state:

  • all CI checks are green on latest head 3c7bbe97
  • all review threads are resolved
  • Closes #1402 was changed to Refs #1402
  • Phase 3 Memory-surface migration is tracked separately in #2492
  • workspace path logging and open-failure logging were added in 1af1c1ea
  • the follow-up CodeRabbit findings were handled in 3c7bbe97 (sanitized IPC errors, allowed nested : path segments) and CodeRabbit approved

YOMXXX avatar May 22 '26 14:05 YOMXXX

@M3gA-Mind Required checks are green again, all review threads are resolved, and the latest review fixes remain in 3c7bbe97:

  • Closes #1402 is now Refs #1402
  • Phase 3 Memory-surface migration is tracked in #2492
  • workspace path diagnostics and open-failure logging are in place
  • IPC workspace path errors are sanitized and colon handling is narrowed to leading URI/drive prefixes

Could you take another reviewer pass when convenient?

YOMXXX avatar May 23 '26 01:05 YOMXXX