72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
export interface BootstrapMarkerLike {
|
|
pinnedCommit?: unknown
|
|
packageCommit?: unknown
|
|
schemaVersion?: unknown
|
|
}
|
|
|
|
// An AITURK package upgrade must bring its managed agent along with the UI.
|
|
// Developer checkouts and installs without proven Desktop ownership keep their
|
|
// existing launch behavior. The installer preserves edits and refuses rollback.
|
|
export function needsPackagedRuntimeUpgrade(
|
|
packaged: boolean, stamp: { commit?: string; source?: string } | null,
|
|
marker: BootstrapMarkerLike | null
|
|
): boolean {
|
|
return Boolean(packaged && stamp?.source !== 'fallback' &&
|
|
/^[0-9a-f]{40}$/i.test(stamp?.commit || '') && !/^0+$/.test(stamp?.commit || '') &&
|
|
hasValidBootstrapMarker(marker, 1) && (marker?.packageCommit || marker?.pinnedCommit) !== stamp?.commit)
|
|
}
|
|
|
|
export interface ActiveRuntimeState {
|
|
hasValidMarker: boolean
|
|
shouldUseActiveRuntime: boolean
|
|
usabilityReason: 'usable' | 'unusable'
|
|
}
|
|
|
|
export function hasValidBootstrapMarker(
|
|
marker: BootstrapMarkerLike | null | undefined,
|
|
schemaVersion: number
|
|
): boolean {
|
|
if (!marker || typeof marker !== 'object') {
|
|
return false
|
|
}
|
|
|
|
if (marker.schemaVersion !== schemaVersion) {
|
|
return false
|
|
}
|
|
|
|
if (typeof marker.pinnedCommit !== 'string' || marker.pinnedCommit.length < 7) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// The active install at ~/.hermes/hermes-agent can be real and runnable even if
|
|
// Desktop never wrote its first-run bootstrap marker (for example when Hermes
|
|
// was installed by the CLI first, or when a past desktop build forgot the
|
|
// marker). Runtime usability is authoritative for "can we launch local Hermes
|
|
// right now?"; the marker is only provenance about how that install was
|
|
// created. A missing/stale marker must never force a healthy local install into
|
|
// the first-run bootstrap UI.
|
|
export function classifyActiveRuntime(
|
|
marker: BootstrapMarkerLike | null | undefined,
|
|
schemaVersion: number,
|
|
runtimeUsable: boolean
|
|
): ActiveRuntimeState {
|
|
const hasValidMarker = hasValidBootstrapMarker(marker, schemaVersion)
|
|
|
|
if (!runtimeUsable) {
|
|
return {
|
|
hasValidMarker,
|
|
shouldUseActiveRuntime: false,
|
|
usabilityReason: 'unusable'
|
|
}
|
|
}
|
|
|
|
return {
|
|
hasValidMarker,
|
|
shouldUseActiveRuntime: true,
|
|
usabilityReason: 'usable'
|
|
}
|
|
}
|