gram/packages/kitchen
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
..
scripts feat(kitchen): emit mise en place and per-section and upfront schedules 2026-09-29 20:42:13 +02:00
src chore: release v1.6.0 2026-12-01 14:38:56 +01:00
tests Merge pull request 'feat(kitchen): warn when an alias written after a blank loses its quantity' (#320) from fix/alias-after-blank into dev/1.6 2026-11-29 21:09:26 +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: rename @gram/compiler package to @gram/kitchen 2026-06-18 13:29:11 +02:00

@gram-lang/kitchen

npm License: GPL v3

Part of the Gram monorepo · Documentation

The compiler for the Gram recipe DSL. Takes a typed Recipe AST (produced by @gram-lang/parser or composed by @gram-lang/modules) and compiles it into structured recipe JSON: aggregating shopping lists, processing sections, resolving compound quantities and same-family unit ratios, splitting mise en place by section, and laying out the task graph and default schedule. Scheduling itself is handled by @gram-lang/scheduler, which kitchen feeds with a neutral list of tasks.

Installation

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

Usage

import { getAST } from '@gram-lang/parser';
import { compile } from '@gram-lang/kitchen';

const source = `
## My Recipe

[Mix] @flour{200g} and @water{100ml} for ~{5min}.
`;

const ast = getAST(source);
const result = compile(ast);

console.log(result.shopping_list);
console.log(result.schedule.totalTime);  // Default timeline, mise en place right before each section (minutes)
console.log(result.tasks);               // The list of tasks and what each one waits for
console.log(result.miseEnPlace);         // How long each section's own preparation takes

// Any other timeline comes from the same tasks, without compiling again:
// import { layout } from '@gram-lang/scheduler';
// layout(result.tasks, { miseEnPlace: 'upfront', rests: 'longest' });

Structure

  • src/core.ts: main compiler entry point (compile).
  • src/processor.ts: processes step-by-step block content, local scopes, and timers.
  • src/section.ts: compiles individual recipe sections.
  • src/shopping.ts: deduplicates and aggregates ingredients into a master shopping list.
  • src/terms.ts, src/compound.ts: normalizes and evaluates compound quantities (1 cup + 2 tbsp).
  • src/ratio.ts: resolves unit ratios (resolveRatios) and scales proportional timers.
  • src/mise-en-place.ts, src/metrics.ts: splits preparation (ingredients, cookware, intermediates) by section and computes preparation time.
  • src/task-graph.ts, src/step-timing.ts: builds the task graph (steps, timers, preparations) and dependencies handed to the scheduler.
  • src/schedule-mode.ts, src/recompute.ts: scheduleFor(), scheduleTimes(), and recomputeSchedule() after scaling or ratio resolution.
  • src/schedule-warnings.ts, src/overlap-warnings.ts: turns scheduler diagnostics (DAY_OVERFLOW, track contention) and passive cookware overlaps (PASSIVE_OVERLAP_SAME_COOKWARE) into compiler warnings.
  • src/legacy-timings.ts: deprecated steps[].timings and metrics time fields, kept until 2.0.0.
  • src/graph.ts: traverses relative quantities and runs cycle detection (DFS).
  • src/registry.ts: tracks declared ingredients, cookware, and references across the recipe.
  • src/scale/: applies scale factors to quantities throughout the compiled recipe.
  • src/warnings.ts: collects non-fatal compilation warnings.
  • src/schemas.ts: Zod schemas for compiler options.
  • src/utils.ts: helpers for slugification, minification, and time unit conversions.

License

Licensed under the GPL-3.0 license.