mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Checkpoint before round-3 reduction (two-tier retirement derived from product identity). Includes: - R2 channel protocol (release_channels.py, channel-protocol.ts): records, builds, manifests, retired channels with pinned destinationHead and receiverProtocol; fail-closed readers in both languages - One shared native manifest/feed writer (scripts/bundles/channel_artifacts.py) - Scoped/disposable R2 publication, fork isolation before credential access, canary bootstrap verification of its own promoted outputs - Channel source CLI: typed SourceTarget, source-channel resolution, retirement downgrade refusal - Desktop channel resolver/strategy, install-stamp/build-stamp receiver ownership (stable-owned S/T candidates), single-flight updater operation - Cross-package retirement machinery (receiver/host/preservation/ compatibility/connections/dialog/discovery, backup_migration strict snapshots with retained-link inventory, empty-dir preservation, connection-collision resolution, URL-credential rejection) - Native install harness (tests/install/channel-retirement-*) and install-e2e retirement jobs - checkout-source.test.ts transport shim now covers build_opener().open (was silently hitting the real network in CI) Removed secondary certification protocol (channel_qualification.py) per approved round-2 plan. All focused suites green at checkpoint; native cross-package journeys unverified (to be deleted in round 3).
142 lines
4.6 KiB
TypeScript
142 lines
4.6 KiB
TypeScript
import type { AppUpdater } from 'electron-updater'
|
|
|
|
import { applyPackagedHandoff } from './packaged-handoff'
|
|
|
|
import type { UpdaterApplyResultWire, UpdaterStatusWire, UpdaterStrategy } from './index'
|
|
|
|
export interface MacStrategyDeps {
|
|
updater: Pick<AppUpdater, 'checkForUpdates' | 'downloadUpdate' | 'quitAndInstall' | 'on' | 'removeListener'>
|
|
channel: string
|
|
expectedVersion?: string
|
|
verifyDownload?: (files: string[]) => Promise<void>
|
|
appVersion: string
|
|
/** Squirrel verifies the signed app before any backend is stopped. */
|
|
prepareInstall: () => Promise<void>
|
|
beforeInstall: () => Promise<void>
|
|
onInstallFailure: () => Promise<void>
|
|
emitProgress: (payload: { stage: string; message: string; percent: number | null }) => void
|
|
}
|
|
|
|
export class MacStrategy implements UpdaterStrategy {
|
|
readonly mechanism = 'electron-updater' as const
|
|
private applying = false
|
|
|
|
constructor(private readonly deps: MacStrategyDeps) {}
|
|
|
|
async check(): Promise<UpdaterStatusWire> {
|
|
if (this.applying) {
|
|
throw new Error('An update is already in progress.')
|
|
}
|
|
|
|
return this.checkRelease()
|
|
}
|
|
|
|
private async checkRelease(): Promise<UpdaterStatusWire> {
|
|
const result = await this.deps.updater.checkForUpdates()
|
|
|
|
if (!result) {
|
|
throw new Error('The macOS updater is not active for this app.')
|
|
}
|
|
|
|
if (this.deps.expectedVersion && result.updateInfo.version !== this.deps.expectedVersion) {
|
|
throw new Error('Native macOS feed does not match the pinned channel version')
|
|
}
|
|
|
|
return {
|
|
supported: true,
|
|
mechanism: this.mechanism,
|
|
currentVersion: this.deps.appVersion,
|
|
channel: this.deps.channel,
|
|
latestTag: `v${result.updateInfo.version}`,
|
|
updateAvailable: result.isUpdateAvailable,
|
|
fetchedAt: Date.now()
|
|
}
|
|
}
|
|
|
|
async apply(): Promise<UpdaterApplyResultWire> {
|
|
if (this.applying) {
|
|
throw new Error('An update is already in progress.')
|
|
}
|
|
|
|
this.applying = true
|
|
|
|
const progress = ({ percent }: { percent: number }): void => {
|
|
this.deps.emitProgress({ stage: 'fetch', message: 'Downloading the Hermes update.', percent })
|
|
}
|
|
|
|
this.deps.updater.on('download-progress', progress)
|
|
|
|
try {
|
|
return await applyPackagedHandoff(
|
|
{
|
|
teardown: this.deps.beforeInstall,
|
|
restore: this.deps.onInstallFailure,
|
|
emitProgress: this.deps.emitProgress
|
|
},
|
|
async (stop: () => Promise<void>): Promise<UpdaterApplyResultWire> => {
|
|
const status = await this.checkRelease()
|
|
|
|
if (!status.updateAvailable) {
|
|
return { ok: true, mechanism: this.mechanism }
|
|
}
|
|
|
|
const files = await this.deps.updater.downloadUpdate()
|
|
await this.deps.verifyDownload?.(files)
|
|
this.deps.emitProgress({ stage: 'prepare', message: 'Verifying the signed macOS update.', percent: null })
|
|
await this.deps.prepareInstall()
|
|
await stop()
|
|
this.deps.emitProgress({
|
|
stage: 'restart',
|
|
message: 'Restarting Hermes to install the update.',
|
|
percent: 100
|
|
})
|
|
this.deps.updater.quitAndInstall()
|
|
|
|
return { ok: true, bundled: true, handedOff: true, mechanism: this.mechanism }
|
|
}
|
|
)
|
|
} finally {
|
|
this.deps.updater.removeListener('download-progress', progress)
|
|
this.applying = false
|
|
}
|
|
}
|
|
}
|
|
|
|
export interface NativeMacUpdater {
|
|
once(event: 'update-downloaded', listener: () => void): unknown
|
|
once(event: 'error', listener: (error: Error) => void): unknown
|
|
removeListener(event: 'update-downloaded', listener: () => void): unknown
|
|
removeListener(event: 'error', listener: (error: Error) => void): unknown
|
|
checkForUpdates(): void
|
|
}
|
|
|
|
/** Download completion alone does not mean Squirrel accepted the signature. */
|
|
export function prepareMacInstall(native: NativeMacUpdater, timeoutMs: number = 120_000): Promise<void> {
|
|
return new Promise<void>((resolve: () => void, reject: (error: Error) => void): void => {
|
|
const cleanup = (): void => {
|
|
clearTimeout(timer)
|
|
native.removeListener('error', failed)
|
|
native.removeListener('update-downloaded', ready)
|
|
}
|
|
|
|
const failed = (error: Error): void => {
|
|
cleanup()
|
|
reject(error)
|
|
}
|
|
|
|
const ready = (): void => {
|
|
cleanup()
|
|
resolve()
|
|
}
|
|
|
|
const timer = setTimeout((): void => failed(new Error('macOS update verification timed out.')), timeoutMs)
|
|
native.once('error', failed)
|
|
native.once('update-downloaded', ready)
|
|
|
|
try {
|
|
native.checkForUpdates()
|
|
} catch (error) {
|
|
failed(error as Error)
|
|
}
|
|
})
|
|
}
|