mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-19 03:40:50 +00:00
* fix(hub): govern runner capabilities so Cursor reopen soft-fails on skew Hub↔runner protocol drift was reported as missing Cursor chat data when cursor-chat-store-status was unregistered. Soft-fail reopen on probe errors, advertise required machine capabilities, surface an unmissable upgrade banner, and stop-runner when a newer CLI binary is already on disk. Fixes #1084 Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web,hub): make runner skew banner dismissible; gate auto-upgrade Compact the out-of-date banner (minimize + 1h snooze + per-host Restart) so it no longer blocks the session list. Auto stop-runner on skew stays opt-in via HAPI_AUTO_UPGRADE_RUNNERS / autoUpgradeRunners (default off). Co-authored-by: Cursor <cursoragent@cursor.com> * fix(web): tolerate full sessionStorage on skew banner minimize QuotaExceededError from setItem aborted minimize before React state updated, leaving the banner stuck over the session list. Persist to memory when storage fails; only enable Restart when a newer CLI is already on disk; clarify opt-in is stop-runner only, not package push. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(hub): drop redundant autoUpgradeRunners; runners already self-restart CLI version handoff already reloads the runner when the on-disk binary mtime changes. Hub-driven stop-runner on skew duplicated that. Keep the skew banner and manual Restart only as a stuck/disabled-handoff escape. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(cli,hub,web): runner-only caps ads; gate Restart on supervisor Address #1108 bot Majors on the thin tip: terminal/lazy bootstraps no longer merge CURRENT_MACHINE_CAPABILITIES into the machine row (only asRunner registration does). Banner Restart refuses unsupervised hosts so stop-runner cannot leave a detached laptop offline; supervised runners advertise supervisedRestart via HAPI_RUNNER_SUPERVISED=1. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(hub,cli,web): clear sticky runner ads; docs SUPERVISED; i18n skew label Omit-means-clear on runner registration so rollback cannot leave supervisedRestart/capabilities sticky; always advertise boolean supervisedRestart from asRunner. Document HAPI_RUNNER_SUPERVISED=1 and localize MachineSelector UPDATE REQUIRED. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Debian <heavygee@oos-linux.in.lockhouse> Co-authored-by: Cursor <cursoragent@cursor.com>
95 lines
3.6 KiB
TypeScript
95 lines
3.6 KiB
TypeScript
import { isKnownFlavor } from '@hapi/protocol'
|
|
import type { Session } from '@/types/api'
|
|
|
|
/** Agent thread id used by hub `resolveAgentResumeId`, flavor-specific.
|
|
* Mirrors hub: cross-flavor ids are ignored to avoid the web layer claiming a
|
|
* session is resumable when the hub will only honor the current flavor's id.
|
|
*/
|
|
export function resolveAgentSessionIdFromMetadata(
|
|
metadata: Session['metadata'] | null | undefined,
|
|
): string | undefined {
|
|
if (!metadata) {
|
|
return undefined
|
|
}
|
|
const flavor = isKnownFlavor(metadata.flavor) ? metadata.flavor : 'claude'
|
|
switch (flavor) {
|
|
case 'agy': return metadata.agySessionId ?? undefined
|
|
case 'codex': return metadata.codexSessionId ?? undefined
|
|
case 'gemini': return metadata.geminiSessionId ?? undefined
|
|
case 'opencode': return metadata.opencodeSessionId ?? undefined
|
|
case 'grok': return metadata.grokSessionId ?? undefined
|
|
case 'cursor': return metadata.cursorSessionId ?? undefined
|
|
case 'kimi': return metadata.kimiSessionId ?? undefined
|
|
case 'copilot': return metadata.copilotSessionId ?? undefined
|
|
case 'pi': return metadata.piSessionId ?? undefined
|
|
default: return metadata.claudeSessionId ?? undefined
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Whether an inactive session can be activated via resume (or fresh spawn on first send).
|
|
* Matches hub: resume with agent id, or fresh spawn when path exists, no agent id, no user messages.
|
|
* Claude and Codex with messages but no flavor-specific id may attempt the
|
|
* hub-authoritative stored-message recovery path; the hub still rejects logs
|
|
* without a safe resume id.
|
|
*
|
|
* Cursor: definitive `onDisk: false` still blocks. Probe failure / unknown
|
|
* (`undefined`) must NOT be treated as missing data — allow reopen and show
|
|
* honest messaging (#1084).
|
|
*/
|
|
export function inactiveSessionCanResume(
|
|
session: Session,
|
|
userMessageCount: number,
|
|
cursorChatOnDisk?: boolean,
|
|
): boolean {
|
|
if (session.active) {
|
|
return true
|
|
}
|
|
if (!session.metadata?.path) {
|
|
return false
|
|
}
|
|
if (resolveAgentSessionIdFromMetadata(session.metadata)) {
|
|
const flavor = isKnownFlavor(session.metadata.flavor) ? session.metadata.flavor : 'claude'
|
|
if (flavor === 'cursor') {
|
|
return cursorChatOnDisk !== false
|
|
}
|
|
return true
|
|
}
|
|
const flavor = isKnownFlavor(session.metadata.flavor) ? session.metadata.flavor : 'claude'
|
|
if ((flavor === 'claude' || flavor === 'codex') && userMessageCount > 0) {
|
|
return true
|
|
}
|
|
return userMessageCount === 0
|
|
}
|
|
|
|
export type CursorReopenGateReason = 'missing' | 'checking'
|
|
|
|
/**
|
|
* UI gate for Cursor reopen. Only definitive `onDisk: false` disables reopen.
|
|
* Probe errors / unknown status allow the attempt (soft-fail) with optional
|
|
* unverified messaging.
|
|
*/
|
|
export function resolveCursorReopenGate(args: {
|
|
applicable: boolean
|
|
onDisk: boolean | undefined
|
|
error: string | null
|
|
isLoading: boolean
|
|
}): { disabledReason: CursorReopenGateReason | null; probeUnverified: boolean } {
|
|
if (!args.applicable) {
|
|
return { disabledReason: null, probeUnverified: false }
|
|
}
|
|
if (args.onDisk === false) {
|
|
return { disabledReason: 'missing', probeUnverified: false }
|
|
}
|
|
if (args.onDisk === true) {
|
|
return { disabledReason: null, probeUnverified: false }
|
|
}
|
|
if (args.error) {
|
|
return { disabledReason: null, probeUnverified: true }
|
|
}
|
|
if (args.isLoading) {
|
|
return { disabledReason: 'checking', probeUnverified: false }
|
|
}
|
|
return { disabledReason: 'checking', probeUnverified: false }
|
|
}
|