feat(scheduler): project a timeline onto the calendar and build the run sheet #79

Merged
abiwab merged 2 commits from feat/scheduler-projection into main 2026-10-04 12:15:05 +02:00
Owner

PR 3 of the 1.4.0 scheduler plan (`.notes/plan-scheduler-1-4.md`, section 11).

`@gram-lang/scheduler` gets its second level: from a serving time, a time zone and the cook's availability, it places a recipe on the calendar.

  • `project(recipes, context)`: ends the timeline at `serveAt`, then walks back from the service and moves the rests written as a range so the cook's own work falls when they are available: a longer rest moves the work earlier (the evening before), a shorter one later (the morning), in the direction `rests` prefers, never beyond the range, never for an exact rest. Each move is a re-layout of the graph (new `restOverrides` option), so dependencies and named tracks are re-checked, and a move that introduces a track contention is refused. Greedy and explainable; every change is listed in `adjustments`.
  • Diagnostics of the reader's context (not warnings): `ACTIVE_OUTSIDE_AVAILABILITY`, `ACTIVE_BLOCK_EXCEEDS_AVAILABILITY` (a stretch of work that cannot be interrupted longer than any availability, so no rest could fix it), `SESSION_DAY_MISMATCH`, `START_IN_PAST`, `MULTI_RECIPE_UNSUPPORTED` (the signature already takes an array).
  • `runSheet(plan)`: the structure of a production sheet (days, tasks of each day in order, adjustments on the rest they concern). Nothing rounded or translated: that is for the renderer.
  • No date library and no `Date.now()`: instants are minutes since the epoch, local time is read with `Intl.DateTimeFormat` and an explicit zone. A day of 23 or 25 hours counts for what it lasts; a time that does not exist becomes the next valid one, a time that happens twice is the first.
  • Availability is an object (a default range, exceptions by weekday and by date; `[]` is not available; a range that ends before it starts runs past midnight).

Checks:

  • Invariant 7 on 300 random recipes: every adjustment stays in its range, only ranges move, and with no unavailability the plan is the layout moved to the serving time.
  • Invariant 8: the same plan and sheet, byte for byte, under six values of `TZ` (a fixture run in subprocesses), across both DST changes.
  • New conformance suite `conformance/schedule/` (13 `layout-`, 11 `project-` cases), independent of the pipeline so a Rust port can use it. The goldens were read: the night stretch (480 to 870 min), the shrink when the longest rests are asked for, a 24 h rest over the autumn and spring clock changes, and an exact rest left alone with its diagnostic.

Not done: I could not build a case where stretching a rest on a named track is refused for a contention, because ALAP chains a track's uses and moves the whole path with it. The guard is there and tested through the layout, but no golden exercises the refusal.

PR 3 of the 1.4.0 scheduler plan (\`.notes/plan-scheduler-1-4.md\`, section 11). \`@gram-lang/scheduler\` gets its second level: from a serving time, a time zone and the cook's availability, it places a recipe on the calendar. - \`project(recipes, context)\`: ends the timeline at \`serveAt\`, then walks back from the service and moves the rests written as a range so the cook's own work falls when they are available: a longer rest moves the work earlier (the evening before), a shorter one later (the morning), in the direction \`rests\` prefers, never beyond the range, never for an exact rest. Each move is a re-layout of the graph (new \`restOverrides\` option), so dependencies and named tracks are re-checked, and a move that introduces a track contention is refused. Greedy and explainable; every change is listed in \`adjustments\`. - Diagnostics of the reader's context (not warnings): \`ACTIVE_OUTSIDE_AVAILABILITY\`, \`ACTIVE_BLOCK_EXCEEDS_AVAILABILITY\` (a stretch of work that cannot be interrupted longer than any availability, so no rest could fix it), \`SESSION_DAY_MISMATCH\`, \`START_IN_PAST\`, \`MULTI_RECIPE_UNSUPPORTED\` (the signature already takes an array). - \`runSheet(plan)\`: the structure of a production sheet (days, tasks of each day in order, adjustments on the rest they concern). Nothing rounded or translated: that is for the renderer. - No date library and no \`Date.now()\`: instants are minutes since the epoch, local time is read with \`Intl.DateTimeFormat\` and an explicit zone. A day of 23 or 25 hours counts for what it lasts; a time that does not exist becomes the next valid one, a time that happens twice is the first. - Availability is an object (a default range, exceptions by weekday and by date; \`[]\` is not available; a range that ends before it starts runs past midnight). Checks: - Invariant 7 on 300 random recipes: every adjustment stays in its range, only ranges move, and with no unavailability the plan is the layout moved to the serving time. - Invariant 8: the same plan and sheet, byte for byte, under six values of \`TZ\` (a fixture run in subprocesses), across both DST changes. - New conformance suite \`conformance/schedule/\` (13 \`layout-*\`, 11 \`project-*\` cases), independent of the pipeline so a Rust port can use it. The goldens were read: the night stretch (480 to 870 min), the shrink when the longest rests are asked for, a 24 h rest over the autumn and spring clock changes, and an exact rest left alone with its diagnostic. Not done: I could not build a case where stretching a rest on a named track is refused for a contention, because ALAP chains a track's uses and moves the whole path with it. The guard is there and tested through the layout, but no golden exercises the refusal.
abiwab merged commit 55b4c21cdc into main 2026-10-04 12:15:05 +02:00
abiwab deleted branch feat/scheduler-projection 2026-10-04 12:15:05 +02:00
Sign in to join this conversation.
No description provided.