Skip to content
← 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.

FollowFork

Files

configure-settings.ts

29 lines · 1.2 KB · TypeScript
import { loadSettings, normalizePilotScope, patchSettings, type FactorySettings } from '../lib/settings.ts'

/**
 * Read or patch non-secret factory settings (Devin org id, shadow mode, concurrency,
 * pilotScope `{ mode: 'allowlist', projectIds: ['kody'], repoRefs: ['kody-hq/kody'] }`).
 *
 * @param input - Optional patch fields; omit to read
 * @returns Current settings
 *
 * @example
 * import configureSettings from 'kody:@kody/kody-factory/configure-settings'
 * await configureSettings({ shadowMode: true, dryRun: true })
 */
export default async function configureSettings(
	input: Partial<FactorySettings> & { dryRun?: boolean } = {},
) {
	const { dryRun, ...patch } = input
	if (patch.pilotScope !== undefined) patch.pilotScope = normalizePilotScope(patch.pilotScope)
	const keys = Object.keys(patch).filter((k) => (patch as Record<string, unknown>)[k] !== undefined)
	if (keys.length === 0) {
		return { settings: await loadSettings(), updated: [], dryRun: false }
	}
	if (dryRun) {
		const current = await loadSettings()
		return { settings: { ...current, ...patch }, updated: keys, dryRun: true, persisted: false }
	}
	const settings = await patchSettings(patch)
	return { settings, updated: keys, dryRun: false, persisted: true }
}