mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
Use a verified writable copy of pinned Python for uv builds. Keep the signed launchers and bundled Python as the MSIX runtime so plugin rebuilds do not remove package access. Identify Microsoft Store builds from the artifact stamp. Use StoreContext for update checks, downloads, and installation requests inside Hermes. Keep relaunch and recovery ownership across the update. Do not report unknown checks or no-op requests as successful installations. Open the build commit link in the system browser. Verification: 168 Python tests, 107 Electron tests, and 121 renderer tests passed. Typechecks, lint, lock validation, and desktop builds passed. A real packaged process completed plugin admission, import, and repair. Store-acquired download, installation, and relaunch remain unverified. This host has only the sideloaded MSIX. Its real Store API call returned an error, which the app reports as unknown. macOS updates are unchanged.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import { APPINSTALLER_CHECK_TIMEOUT_MS, runAppInstallerChecker } from '../appinstaller-checker'
|
|
|
|
import { type StoreResult, StoreStrategy, type StoreStrategyDeps } from './store'
|
|
|
|
export interface StoreClientDeps extends Omit<StoreStrategyDeps, 'run'> {
|
|
python: string
|
|
script: string
|
|
sitePackages: string
|
|
env: NodeJS.ProcessEnv
|
|
windowHandle: () => Buffer | null
|
|
run?: typeof runAppInstallerChecker
|
|
}
|
|
|
|
function parseResult(code: number, stdout: string): StoreResult {
|
|
const unknown = (error: string): StoreResult => ({ available: null, packages: [], ok: false, error })
|
|
let value: unknown
|
|
|
|
try {
|
|
value = JSON.parse(stdout)
|
|
} catch {
|
|
return unknown(`Microsoft Store returned invalid JSON (exit ${code})`)
|
|
}
|
|
|
|
if (!value || typeof value !== 'object') {
|
|
return unknown('Microsoft Store returned no result')
|
|
}
|
|
|
|
const row = value as Partial<StoreResult>
|
|
|
|
if (
|
|
(code !== 0 && code !== 2) ||
|
|
row.ok !== true ||
|
|
typeof row.available !== 'boolean' ||
|
|
!Array.isArray(row.packages) ||
|
|
!row.packages.every(item => typeof item === 'string')
|
|
) {
|
|
return unknown(typeof row.error === 'string' ? row.error : `Microsoft Store request failed (exit ${code})`)
|
|
}
|
|
|
|
return { ok: true, available: row.available, packages: row.packages }
|
|
}
|
|
|
|
export function createStoreStrategy(deps: StoreClientDeps): StoreStrategy {
|
|
const run = deps.run ?? runAppInstallerChecker
|
|
|
|
return new StoreStrategy({
|
|
...deps,
|
|
run: async mode => {
|
|
const env: NodeJS.ProcessEnv = { ...deps.env, PYTHONPATH: deps.sitePackages }
|
|
delete env.PYTHONHOME
|
|
delete env.VIRTUAL_ENV
|
|
delete env.PYTHONEXECUTABLE
|
|
delete env.__PYVENV_LAUNCHER__
|
|
const handle = deps.windowHandle()
|
|
|
|
if (mode !== 'check' && !handle) {
|
|
throw new Error('A desktop window is required for Microsoft Store consent')
|
|
}
|
|
|
|
const args = ['--mode', mode]
|
|
|
|
if (handle) {
|
|
const hwnd = handle.length === 8 ? handle.readBigUInt64LE().toString() : handle.readUInt32LE().toString()
|
|
args.push('--hwnd', hwnd)
|
|
}
|
|
|
|
const result = await run(deps.python, deps.script, {
|
|
args,
|
|
env,
|
|
timeoutMs: mode === 'check' ? APPINSTALLER_CHECK_TIMEOUT_MS : 1_830_000,
|
|
waitForExit: mode !== 'check'
|
|
})
|
|
|
|
if (mode !== 'check' && result.code !== 0) {
|
|
const failed = parseResult(result.code, result.stdout)
|
|
|
|
return { ...failed, ok: false, error: failed.error || `Microsoft Store ${mode} did not complete` }
|
|
}
|
|
|
|
return parseResult(result.code, result.stdout)
|
|
}
|
|
})
|
|
}
|