Repository navigation
feat: add initial deep link implementation - #1584
Conversation
|
@claude deep review please |
|
Claude finished @kantord's task in 1m 50s —— View job Deep Review Complete ✓I've completed a thorough review of the deep link implementation. This is a well-architected feature with strong foundations. Below are my detailed findings organized by severity. 🔴 Critical Issues1. Window Readiness Race ConditionLocation: The TODO comment correctly identifies a critical issue - Problem: The renderer performs async initialization (fetching ToolHive port, creating router) after HTML loads. If a deep link arrives during cold start, Recommendation: Implement an explicit readiness signal from the renderer:
Impact: Deep links clicked from external sources (email, web browser) when the app isn't running may fail to navigate properly. 🟡 High Priority Issues2. Error Handling in Deep Link HandlerLocation: When Recommendation: } catch (error) {
log.error('[deep-link] Window did not become ready:', error)
// Still attempt to send show-not-found as a fallback
sendToMainWindowRenderer(IPC_CHANNEL, {
version: showNotFound.version,
intent: showNotFound.intent,
params: {},
})
return
}3. Missing Comprehensive Integration TestsLocation: Test coverage While
Recommendation: Add integration tests or E2E tests covering the full deep link flow, especially cold-start scenarios. 🟢 Medium Priority Issues4. Parameter Stripping BehaviorLocation: Test line 109 states "Zod strips unknown keys by default" but this is incorrect. Zod's default behavior is to pass through unknown keys unless Current behavior: Extra params are silently ignored (passed through). Recommendation: Either:
5. Inconsistent Error MessagesLocation: Line 20 logs Recommendation: Standardize error message format, e.g., always prefix with 6. No Validation of Navigation TargetsLocation: The renderer trusts that Recommendation: Add try-catch around 🔵 Low Priority / Nice-to-Have7. Limited Deep Link Intent CoverageCurrently only Suggestions:
8. Deep Link AnalyticsLocation: All deep link handlers No telemetry/analytics tracking for deep link usage. Consider adding Sentry breadcrumbs or analytics events to understand:
9. Documentation: Windows Registry PersistenceLocation: The README explains how to test deep links on Linux but doesn't mention that Windows requires either:
Recommendation: Add a Windows section to the testing guide. 10. Type Safety GapLocation: const target = deepLinkDef.navigate(deepLink.params as never)The Recommendation: Consider using a discriminated union or type guards to avoid the cast. ✅ StrengthsThis implementation has several excellent qualities:
📋 SummaryThis is a high-quality implementation that follows Electron best practices. The architecture is extensible and maintainable. The main concerns are:
The security posture is strong, and the code is well-structured. Once the window readiness issue is addressed and comprehensive tests are added, this feature will be production-ready. Files Reviewed: 13 files (parse.ts, parse.test.ts, intents.ts, index.ts, squirrel.ts, main.ts, forge.config.ts, preload.ts, renderer.tsx, electronAPI.ts, vitest.setup.ts, README.md, main-window.ts) |
b524b68 to
7217723
Compare
|
@claude please do a deep review |
f485105 to
979a616
Compare
|
@claude please do a deep review |
|
Claude finished @kantord's task in 2m 44s —— View job Deep Review Complete ✓I've conducted a thorough analysis of the deep link implementation across all 15 changed files. This is a well-architected feature with strong foundations. Below are my detailed findings organized by severity. 🔴 Critical Issues1. Window Readiness Race Condition (Already Noted in TODO)Location: The TODO comment correctly identifies a critical issue: Problem: The renderer performs async initialization (fetching ToolHive port, creating router) after the HTML loads. If a deep link arrives during cold start, Evidence: In
If the main process dispatches a deep link before step 3 completes, the Recommendation:
Impact: Deep links clicked from external sources (email, browser) when the app isn't running will fail to navigate. 🟡 High Priority Issues2. Silent Failure When Window Readiness Times OutLocation: When Current behavior: } catch (error) {
log.error('[deep-link] Window did not become ready:', error)
return // Silent failure
}Recommendation: } catch (error) {
log.error('[deep-link] Window did not become ready:', error)
// Still send show-not-found as fallback so user gets feedback
const fallbackTarget = showNotFound.navigate({})
sendToMainWindowRenderer(IPC_CHANNEL, fallbackTarget)
return
}3. Misleading Test Comment About Zod BehaviorLocation: Line 109 states "Zod strips unknown keys by default" but this is incorrect. Zod's default behavior with Test name: Actual behavior: Extra params are not stripped, they're passed through. The schema doesn't reject them. Security consideration: If future code assumes params only contain declared fields, unexpected keys could cause issues or bypass validation. Recommendation: Choose one approach and be explicit: Option A - Reject unknown params: // In common/deep-links.ts, line 24
schema: z.object({
version: z.literal(VERSION),
intent: z.literal(config.intent),
params: config.params,
}).strict(), // Explicitly reject unknown keysOption B - Document passthrough behavior: // Update test comment to:
// Zod's default .object() behavior is .passthrough() which allows unknown keys.
// This is intentional - extra params are harmless and ignored by navigation.I recommend Option A (strict validation) for defense-in-depth. 4. No Integration/E2E Test CoverageLocation: Test suite While
Recommendation: Add integration tests that:
For E2E tests (using Playwright), test:
🟢 Medium Priority Issues5. Inconsistent Error Message FormattingLocation: Line 22 logs: Different formats make log parsing and monitoring harder. Recommendation: Standardize to: log.warn(`[deep-link] Error: Unsupported protocol ${url.protocol} (expected ${DEEP_LINK_PROTOCOL}:)`)
log.warn(`[deep-link] Error: Schema validation failed - ${z.prettifyError(result.error)}`)6. No Explicit Navigation Error Handling in RendererLocation: The renderer trusts that navigation will succeed: const deepLinkCleanup = window.electronAPI.onDeepLinkNavigation((target) => {
log.info(`[deep-link] Navigating to: ${target.to}`, target.params)
router.navigate(target)
})If Recommendation: const deepLinkCleanup = window.electronAPI.onDeepLinkNavigation(async (target) => {
log.info(`[deep-link] Received navigation target: ${target.to}`, target.params)
try {
await router.navigate(target)
log.info(`[deep-link] Navigation succeeded`)
} catch (error) {
log.error(`[deep-link] Navigation failed:`, error)
// Optionally: navigate to 404 as fallback
}
})7. Missing Windows Registry Testing DocumentationLocation: The README explains Linux testing (lines 81-100) but doesn't mention that Windows requires registry entries for deep link testing in development. Missing info:
Recommendation: Add a Windows section to the testing guide: #### Windows
In development, protocol handlers require registry entries. The packaged installer handles this automatically via Squirrel's `Update.exe`, but for local testing:
**Option 1 (Recommended):** Install a packaged `.exe`:
```bash
pnpm run package
# Then run the installer from out/make/squirrel.windows/Option 2 (Manual Registry): Add registry entries manually: Once registered, test with: start toolhive-gui://v1/open-registry-server-detail?serverName=fetchThe Root cause: The discriminated union type Recommendation: This is acceptable given the Zod validation, but consider adding a runtime assertion: const def = deepLinksByIntent.get(deepLink.intent)
if (!def) {
return showNotFound.navigate({})
}
// Runtime check that the definition matches the intent
if (def.intent !== deepLink.intent) {
log.error(`[deep-link] Intent mismatch: ${def.intent} !== ${deepLink.intent}`)
return showNotFound.navigate({})
}
return def.navigate(deepLink.params as never)Lower priority - the current implementation is safe due to Zod validation. 🔵 Low Priority / Nice-to-Have9. Limited Deep Link Intent CoverageOnly one real intent is implemented: The architecture is excellent and extensible. Consider adding more intents to demonstrate value: Suggestions:
This would make the feature more useful and test the architecture with multiple use cases. 10. No Telemetry/Analytics for Deep LinksLocation: All deep link handlers No tracking for deep link usage. Consider adding Sentry breadcrumbs or analytics events: // In main/src/deep-links/index.ts after successful parsing
Sentry.addBreadcrumb({
category: 'deep-link',
message: `Deep link activated: ${result.deepLink.intent}`,
level: 'info',
data: { intent: result.deepLink.intent, version: result.deepLink.version }
})This helps understand:
11. Deep Link Validation Could Be StricterLocation: The const safeString = z.string().regex(/^[a-zA-Z0-9_.-]+$/)Current usage: Only used for Recommendation: Document why dots are allowed (valid in server names) or tighten to ✅ Strengths (What's Done Right)This implementation has several excellent qualities: 1. Single Source of Truth ArchitectureThe
2. Security-First Design
3. Excellent Test Coverage for ParserThe
4. Cross-Platform SupportProper handling of platform differences:
5. Graceful Degradation
6. Clear LoggingComprehensive logging at each stage:
7. Production-Ready Infrastructure
📋 SummaryThis is a high-quality implementation that follows Electron best practices. The architecture is clean, extensible, and secure. Critical actions needed:
Security posture: Strong. Input validation, safe string regex, and comprehensive test coverage for attack vectors. Maintainability: Excellent. Single source of truth pattern, clear code structure, good logging. Once the window readiness race condition is addressed with an explicit IPC signal and integration tests are added, this feature will be fully production-ready. 📊 Test Coverage AnalysisCurrent coverage:
Missing test scenarios:
Files Reviewed: 15 files (common/deep-links.ts, parse.ts, parse.test.ts, index.ts, squirrel.ts, main.ts, main-window.ts, forge.config.ts, preload.ts, renderer.tsx, electronAPI.ts, vitest.setup.ts, README.md, install-deep-link-handler.sh, package.json) |
There was a problem hiding this comment.
Pull request overview
Adds an initial deep-linking flow to ToolHive Studio, allowing toolhive-gui://... URLs to be parsed/validated in the main process and translated into renderer navigation via IPC, plus packaging/runtime protocol registration support.
Changes:
- Introduces a shared deep-link registry (
common/deep-links.ts) with Zod schemas and navigation target resolution. - Implements main-process deep link handling (argv + macOS
open-url) and IPC forwarding, with renderer-side navigation subscription. - Adds packaging/config/docs/scripts updates to register the
toolhive-gui://protocol handler (notably for Linux testing).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| vitest.setup.ts | Extends Electron API stubs to include deep link navigation listener. |
| scripts/install-deep-link-handler.sh | Adds a Linux helper to build a .deb, install the .desktop, and register the protocol handler. |
| renderer/src/renderer.tsx | Subscribes to onDeepLinkNavigation and navigates the router accordingly. |
| renderer/src/common/mocks/electronAPI.ts | Updates renderer Electron API mock to include deep link navigation listener. |
| preload/src/preload.ts | Exposes onDeepLinkNavigation over contextBridge and updates ElectronAPI typing. |
| package.json | Adds deeplink:registerTestLinuxProtocolHandler script. |
| main/src/main.ts | Wires deep link handling into single-instance flow, cold start argv, and macOS open-url; registers protocol handler. |
| main/src/main-window.ts | Exports waitForMainWindowReady for use by deep-link handler. |
| main/src/deep-links/squirrel.ts | Implements protocol registration, including Squirrel-friendly registration on Windows. |
| main/src/deep-links/parse.ts | Adds URL parsing + Zod validation for deep links. |
| main/src/deep-links/index.ts | Adds argv extraction + end-to-end deep link handling and IPC dispatch. |
| main/src/deep-links/tests/parse.test.ts | Adds unit tests for deep link parsing/validation. |
| forge.config.ts | Adds protocol/mimeType metadata for macOS/Linux packaging outputs. |
| docs/README.md | Documents deep link format and Linux testing workflow. |
| common/deep-links.ts | Defines deep link intents, schemas, and navigation target resolution shared across processes. |
|
@kantord clicking on jsfiddle the
|
|
@kantord did you try with a build and the app closed? |
|
/build-test |
|
git fetch origin main
git rebase origin/main
git push --force-with-lease |
281f663 to
beefc81
Compare
|
/build-test |
Build Artifacts for PR #1584
Download artifacts from workflow run Version:
|
beefc81 to
accc4a5
Compare
|
/build-test |
|
/build-test |
|
/build-test |


fixes #1076
Technical document: https://docs.google.com/document/d/1Y-tYsIl98DPHKdCNsbuvtZeb0VUq41cTxQfGQElbS9c
Add deep link support via the toolhive-gui:// protocol. URLs like toolhive-gui://v1/open-registry-server-detail?serverName=fetch open the app
(or focus it if already running) and navigate to the corresponding page.
For testing on MacOS, you probably have to make a production build and install it. There are probably some hacky ways to make such testing builds more automated, but I could not test that.
For Linux, a helper script was added: this script makes a production build and installs its .desktop file in such a way that deep links are immediately opened using that link.
You can use this js fiddle to find some links for testing: https://jsfiddle.net/deLzqvos/1/ (github markdown filters out custom protocols, so cannot be directly included in the PR description)
Still TODO: