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

add-progress-note.ts

33 lines · 1.2 KB · TypeScript
import { addProgressNote as addNote, loadPlanStore, savePlanStore } from '../../core/plan.ts'

/**
 * Add a dated progress note to a plan (same YYYY-MM-DD, America/Denver format
 * as the existing planning adapter).
 *
 * @example
 * import addProgressNote from 'kody:@kody/kody-factory/plans/add-progress-note'
 * await addProgressNote({ id: 'plan_abc', text: 'Decided on the approach.' })
 */
export default async function addProgressNote(input: {
	id: string
	text: string
	date?: string
	author?: string
	dryRun?: boolean
}) {
	if (!input?.id) throw new Error('plans/add-progress-note: id is required')
	if (!input.text?.trim()) throw new Error('plans/add-progress-note: text is required')

	const store = await loadPlanStore()
	const plan = store.plans[input.id]
	if (!plan) throw new Error(`plans/add-progress-note: plan not found: ${input.id}`)

	const date = input.date ?? new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Denver' }).format(new Date())
	const updated = addNote(plan, { date, text: input.text.trim(), author: input.author })

	if (input.dryRun) return { plan: updated, persisted: false }

	store.plans[updated.id] = updated
	await savePlanStore(store)
	return { plan: updated, persisted: true }
}