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

templates.ts

140 lines · 4.8 KB · TypeScript
/**
 * Built-in config templates for new projects or fresh installs.
 * Templates are partial ConfigDocuments; applying one merges it into
 * the current config without touching credentials or existing work items.
 */
import { CONFIG_VERSION, type ConfigDocument, type ConfigProject, type ConfigSettings, type ConfigJob } from './schema.ts'

export type ConfigTemplate = {
	id: string
	name: string
	description: string
	doc: ConfigDocument
}

const BASE_SETTINGS: ConfigSettings = {
	shadowMode: true,
	maxConcurrentRuns: 3,
	agentMayMerge: 'none',
	sweepStartLimit: 3,
	agentDryRunDefault: false,
	killSwitch: false,
	postMergeFixTimeoutMinutes: 60,
	postMergePendingTimeoutMinutes: 180,
	stallHealthEnabled: false,
	bugbotCursorLogin: '',
	shipPrSummaryChannelId: '',
	discordNotificationsEnabled: false,
	discordNotificationsChannelId: '',
}

const BASE_JOBS: ConfigJob[] = [
	{ name: 'sweep', enabled: true, schedule: '*/15 * * * *', description: 'Sweep work-item ledger across projects.' },
	{ name: 'friction-daily', enabled: false, schedule: '0 5 * * *', description: 'Daily friction sweep.' },
	{ name: 'cleanup-legacy-reaper', enabled: false, schedule: '0 2 * * 1', description: 'Weekly legacy reaper cleanup.' },
	{ name: 'cleanup-docs-freshness', enabled: false, schedule: '0 3 * * *', description: 'Daily docs freshness pass.' },
	{ name: 'cleanup-keep-tests-tight', enabled: false, schedule: '30 3 * * *', description: 'Daily keep-tests-tight pass.' },
	{ name: 'cleanup-general-audit', enabled: false, schedule: '0 4 * * 0', description: 'Weekly general audit.' },
]

const CREDENTIAL_NEEDS = ['runner', 'model', 'github']

function basicOssProject(): ConfigProject {
	return {
		id: 'my-oss-project',
		displayName: 'My OSS Project',
		enabled: true,
		defaultRunnerId: 'devin',
		repos: [{ repoRef: 'owner/my-repo', host: 'github', enabled: true }],
		signalSources: ['github-issues', 'ci-failure', 'feedback', 'friction'],
	}
}

function kodySetupProjects(): ConfigProject[] {
	return [
		{
			id: 'kody',
			displayName: 'Kody',
			enabled: true,
			defaultRunnerId: 'devin',
			repos: [{ repoRef: 'kody-hq/kody', host: 'github', enabled: true }],
			signalSources: ['sentry', 'github-issues', 'feedback', 'friction', 'ci-failure', 'discord', 'email', 'x'],
		},
		{
			id: 'kody-video',
			displayName: 'Kody Video',
			enabled: true,
			defaultRunnerId: 'devin',
			repos: [{ repoRef: 'kentcdodds/kody-video', host: 'github', enabled: true }],
			signalSources: ['sentry', 'github-issues', 'feedback', 'friction', 'ci-failure', 'discord', 'email', 'x'],
		},
		{
			id: 'kody-exchange',
			displayName: 'Kody Exchange',
			enabled: true,
			defaultRunnerId: 'devin',
			repos: [{ repoRef: 'kentcdodds/kody-exchange', host: 'github', enabled: true }],
			signalSources: ['sentry', 'github-issues', 'feedback', 'friction', 'ci-failure', 'discord', 'email', 'x'],
		},
		{
			id: 'kody-celld',
			displayName: 'Kody Celld',
			enabled: true,
			defaultRunnerId: 'devin',
			repos: [{ repoRef: 'kody-hq/kody-celld', host: 'github', enabled: true }],
			signalSources: ['sentry', 'github-issues', 'feedback', 'friction', 'ci-failure', 'discord', 'email', 'x'],
		},
		{
			id: 'mediarss',
			displayName: 'MediaRSS',
			enabled: true,
			defaultRunnerId: 'devin',
			repos: [{ repoRef: 'kentcdodds/mediarss', host: 'github', enabled: true }],
			signalSources: ['sentry', 'github-issues', 'feedback', 'friction', 'ci-failure', 'discord', 'email', 'x'],
		},
	]
}

export const TEMPLATES: ConfigTemplate[] = [
	{
		id: 'basic-oss',
		name: 'Basic OSS repo',
		description: 'A single open-source repository with GitHub issues, CI failure, feedback, and friction signals. Shadow mode on, Devin runner, no autonomous merge.',
		doc: {
			version: CONFIG_VERSION,
			exportedAt: '',
			projects: [basicOssProject()],
			settings: { ...BASE_SETTINGS },
			jobs: BASE_JOBS,
			credentialNeeds: CREDENTIAL_NEEDS,
			templateId: 'basic-oss',
		},
	},
	{
		id: 'kody-setup',
		name: 'Kody setup',
		description: 'Five projects (Kody, Kody Video, Kody Exchange, Kody Celld, MediaRSS) with all signal sources, shadow mode on, and all cleanup jobs declared disabled. Derived from the real Kody config, minus secrets and private data.',
		doc: {
			version: CONFIG_VERSION,
			exportedAt: '',
			projects: kodySetupProjects(),
			settings: {
				...BASE_SETTINGS,
				agentMayMerge: 'low',
				bugbotCursorLogin: 'kentcdodds',
				shipPrSummaryChannelId: '1491568683737157683',
			},
			jobs: BASE_JOBS,
			credentialNeeds: CREDENTIAL_NEEDS,
			templateId: 'kody-setup',
		},
	},
]

export function getTemplate(id: string): ConfigTemplate | null {
	return TEMPLATES.find((t) => t.id === id) ?? null
}

export function listTemplates(): Array<{ id: string; name: string; description: string }> {
	return TEMPLATES.map((t) => ({ id: t.id, name: t.name, description: t.description }))
}