gram/packages/scheduler
Repository files (latest commit first)
Filename Latest commit message Latest commit date
abiwab 7d67ccadaf
All checks were successful
CI / Build & Test (pull_request) Successful in 9m18s
chore: release v1.6.0
2026-12-01 14:38:56 +01:00
..
src feat(scheduler): accept 12-hour am/pm times in availability, meal times, serve and find 2026-11-19 14:14:46 +01:00
tests feat(scheduler): accept 12-hour am/pm times in availability, meal times, serve and find 2026-11-19 14:14:46 +01:00
CHANGELOG.md chore: release v1.6.0 2026-12-01 14:38:56 +01:00
package.json chore: release v1.6.0 2026-12-01 14:38:56 +01:00
README.md docs: rewrite root and package READMEs for v1.6 2026-11-29 22:35:50 +01:00
tsconfig.json refactor(scheduler): extract the scheduling engine into its own package 2026-10-04 11:26:53 +02:00

@gram-lang/scheduler

npm License: GPL v3

Part of the Gram monorepo · Documentation

The scheduling engine behind Gram recipes. Lays tasks out on a timeline (as-late-as-possible backward pass, named-track contention, mise en place placement, working days) from a neutral description of the work, without depending on the Gram AST or compiled recipe format. @gram-lang/kitchen feeds it and writes the result into the compiled JSON.

Installation

npm install @gram-lang/scheduler
# or
bun add @gram-lang/scheduler

Usage

import { getAST } from '@gram-lang/parser';
import { compile } from '@gram-lang/kitchen';
import { layout, project, runSheet } from '@gram-lang/scheduler';

const compiled = compile(getAST('## Dough\n\n[Mix] @flour{500g}.\n\n[Rest] ~_{8-16h}.\n'));

// 1. Re-lay out the timeline without re-compiling
const { schedule } = layout(compiled.tasks, { miseEnPlace: 'upfront', rests: 'balanced' });

// 2. Project onto a calendar working backward from serving time
const plan = project([{ graph: compiled.tasks }], {
  serveAt: '2026-10-17T20:00',
  timeZone: 'Europe/Paris',
  availability: { daily: [{ start: '08:00', end: '22:00' }] }
});

// 3. Group into days, kitchen visits, and background threads
const sheet = runSheet(plan, { graph: compiled.tasks });

API overview

  • layout(tasks, { miseEnPlace, rests }): lays a task graph out on a timeline, in minutes from the start.
  • project([{ graph }], { serveAt, timeZone, availability }): places that timeline on the calendar ending at the serving time, stretching range rests so active work falls within your available hours. Reads no system clock or machine time zone, so the same input always yields the same plan.
  • runSheet(plan | schedule, { graph, context }): groups a plan (or a bare schedule, in days before service) into days, kitchen visits, and background threads, with each visit's margin.
  • findServeTimes() and earliestServe(): test candidate serving times with project() and report which ones work and why the others do not.
  • parseAvailability(), parseMealTimes(), isTimeZone(), availabilityEntries(), and isCalendarDate(): parse and validate project availability settings (08:00-22:00, fri=18:00-22:00, 2026-10-09=none) consistently across the CLI and editor, rejecting nonexistent calendar dates.
  • visitSections(): returns the sections to name a run-sheet visit after.
  • MISE_EN_PLACE_MODES (perSection, upfront, perDay) and REST_CHOICES (shortest, balanced, longest): valid layout() options with defaults and guards.

License

Licensed under the GPL-3.0 license.