← Public packages
@kody/kody-factory
Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.
Files
import { loadHealthConfig, patchHealthConfig, type HealthConfig } from '../../health/config.ts'
import { releaseLease } from '../../health/store.ts'
/**
* Read or change the factory health switches. All three default to off.
* `intakeEnabled` records run errors, `reconcileEnabled` lets the sweep scan
* open error runs and soft-triage Activity, `wakesEnabled` lets the sweep wake
* Patch. Turning intake or reconcile on never sends a wake.
*
* @param input - Optional patch `{ intakeEnabled?, reconcileEnabled?, wakesEnabled?, org?, releaseLease?, dryRun? }`; omit to read
* @returns Current switches
*
* @example
* import configureHealth from 'kody:@kody/kody-factory/health/configure'
* await configureHealth({ intakeEnabled: true, reconcileEnabled: true, dryRun: true })
*/
export default async function configureHealth(
input: Partial<Pick<HealthConfig, 'intakeEnabled' | 'reconcileEnabled' | 'wakesEnabled' | 'org'>> & { releaseLease?: boolean; dryRun?: boolean } = {},
) {
const patch: Partial<HealthConfig> = {}
for (const key of ['intakeEnabled', 'reconcileEnabled', 'wakesEnabled'] as const) {
if (typeof input?.[key] === 'boolean') patch[key] = input[key]
}
if (input?.org === null || typeof input?.org === 'string') patch.org = input.org
const current = await loadHealthConfig()
if (input?.dryRun === true) return { config: { ...current, ...patch }, persisted: false }
if (input?.releaseLease === true) await releaseLease()
const config = Object.keys(patch).length ? await patchHealthConfig(patch) : current
return { config, persisted: Object.keys(patch).length > 0, leaseReleased: input?.releaseLease === true }
}