Files
hermes-agent/apps/desktop/electron/deep-link-protocol.ts
Teknium ab9633b0af fix(desktop): E2E and harness launches leave the OS hermes:// handler alone
Every Electron launch calls app.setAsDefaultProtocolClient, which on Windows
rewrites HKCU\Software\Classes\hermes. An unpackaged checkout registers
`electron.exe <checkout>`, so running the Desktop E2E suite on a dev box
repointed the user's installed hermes:// handler at the test checkout (base
and head alike).

registerDeepLinkProtocol moves to electron/deep-link-protocol.ts (main.ts is
at its size cap) and skips the OS registration when
HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION=1. The core, mock-backend and
update harnesses set it. Deep links that arrive through argv /
second-instance still route as before; production launches are unchanged.

Test: deep-link-protocol.test.ts (skipped with the env, registered with the
dev exec path / bare otherwise).

Review: https://github.com/NousResearch/hermes-agent/pull/106742#issuecomment-6073624820
(cherry picked from commit 8e72f6460aa00e084a842b6c30b0309a24bfc4f7)
2026-10-09 02:10:49 -07:00

49 lines
1.8 KiB
TypeScript

/**
* `hermes://` deep-link registration. Every launch rewrites the OS handler (on Windows,
* HKCU\Software\Classes\<protocol>), so a test or dev run of an unpackaged checkout would
* repoint the user's installed handler at that checkout. `HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION=1`
* (set by the E2E harnesses) leaves the OS registration untouched; deep links that arrive
* through argv / second-instance still route normally.
*/
export interface ProtocolRegistrar {
setAsDefaultProtocolClient: (protocol: string, path?: string, args?: string[]) => boolean
}
export interface DeepLinkProtocolOptions {
app: ProtocolRegistrar
protocol: string
env: NodeJS.ProcessEnv
/** `process.defaultApp`: running as `electron <dir>` rather than a packaged binary. */
defaultApp: boolean
argv: string[]
execPath: string
resolve: (entry: string) => string
log: (line: string) => void
}
export function registerDeepLinkProtocol(options: DeepLinkProtocolOptions): void {
const { app, protocol, env, defaultApp, argv, execPath, resolve, log } = options
if (env.HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION === '1') {
log(`[deeplink] ${protocol}:// registration skipped (HERMES_DESKTOP_SKIP_PROTOCOL_REGISTRATION)`)
return
}
try {
if (defaultApp && argv.length >= 2) {
// Dev: register with the electron exec path + entry script so the OS can
// relaunch us with the URL. argv[1] is usually "." when launched via
// `electron .` from apps/desktop — resolve against cwd.
app.setAsDefaultProtocolClient(protocol, execPath, [resolve(argv[1])])
} else {
app.setAsDefaultProtocolClient(protocol)
}
log(`[deeplink] registered ${protocol}:// handler`)
} catch (err) {
log(`[deeplink] protocol registration failed: ${(err as Error).message}`)
}
}