Skip to content
← Public packages

@kentcdodds/codebase-cleanup

Cursor cloud agents for legacy cleanup, docs freshness, tight tests, and prod CI fixes, plus a weekly Devin general audit.

FollowFork

Files

prompts.ts

67 lines · 2.3 KB · TypeScript
import {
	devinPromptFooter,
	launcherOf,
	notifyPhrase,
	privateNotifyPhrase,
	sharedPromptFooter,
	type AutomationId,
} from './shared.ts'
import { templates } from './prompts/templates.ts'

export type ResolvePromptInput = {
	automation: AutomationId
	repo: string
	branch: string
	/** Optional CI / context block inserted at {{extra}}. */
	extra?: string
	/** Notify target (Kody export spec) from config; null/omitted = report in the PR. */
	notify?: string | null
	/** Override a template (for tests or set-config of prompt text). */
	templateOverride?: string
	/** Exact branch name the agent must use (cleanup/<automation>-<date>...). */
	branchName?: string | null
	/** Scoped runs: markdown list of files and reasons, inserted at {{files}}. */
	files?: string
	/** Scoped runs: the git range, inserted at {{range}}. */
	range?: string
	/** Scoped runs: reason defs for kinds present in the file list, inserted at {{reasons}}. */
	reasons?: string
}

/**
 * Resolve the agent prompt for one automation + repo.
 * Templates are unique-job only; the launcher's footer is appended here
 * (shipping footer, or private-report footer for Devin-launched automations).
 */
export function resolvePrompt(input: ResolvePromptInput) {
	const template = input.templateOverride ?? templates[input.automation]
	const devin = launcherOf(input.automation) === 'devin'
	const body = template
		.replaceAll('{{repo}}', input.repo)
		.replaceAll('{{branch}}', input.branch)
		.replaceAll('{{files}}', input.files ?? '')
		.replaceAll('{{range}}', input.range ?? '')
		.replaceAll('{{reasons}}', input.reasons ?? '')
		.replaceAll('{{branchName}}', input.branchName ?? '')
		.replaceAll('{{extra}}', input.extra?.trim() ? input.extra.trim() + '\n' : '')
		.replaceAll(
			'{{notify}}',
			devin ? privateNotifyPhrase(input.notify) : notifyPhrase(input.notify),
		)
	const footer = devin ? devinPromptFooter(input.notify) : sharedPromptFooter(input.notify, input.branchName)

	return `${body.trim()}\n\n${footer}`
}

/**
 * List editable prompt template ids and a short preview.
 */
export function listPromptTemplates() {
	return (Object.keys(templates) as AutomationId[]).map((id) => ({
		id,
		chars: templates[id].length,
		preview: templates[id].slice(0, 120).replace(/\s+/g, ' ').trim(),
	}))
}

export { templates }