'use strict'; const { contextBridge, ipcRenderer } = require('electron'); async function invoke(channel, payload) { const result = await ipcRenderer.invoke(channel, payload); if (!result?.ok) { const error = new Error(result?.error?.message || 'ForgeFlow operation failed.'); error.code = result?.error?.code; error.status = result?.error?.status; error.recoverable = result?.error?.recoverable; error.commitSha = result?.error?.commitSha; throw error; } return result.data; } function subscribe(channel, listener) { if (typeof listener !== 'function') return () => {}; const handler = (_event, payload) => listener(payload); ipcRenderer.on(channel, handler); return () => ipcRenderer.removeListener(channel, handler); } contextBridge.exposeInMainWorld('forgeflow', Object.freeze({ bootstrap: () => invoke('app:bootstrap'), selectDirectory: (payload) => invoke('dialog:select-directory', payload), selectKeyFile: (payload) => invoke('dialog:select-key-file', payload), setupPreflight: (payload) => invoke('setup:preflight', payload), validateGitea: (payload) => invoke('setup:validate-gitea', payload), completeSetup: (payload) => invoke('setup:complete', payload), updateGitea: (payload) => invoke('settings:update-gitea', payload), setWorkspaceRoots: (roots) => invoke('settings:set-roots', { roots }), setAppearance: (appearance) => invoke('settings:set-appearance', { appearance }), setPreferences: (preferences) => invoke('settings:set-preferences', { preferences }), setUpdatePreferences: (updates) => invoke('updates:preferences', { updates }), checkForUpdates: () => invoke('updates:check'), downloadUpdate: () => invoke('updates:download'), applyUpdate: () => invoke('updates:apply'), saveServer: (server, password = '', passphrase = '') => invoke('server:save', { server, password, passphrase }), deleteServer: (serverId) => invoke('server:delete', { serverId }), testServer: (serverId) => invoke('server:test', { serverId }), inspectServerProject: (repository, profileId) => invoke('server:inspect-project', { repository, profileId }), refreshRepositories: () => invoke('repositories:refresh'), discoverRepositories: (roots) => invoke('repositories:discover', { roots }), favoriteRepository: (fullName, favorite) => invoke('repository:favorite', { fullName, favorite }), linkRepository: (fullName, localPath) => invoke('repository:link', { fullName, localPath }), unlinkRepository: (fullName) => invoke('repository:unlink', { fullName }), repositoryStatus: (localPath) => invoke('repository:status', { localPath }), repositoryDiff: (localPath, filePath, staged = false) => invoke('repository:diff', { localPath, filePath, staged }), stageFiles: (localPath, files) => invoke('repository:stage', { localPath, files }), unstageFiles: (localPath, files) => invoke('repository:unstage', { localPath, files }), commit: (localPath, message, files) => invoke('repository:commit', { localPath, message, files }), commitAndPush: (localPath, message, files) => invoke('repository:commit-push', { localPath, message, files }), push: (localPath) => invoke('repository:push', { localPath }), fetch: (localPath) => invoke('repository:fetch', { localPath }), pull: (localPath) => invoke('repository:pull', { localPath }), history: (localPath, limit = 20) => invoke('repository:history', { localPath, limit }), branches: (localPath) => invoke('repository:branches', { localPath }), checkoutBranch: (localPath, branch) => invoke('repository:checkout-branch', { localPath, branch }), createBranch: (localPath, branch) => invoke('repository:create-branch', { localPath, branch }), stash: (localPath, message) => invoke('repository:stash', { localPath, message }), stashList: (localPath) => invoke('repository:stash-list', { localPath }), popStash: (localPath, ref) => invoke('repository:stash-pop', { localPath, ref }), cloneRepository: (fullName, mode = 'default') => invoke('repository:clone', { fullName, mode }), openPath: (localPath) => invoke('repository:open-path', { localPath }), openExternal: (url) => invoke('external:open', { url }), saveDeploymentProfile: (fullName, profile) => invoke('deployment:save-profile', { fullName, profile }), deploymentPreflight: (repository, profileId) => invoke('deployment:preflight', { repository, profileId }), deleteDeploymentProfile: (fullName, profileId) => invoke('deployment:delete-profile', { fullName, profileId }), deploy: (repository, profileId, sha) => invoke('deployment:dispatch', { repository, profileId, sha }), rollback: (repository, profileId, targetSha) => invoke('deployment:rollback', { repository, profileId, targetSha }), healthcheck: (url) => invoke('deployment:health', { url }), refreshProfileState: (fullName, profileId) => invoke('deployment:profile-state', { fullName, profileId }), refreshOperations: (operationId = null) => invoke('operations:refresh', { operationId }), getOperation: (operationId) => invoke('operations:get', { operationId }), diagnosticsStatus: () => invoke('diagnostics:status'), clearDiagnostics: () => invoke('diagnostics:clear'), openDiagnosticsFolder: () => invoke('diagnostics:open-folder'), exportDiagnostics: (privacyMode = 'standard') => invoke('diagnostics:export', { privacyMode }), showDiagnosticBundle: (filePath) => invoke('diagnostics:show-bundle', { filePath }), reportRendererEvent: (level, event, details = {}) => invoke('renderer:report', { level, event, details }), onRepositoriesChanged: (listener) => subscribe('repositories:changed', listener), onOperationsChanged: (listener) => subscribe('operations:changed', listener), onUpdatesChanged: (listener) => subscribe('updates:changed', listener), reset: () => invoke('app:reset') }));