Kumbatio
Core

Deferral

createDeferralPresets, resolveDeferral, DEFERRAL_PRESET_IDS, and the energy-aware deferral strategy

Deferral ("snooze") is the "not now" primitive. Deferring an item is an energy statement: it declares insufficient capacity for it right now and names when it should resurface. Presets are pure (now: Date) => Date functions; the energy-aware strategy orders them so the default suggestion matches current capacity - low energy means longer deferrals, because items should resurface when capacity has plausibly recovered, not in an hour.

DEFERRAL_PRESET_IDS

const DEFERRAL_PRESET_IDS: Readonly<{
  inOneHour: 'in-1-hour'
  thisEvening: 'this-evening'
  tomorrowMorning: 'tomorrow-morning'
  nextWorkday: 'next-workday'
  nextMonday: 'next-monday'
}>

Stable preset ids, exported so configs/strategies can reference them.

DeferralPreset

A named deferral option.

Prop

Type

/>

createDeferralPresets

function createDeferralPresets(options?: DeferralPresetOptions): readonly DeferralPreset[]

Build the standard deferral presets. Times are computed in local time - "tomorrow morning" means the user's morning. Throws for hours outside the integer range 0-23.

DeferralPresetOptions

Prop

Type

/>

The five presets

IdLabelResurface time
in-1-hourIn 1 hournow + 60 minutes
this-eveningThis evening (18:00)Today at eveningHour; if that has already passed, tomorrow at eveningHour
tomorrow-morningTomorrow morning (9:00)Tomorrow at morningHour
next-workdayNext workday (9:00)Next non-weekend day at morningHour
next-mondayNext Monday (9:00)The coming Monday at morningHour (a full week ahead when today is Monday)
import { createDeferralPresets, resolveDeferral, DEFERRAL_PRESET_IDS } from '@kumbatio/energy-system'

const presets = createDeferralPresets({ morningHour: 8 })
const resurfaceAt = resolveDeferral(presets, DEFERRAL_PRESET_IDS.tomorrowMorning)
// epoch ms for tomorrow 08:00 local time

resolveDeferral

function resolveDeferral(
  presets: readonly DeferralPreset[],
  presetId: string,
  now?: Date,   // default: new Date()
): number | null

Resolve a preset id to a resurface timestamp (epoch ms). Returns null for an unknown id - callers decide whether that is an error.

deferralStrategy

const deferralStrategy: AdaptationStrategy<DeferralConfig>

The energy-aware ordering strategy (name: 'deferral'). Resolve it directly or through the engine like any built-in strategy.

DeferralConfig

Prop

Type

/>

Values per level

LevelorderedPresetIdsdefaultPresetId
100in-1-hour, this-evening, tomorrow-morning, next-workday, next-mondayin-1-hour
75in-1-hour, this-evening, tomorrow-morning, next-workday, next-mondayin-1-hour
50this-evening, tomorrow-morning, in-1-hour, next-workday, next-mondaythis-evening
25tomorrow-morning, next-workday, this-evening, next-monday, in-1-hourtomorrow-morning
0tomorrow-morning, next-monday, next-workday, this-evening, in-1-hourtomorrow-morning