assignment-user-matcher 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +56 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +8 -1
  5. package/dist/matcher.class.d.ts +1 -1
  6. package/dist/matcher.class.js +1 -1
  7. package/dist/scheduling/constraints/constraint.d.ts.map +1 -1
  8. package/dist/scheduling/constraints/constraint.js +7 -1
  9. package/dist/scheduling/constraints/contract.d.ts +1 -0
  10. package/dist/scheduling/constraints/contract.d.ts.map +1 -1
  11. package/dist/scheduling/constraints/contract.js +61 -16
  12. package/dist/scheduling/constraints/fairness.js +1 -1
  13. package/dist/scheduling/constraints/overtime.d.ts.map +1 -1
  14. package/dist/scheduling/constraints/overtime.js +4 -2
  15. package/dist/scheduling/constraints/site-eligibility.d.ts +11 -0
  16. package/dist/scheduling/constraints/site-eligibility.d.ts.map +1 -0
  17. package/dist/scheduling/constraints/site-eligibility.js +52 -0
  18. package/dist/scheduling/constraints/site-home.d.ts +14 -0
  19. package/dist/scheduling/constraints/site-home.d.ts.map +1 -0
  20. package/dist/scheduling/constraints/site-home.js +43 -0
  21. package/dist/scheduling/constraints/site-travel-gap.d.ts +19 -0
  22. package/dist/scheduling/constraints/site-travel-gap.d.ts.map +1 -0
  23. package/dist/scheduling/constraints/site-travel-gap.js +88 -0
  24. package/dist/scheduling/contract-hours.d.ts +42 -0
  25. package/dist/scheduling/contract-hours.d.ts.map +1 -0
  26. package/dist/scheduling/contract-hours.js +104 -0
  27. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  28. package/dist/scheduling/engine/objective.js +5 -0
  29. package/dist/scheduling/engine/state.d.ts.map +1 -1
  30. package/dist/scheduling/engine/state.js +1 -0
  31. package/dist/scheduling/engine/timeline.d.ts +2 -0
  32. package/dist/scheduling/engine/timeline.d.ts.map +1 -1
  33. package/dist/scheduling/index.d.ts +4 -1
  34. package/dist/scheduling/index.d.ts.map +1 -1
  35. package/dist/scheduling/index.js +14 -1
  36. package/dist/scheduling/model.d.ts +11 -0
  37. package/dist/scheduling/model.d.ts.map +1 -1
  38. package/dist/scheduling/model.js +81 -1
  39. package/dist/scheduling/operations.d.ts +17 -1
  40. package/dist/scheduling/operations.d.ts.map +1 -1
  41. package/dist/scheduling/operations.js +71 -3
  42. package/dist/scheduling/provenance.d.ts +2 -2
  43. package/dist/scheduling/provenance.d.ts.map +1 -1
  44. package/dist/scheduling/provenance.js +15 -1
  45. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  46. package/dist/scheduling/scheduler.class.js +4 -1
  47. package/dist/scheduling/sites.d.ts +35 -0
  48. package/dist/scheduling/sites.d.ts.map +1 -0
  49. package/dist/scheduling/sites.js +112 -0
  50. package/dist/scheduling/types.d.ts +120 -1
  51. package/dist/scheduling/types.d.ts.map +1 -1
  52. package/package.json +13 -1
package/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/assignment-user-matcher.svg)](https://badge.fury.io/js/assignment-user-matcher)
4
4
  [![CI Pipeline](https://github.com/ViljarVoidula/assignment-user-matcher/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/ViljarVoidula/assignment-user-matcher/actions/workflows/npm-publish.yml)
5
+ [![5xer Cloud](https://img.shields.io/badge/%E2%98%81%EF%B8%8F_5xer_Cloud-Sign_up-7C3AED)](https://5xer.com)
5
6
 
6
7
  <!-- Add other badges if you have them, e.g., build status, test coverage -->
7
8
 
@@ -9,6 +10,12 @@
9
10
 
10
11
  It leverages the speed and efficiency of Redis to deliver a robust solution perfect for scenarios like call centers, customer support queues, back-office operations, and more.
11
12
 
13
+ > ### ☁️ Don't want to run your own Redis?
14
+ >
15
+ > **[5xer Cloud](https://5xer.com)** offers this matching engine as a fully managed service — no infrastructure, no maintenance sweeps, no Redis ops. On top of that, you get a polished no-code UI: a mobile-friendly PWA where workers see their assignments, accept, and complete work from anywhere — no client to install, no code to write.
16
+ >
17
+ > **[Sign up at 5xer.com →](https://5xer.com)** — getting started is free.
18
+
12
19
  ## The Challenge: Efficiently Connecting Users to Work
13
20
 
14
21
  In many applications, from customer service platforms to internal task management systems, the core challenge remains the same: how do you quickly and accurately assign incoming work (assignments) to the best available person (user)? This becomes particularly complex when dealing with:
@@ -1334,6 +1341,9 @@ pnpm benchmark:learning -- 300 8000 10 20260611
1334
1341
  # arguments: <users> <assignmentsPerRound> <rounds> <seed>
1335
1342
  ```
1336
1343
 
1344
+ Set `REDIS_URL` to benchmark against a non-default Redis endpoint. Benchmark
1345
+ runs use isolated, unique key prefixes and never call `FLUSHDB`.
1346
+
1337
1347
  Output includes:
1338
1348
 
1339
1349
  1. Per-mode throughput and latency (`baseline`, `learning-shadow`, `learning-live`)
@@ -1613,6 +1623,12 @@ This demonstrates the library's impressive performance even with large numbers o
1613
1623
 
1614
1624
  A companion engine for **rostering**: generating fair, constraint-compliant timetables that assign employees to shifts over a period. Unlike the matcher, this module is **pure and Redis-free** — `solveSchedule(input)` is a synchronous in-process function; wrap it in your own queue if you need one.
1615
1625
 
1626
+ **Import it from the `assignment-user-matcher/scheduling` subpath** to get the engine without the Redis-backed matcher. The root barrel pulls in `redis`; this one pulls nothing but the scheduler, so it loads in a browser, a Web Worker or an edge runtime as well as in Node. (Every example below uses the root import for continuity; the subpath exports the same names.)
1627
+
1628
+ ```ts
1629
+ import { solveSchedule } from 'assignment-user-matcher/scheduling';
1630
+ ```
1631
+
1616
1632
  ```ts
1617
1633
  import { solveSchedule } from 'assignment-user-matcher';
1618
1634
 
@@ -1679,8 +1695,46 @@ Break entitlements are checked against shift design: `unpaidBreakMinutes` (deduc
1679
1695
 
1680
1696
  **Overtime** is regulated separately from total working time where national law does so. `rules.overtime` defines the ordinary baseline (`ordinaryPerDayMinutes` / `ordinaryPerWeekMinutes`; a person's `contract.weeklyMinutes` overrides the weekly figure, so a part-timer's overtime starts at their agreed hours), caps the overtime portion per rolling 24h or per rolling window, and with `requiresConsent` makes any overtime conditional on the employee's recorded `overtimeConsent`. With `compensation: 'timeOff'`, each employee's period overtime accrues a `timeOffInLieu` entry in `result.ledger`.
1681
1697
 
1698
+ **Contracted hours and part-time.** A person's contracted week is stated either as minutes (`contract.weeklyMinutes`) or as a fraction of full time (`contract.fte`, `0 < fte <= 1`, e.g. `0.5` for half-time). An `fte` resolves against `rules.contract.fullTimeWeeklyMinutes`, falling back to `rules.overtime.ordinaryPerWeekMinutes`; with neither the input is rejected rather than a working week guessed. The resolved week is read in one place (`ModelContext.contractedWeeklyMinutes`) by everything that needs it: the overtime baseline, pro-rata fairness (`proRataByContract`), and the **contract-hours objective**, which pulls every person with a contract towards `weekly × periodDays / 7` at the soft level (`objectives.contractHoursWeight`, default `1` point per hour of deviation, `0` to disable) — so a half-timer is planned half the hours of a full-timer instead of being filled to the statutory ceiling. Two optional bounds on `rules.contract`: `maxOverMinutes` (hard cap at contract plus the allowance; `0` means never over contract — omit when your `overtime` rule governs the surplus) and `maxUnderMinutes` (a shortfall beyond it is reported as a soft violation). `result.contractHours` / `ComplianceReport.contractHours` list planned against contracted minutes per person, and `rankCandidates` reports `contractDeltaMinutes` and ranks people with contract headroom ahead of those a shift would push over.
1699
+
1700
+ **Public holidays** are caller-supplied ISO dates in `calendar.publicHolidays`. They mark `ShiftInstance.isPublicHoliday`, which drives `restDays.holidayAllowed` and `compensatoryRestWithinDays.holiday`, the `holidays` fairness dimension and the `holiday` cost premium. The engine ships no holiday calendar — a host resolves the roster's location to dates and passes them in.
1701
+
1682
1702
  **Duty-type quotas** (`rules.dutyQuotas`) cap how much of one duty type a person may hold over a rolling window, matched on `shiftTypeTag` — e.g. "at most 30 hours of stand-by in any 28 days". `maxMinutes` counts _elapsed_ duty minutes (a stand-by cap limits clock occupation, which is exactly the time a duty classification keeps out of the working-time budget); `maxCount` caps occurrences.
1683
1703
 
1704
+ ### Multi-site rosters
1705
+
1706
+ When you run several sites in one city, site data makes the solver and the call-in suggestions location-aware:
1707
+
1708
+ - Add a `sites` registry with optional coordinates and an asymmetric `travelMinutesTo` matrix.
1709
+ - Set `Employee.homeSiteId` for the soft home-site preference and `Employee.siteIds` as a hard allow-list.
1710
+ - Use `objectives.homeSiteWeight` to make the solver prefer keeping people at their home site.
1711
+ - `repairSchedule` and `rankCandidates` measure "nearby" from the candidate's nearest same-day assignment, falling back to `homeSiteId`, and include `originSiteId`, `travelMinutes`, `distanceKm` and `isHomeSite` on every `RepairCandidate`.
1712
+
1713
+ ```ts
1714
+ const result = solveSchedule({
1715
+ period: { startDate: '2026-01-05', endDate: '2026-01-11', timeZone: 'Europe/Berlin' },
1716
+ employees: [
1717
+ { id: 'alice', tags: ['nurse'], timeOff: [], homeSiteId: 'north', siteIds: ['north', 'south'] },
1718
+ { id: 'bob', tags: ['nurse'], timeOff: [], homeSiteId: 'south', siteIds: ['south'] },
1719
+ ],
1720
+ shifts: [
1721
+ { id: 'day', name: 'Day', startTime: '08:00', endTime: '16:00', siteId: 'north' },
1722
+ { id: 'late', name: 'Late', startTime: '14:00', endTime: '22:00', siteId: 'south' },
1723
+ ],
1724
+ sites: [
1725
+ { id: 'north', lat: 52.5, lng: 13.4, travelMinutesTo: { south: 35 } },
1726
+ { id: 'south', lat: 52.4, lng: 13.5, travelMinutesTo: { north: 40 } },
1727
+ ],
1728
+ // Fallback only used when a matrix entry is missing:
1729
+ travelSpeedKmh: 30,
1730
+ objectives: { homeSiteWeight: 1 },
1731
+ });
1732
+ ```
1733
+
1734
+ Travel-time resolution order: explicit matrix entry → haversine kilometres ÷ `travelSpeedKmh` → unknown. When minutes are unknown, suggestions still show `distanceKm` for host-side re-sorting.
1735
+
1736
+ The `site-travel-gap` rule is a hard constraint: two consecutive assignments at different sites must leave at least the travel time between them. It reads the same person timeline as the rest rules, so it works across contracts (`personId`) and across the period boundary via `history` entries that carry `siteId`. It enforces the gap only; it does not treat travel time as working time (CJEU C-266/14). Because the default 11h `min-rest` rule masks most intra-day switches, the gap rule mainly matters when you have relaxed `minRestMinutes` or configured a `dailyRest` rule that permits split shifts.
1737
+
1684
1738
  ### Labour cost
1685
1739
 
1686
1740
  `Employee.cost` prices the roster: hourly rate, premium bands (`night` / `sunday` / `holiday`, stacked additively or by maximum), an overtime step (`overtimeAfterMinutes` + `overtimeMultiplier`), and a `standbyRateFraction` paying the non-working remainder of a duty-classified span (e.g. stand-by owed at 1/10 of the wage). When any employee carries a cost model, `result.cost` reports `{ totalCents, byEmployee }`.
@@ -1698,6 +1752,8 @@ diagnoseInfeasibility(input); // why it cannot be solved, before solving
1698
1752
 
1699
1753
  `repairSchedule` is the call-in path: everything untouched is pinned, so you get a **diff** rather than an unrecognisable new roster, plus a ranked list of who can lawfully cover, each with compliance verdicts, marginal cost and a rationale. All four share the solver's constraint set — there is deliberately no second validation path. `checkCompliance` also runs the solver's ledger pass, so a hand-edited roster reports the same accrued obligations (compensatory rest, late-cancellation pay, protection fallbacks, time off in lieu) that `solveSchedule` would report for the same assignments — a human override can never validate as "compliant but owing nothing".
1700
1754
 
1755
+ `expandShiftInstances(input)` returns the dated planning grid a host should render before anything is assigned — the same `<templateId>@<date>` ids every other call refers to. Use it so the grid ids never drift from the instances the solver will judge.
1756
+
1701
1757
  ### Compliance boundary
1702
1758
 
1703
1759
  Ranking uses declared qualifications, contractual availability, legal limits, cost, and fairness debt computed from **realised** assignment counts. It never consumes reliability scores, no-show prediction, acceptance history or learned per-worker behaviour, and the module is not wired to the matcher's learning layer. Under AI Act Annex III point 4(b), allocating on individual behaviour or traits is high-risk, and the Art 6(3) narrow-task filter has an absolute carve-back for profiling — so that boundary is what keeps this a constraint solver. `result.provenance` records `{ engineVersion, seed, rulesHash, profilingFree }` for audit.
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { WorkflowDefinition, WorkflowDefinitionInput, WorkflowDefinitionSum
5
5
  export { explainMatchScore, type MatchScoreExplanation } from './scoring/match-score';
6
6
  export { extractMatchFeatures, cosineSimilarity } from './learning/features';
7
7
  export { synthesizeRoutingWeights, DEFAULT_AUTO_WEIGHTS_OPTIONS } from './learning/auto-weights';
8
- export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, hours, days, weeklyAverageOver, type AssignmentPair, type AvailabilityRule, type ComplianceReport, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type HistoricalAssignment, type InfeasibilityReport, type LedgerEntry, type ModelContext, type NightWorkRule, type ObjectiveWeights, type OvertimeRule, type RepairCandidate, type RepairResult, type RuleVerdict, type ScheduleInput, type ScheduleResult, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type TimeOffEntry, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
8
+ export { ShiftScheduler, solveSchedule, ScheduleValidationError, DEFAULT_MIN_REST_MINUTES, PeriodClock, expandShiftInstances, checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, hours, days, weeklyAverageOver, DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, type AssignmentPair, type AvailabilityRule, type BreakRule, type ClockRange, type ClockRangeConfig, type ComplianceReport, type ConsecutiveRule, type ConstraintOptions, type ConstraintViolation, type DailyRestRule, type Disruption, type DutyClassification, type DutyQuota, type Employee, type EmployeeContract, type ContractHoursRule, type ContractHoursSummary, type EmployeeCost, type EmployeeProtection, type EngagementRule, type FairnessRule, type HistoricalAssignment, type InfeasibilityReport, type LedgerEntry, type MinuteRange, type ModelContext, type NightVolumeQuota, type NightWorkRule, type NoticeRule, type ObjectiveWeights, type OvertimeRule, type PersonTimeline, type Qualification, type RepairCandidate, type RepairResult, type RestDayRule, type RollingAverage, type RuleVerdict, type ScheduleInput, type ScheduleProvenance, type ScheduleResult, type ScheduledAssignment, type SchedulingConstraint, type SearchState, type Severity, type ShiftInstance, type ShiftTemplate, type Site, type SiteIndex, type TimeOffEntry, type TimelineEntry, type TimelineIndex, type WeeklyRestRule, type WorkingTimeLimits, type WorkingTimeRules, } from './scheduling';
9
9
  export { WorkflowBuilder, WorkflowStepBuilder, workflow, linearWorkflow, approvalWorkflow } from './workflow-builder';
10
10
  export { normalizeWorkflowDefinition, validateWorkflowDefinition } from './workflow-validation';
11
11
  export * from './utils/cidr';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,iBAAiB,CAAC;AAEhD,YAAY,EACR,UAAU,EACV,cAAc,EACd,OAAO,EACP,KAAK,EACL,UAAU,EACV,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,SAAS,EACT,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,oBAAoB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7E,YAAY,EACR,kBAAkB,E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GACxB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtH,OAAO,EAAE,2BAA2B,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAGhG,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC7B,eAAe,iBAAiB,CAAC"}
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.AssignmentMatcher = exports.createKeyBuilders = exports.validateWorkflowDefinition = exports.normalizeWorkflowDefinition = exports.approvalWorkflow = exports.linearWorkflow = exports.workflow = exports.WorkflowStepBuilder = exports.WorkflowBuilder = exports.weeklyAverageOver = exports.days = exports.hours = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.PeriodClock = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.solveSchedule = exports.ShiftScheduler = exports.DEFAULT_AUTO_WEIGHTS_OPTIONS = exports.synthesizeRoutingWeights = exports.cosineSimilarity = exports.extractMatchFeatures = exports.explainMatchScore = exports.userCoversTag = exports.lintAssignment = void 0;
20
+ exports.AssignmentMatcher = exports.createKeyBuilders = exports.validateWorkflowDefinition = exports.normalizeWorkflowDefinition = exports.approvalWorkflow = exports.linearWorkflow = exports.workflow = exports.WorkflowStepBuilder = exports.WorkflowBuilder = exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.expandShiftInstances = exports.PeriodClock = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.solveSchedule = exports.ShiftScheduler = exports.DEFAULT_AUTO_WEIGHTS_OPTIONS = exports.synthesizeRoutingWeights = exports.cosineSimilarity = exports.extractMatchFeatures = exports.explainMatchScore = exports.userCoversTag = exports.lintAssignment = void 0;
21
21
  const matcher_class_1 = __importDefault(require("./matcher.class"));
22
22
  exports.AssignmentMatcher = matcher_class_1.default;
23
23
  // Pre-flight lint (pure, Redis-free) — usable host-side before addAssignment
@@ -42,6 +42,9 @@ Object.defineProperty(exports, "solveSchedule", { enumerable: true, get: functio
42
42
  Object.defineProperty(exports, "ScheduleValidationError", { enumerable: true, get: function () { return scheduling_1.ScheduleValidationError; } });
43
43
  Object.defineProperty(exports, "DEFAULT_MIN_REST_MINUTES", { enumerable: true, get: function () { return scheduling_1.DEFAULT_MIN_REST_MINUTES; } });
44
44
  Object.defineProperty(exports, "PeriodClock", { enumerable: true, get: function () { return scheduling_1.PeriodClock; } });
45
+ // The dated occurrences a host draws a planning grid from, with the same
46
+ // `<templateId>@<date>` ids every other call refers to.
47
+ Object.defineProperty(exports, "expandShiftInstances", { enumerable: true, get: function () { return scheduling_1.expandShiftInstances; } });
45
48
  // Operational APIs: validate a hand-edited roster, explain a candidate,
46
49
  // repair around a call-in, diagnose an impossible problem.
47
50
  Object.defineProperty(exports, "checkCompliance", { enumerable: true, get: function () { return scheduling_1.checkCompliance; } });
@@ -53,6 +56,10 @@ Object.defineProperty(exports, "diagnoseInfeasibility", { enumerable: true, get:
53
56
  Object.defineProperty(exports, "hours", { enumerable: true, get: function () { return scheduling_1.hours; } });
54
57
  Object.defineProperty(exports, "days", { enumerable: true, get: function () { return scheduling_1.days; } });
55
58
  Object.defineProperty(exports, "weeklyAverageOver", { enumerable: true, get: function () { return scheduling_1.weeklyAverageOver; } });
59
+ Object.defineProperty(exports, "DEFAULT_CONTRACT_HOURS_WEIGHT", { enumerable: true, get: function () { return scheduling_1.DEFAULT_CONTRACT_HOURS_WEIGHT; } });
60
+ Object.defineProperty(exports, "contractedPeriodMinutes", { enumerable: true, get: function () { return scheduling_1.contractedPeriodMinutes; } });
61
+ Object.defineProperty(exports, "fullTimeWeeklyMinutes", { enumerable: true, get: function () { return scheduling_1.fullTimeWeeklyMinutes; } });
62
+ Object.defineProperty(exports, "resolveContractedWeeklyMinutes", { enumerable: true, get: function () { return scheduling_1.resolveContractedWeeklyMinutes; } });
56
63
  // Workflow builder DSL
57
64
  var workflow_builder_1 = require("./workflow-builder");
58
65
  Object.defineProperty(exports, "WorkflowBuilder", { enumerable: true, get: function () { return workflow_builder_1.WorkflowBuilder; } });
@@ -917,7 +917,7 @@ export default class AssignmentMatcher implements WorkflowHost {
917
917
  * Start the periodic maintenance tick. Idempotent; a second call with
918
918
  * different options replaces the first.
919
919
  *
920
- * @param options.intervalMs how often to sweep (default 5000)
920
+ * @param options which sweeps to run, plus `intervalMs` (default 5000) for the tick itself
921
921
  */
922
922
  startMaintenance(options?: MaintenanceOptions): void;
923
923
  /** Stop the periodic maintenance tick. Safe to call when not started. */
@@ -4159,7 +4159,7 @@ class AssignmentMatcher {
4159
4159
  * Start the periodic maintenance tick. Idempotent; a second call with
4160
4160
  * different options replaces the first.
4161
4161
  *
4162
- * @param options.intervalMs how often to sweep (default 5000)
4162
+ * @param options which sweeps to run, plus `intervalMs` (default 5000) for the tick itself
4163
4163
  */
4164
4164
  startMaintenance(options) {
4165
4165
  this.stopMaintenance();
@@ -1 +1 @@
1
- {"version":3,"file":"constraint.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/constraint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA4BzF,MAAM,WAAW,wBAAwB;IACrC,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;IACvB,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,qFAAqF;IACrF,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,wBAAwB,GAAG,oBAAoB,EAAE,CAkClG"}
1
+ {"version":3,"file":"constraint.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/constraint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA+BzF,MAAM,WAAW,wBAAwB;IACrC,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;IACvB,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,qFAAqF;IACrF,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,wBAAwB,GAAG,oBAAoB,EAAE,CA6ClG"}
@@ -40,6 +40,9 @@ const contract_1 = require("./contract");
40
40
  const overtime_1 = require("./overtime");
41
41
  const duty_quota_1 = require("./duty-quota");
42
42
  const cost_1 = require("./cost");
43
+ const site_eligibility_1 = require("./site-eligibility");
44
+ const site_travel_gap_1 = require("./site-travel-gap");
45
+ const site_home_1 = require("./site-home");
43
46
  /**
44
47
  * The built-in constraints in evaluation order.
45
48
  *
@@ -86,12 +89,15 @@ function createDefaultConstraints(options) {
86
89
  constraints.push((0, fairness_1.fairness)(rules.fairness));
87
90
  // Always-on person-scoped rules: they no-op unless the employee carries the
88
91
  // relevant data, so they cost nothing for simple rosters.
89
- constraints.push((0, availability_1.availability)(), (0, qualification_1.qualification)(), (0, group_composition_1.groupComposition)(), (0, protections_1.protections)(), (0, contract_1.contractLimits)());
92
+ constraints.push((0, availability_1.availability)(), (0, qualification_1.qualification)(), (0, group_composition_1.groupComposition)(), (0, protections_1.protections)(), (0, contract_1.contractLimits)(), (0, site_eligibility_1.siteEligibility)(), (0, site_travel_gap_1.siteTravelGap)());
90
93
  // The cost term is score-only: its verdict always passes, so it steers the
91
94
  // search without ever appearing as a violation.
92
95
  const costWeight = options.objectives?.costWeightPerEuro;
93
96
  if (costWeight !== undefined && costWeight > 0)
94
97
  constraints.push((0, cost_1.costObjective)(costWeight));
98
+ const homeSiteWeight = options.objectives?.homeSiteWeight;
99
+ if (homeSiteWeight !== undefined && homeSiteWeight > 0)
100
+ constraints.push((0, site_home_1.siteHomePreference)(homeSiteWeight));
95
101
  return constraints;
96
102
  }
97
103
  exports.createDefaultConstraints = createDefaultConstraints;
@@ -17,5 +17,6 @@
17
17
  * outruns the contract.
18
18
  */
19
19
  import type { SchedulingConstraint } from '../types';
20
+ export declare const CONTRACT_HOURS_CITATION = "Contract of employment; Directive 97/81/EC cl. 4 (pro rata temporis)";
20
21
  export declare function contractLimits(): SchedulingConstraint;
21
22
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,wBAAgB,cAAc,IAAI,oBAAoB,CAkHrD"}
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,eAAO,MAAM,uBAAuB,yEAAyE,CAAC;AAE9G,wBAAgB,cAAc,IAAI,oBAAoB,CAmKrD"}
@@ -18,8 +18,9 @@
18
18
  * outruns the contract.
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.contractLimits = void 0;
21
+ exports.contractLimits = exports.CONTRACT_HOURS_CITATION = void 0;
22
22
  const support_1 = require("./support");
23
+ exports.CONTRACT_HOURS_CITATION = 'Contract of employment; Directive 97/81/EC cl. 4 (pro rata temporis)';
23
24
  function contractLimits() {
24
25
  const constraint = (0, support_1.fromVerdict)({
25
26
  id: 'contract',
@@ -77,17 +78,39 @@ function contractLimits() {
77
78
  unit: 'days',
78
79
  });
79
80
  }
80
- if (contract.maxPeriodMinutes !== undefined) {
81
- const worked = attributable.reduce((sum, e) => {
82
- const overlap = Math.min(e.end, periodWindow.end) - Math.max(e.start, periodWindow.start);
83
- const span = e.end - e.start;
84
- return sum + (span > 0 ? Math.round((e.workingMinutes * Math.max(0, overlap)) / span) : 0);
85
- }, 0);
86
- if (worked > contract.maxPeriodMinutes) {
87
- return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(worked)}, over their ${(0, support_1.h)(contract.maxPeriodMinutes)} contract maximum`, { actual: worked, required: contract.maxPeriodMinutes, unit: 'minutes' });
88
- }
81
+ const contracted = state.ctx.contractedPeriodMinutes.get(pair.employeeId);
82
+ const maxOver = (0, support_1.rulesFor)(state.ctx, pair.employeeId).contract?.maxOverMinutes;
83
+ if (contract.maxPeriodMinutes === undefined && contracted === undefined) {
84
+ return (0, support_1.pass)('contract', 'within contract limits');
85
+ }
86
+ const worked = attributable.reduce((sum, e) => {
87
+ const overlap = Math.min(e.end, periodWindow.end) - Math.max(e.start, periodWindow.start);
88
+ const span = e.end - e.start;
89
+ return sum + (span > 0 ? Math.round((e.workingMinutes * Math.max(0, overlap)) / span) : 0);
90
+ }, 0);
91
+ if (contract.maxPeriodMinutes !== undefined && worked > contract.maxPeriodMinutes) {
92
+ return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(worked)}, over their ${(0, support_1.h)(contract.maxPeriodMinutes)} contract maximum`, { actual: worked, required: contract.maxPeriodMinutes, unit: 'minutes' });
93
+ }
94
+ // The contracted week pro-rated to the period, plus whatever
95
+ // surplus the rules allow. Whether the surplus is a breach or
96
+ // merely overtime is the caller's regime, which is why the cap
97
+ // is opt-in.
98
+ if (contracted !== undefined && maxOver !== undefined && worked > contracted + maxOver) {
99
+ return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(worked)}, over their ${(0, support_1.h)(contracted)} contracted for the period` +
100
+ (maxOver > 0 ? ` (${(0, support_1.h)(maxOver)} over allowed)` : ''), {
101
+ actual: worked,
102
+ required: contracted + maxOver,
103
+ unit: 'minutes',
104
+ citation: (0, support_1.rulesFor)(state.ctx, pair.employeeId).contract?.citation ?? exports.CONTRACT_HOURS_CITATION,
105
+ });
89
106
  }
90
- return (0, support_1.pass)('contract', 'within contract limits');
107
+ return contracted === undefined
108
+ ? (0, support_1.pass)('contract', 'within contract limits')
109
+ : (0, support_1.pass)('contract', `${(0, support_1.h)(worked)} of ${(0, support_1.h)(contracted)} contracted for the period`, {
110
+ actual: worked,
111
+ required: contracted,
112
+ unit: 'minutes',
113
+ });
91
114
  });
92
115
  },
93
116
  });
@@ -98,19 +121,41 @@ function contractLimits() {
98
121
  const out = [];
99
122
  for (const employee of state.ctx.employees) {
100
123
  const contract = employee.contract;
101
- if (!contract || contract.kind === 'days' || contract.minPeriodMinutes === undefined)
124
+ if (!contract)
102
125
  continue;
103
126
  const worked = state.minutesByEmployee.get(employee.id) ?? 0;
104
- if (worked >= contract.minPeriodMinutes)
127
+ if (contract.kind !== 'days' && contract.minPeriodMinutes !== undefined && worked < contract.minPeriodMinutes) {
128
+ out.push({
129
+ constraintId: 'contract',
130
+ severity: 'hard',
131
+ employeeId: employee.id,
132
+ message: `employee "${employee.id}" is rostered ${(0, support_1.h)(worked)}, below their ${(0, support_1.h)(contract.minPeriodMinutes)} contract minimum`,
133
+ actual: worked,
134
+ required: contract.minPeriodMinutes,
135
+ unit: 'minutes',
136
+ });
137
+ }
138
+ // A shortfall against the contracted week is a report, not a
139
+ // breach: the roster is short of what the person is owed, which
140
+ // the manager needs to see, but blocking on it would stall the
141
+ // very assignments that close it.
142
+ const rule = (0, support_1.rulesFor)(state.ctx, employee.id).contract;
143
+ const contracted = state.ctx.contractedPeriodMinutes.get(employee.id);
144
+ if (rule?.maxUnderMinutes === undefined || contracted === undefined)
145
+ continue;
146
+ const shortfall = contracted - worked;
147
+ if (shortfall <= rule.maxUnderMinutes)
105
148
  continue;
149
+ const fte = contract.fte !== undefined ? ` (${contract.fte} FTE)` : '';
106
150
  out.push({
107
151
  constraintId: 'contract',
108
- severity: 'hard',
152
+ severity: 'soft',
109
153
  employeeId: employee.id,
110
- message: `employee "${employee.id}" is rostered ${(0, support_1.h)(worked)}, below their ${(0, support_1.h)(contract.minPeriodMinutes)} contract minimum`,
154
+ message: `employee "${employee.id}" is planned ${(0, support_1.h)(worked)} against ${(0, support_1.h)(contracted)} contracted for the period${fte}, ${(0, support_1.h)(shortfall)} short`,
111
155
  actual: worked,
112
- required: contract.minPeriodMinutes,
156
+ required: contracted - rule.maxUnderMinutes,
113
157
  unit: 'minutes',
158
+ citation: rule.citation ?? exports.CONTRACT_HOURS_CITATION,
114
159
  });
115
160
  }
116
161
  return out;
@@ -136,7 +136,7 @@ function shareWeights(state, rule, employeeIds) {
136
136
  weights.set(id, 1);
137
137
  continue;
138
138
  }
139
- const weekly = state.ctx.employeeById.get(id)?.contract?.weeklyMinutes;
139
+ const weekly = state.ctx.contractedWeeklyMinutes.get(id);
140
140
  weights.set(id, weekly && weekly > 0 ? weekly : 1);
141
141
  }
142
142
  return weights;
@@ -1 +1 @@
1
- {"version":3,"file":"overtime.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/overtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAY,WAAW,EAAE,YAAY,EAAe,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAgBpH,eAAO,MAAM,iBAAiB,2FAAuE,CAAC;AAEtG;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,SAAU,GAAG,IAAI,CAYjF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,oBAAoB,CAkFjE;AAOD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,EAAE,CAiBhE"}
1
+ {"version":3,"file":"overtime.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/overtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAY,WAAW,EAAE,YAAY,EAAe,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAgBpH,eAAO,MAAM,iBAAiB,2FAAuE,CAAC;AAEtG;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,SAAU,GAAG,IAAI,CAYjF;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,oBAAoB,CAoFjE;AAOD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,GAAG,WAAW,EAAE,CAiBhE"}
@@ -65,7 +65,9 @@ function overtime(rule) {
65
65
  return (0, support_1.pass)('overtime', 'no overtime rule applies to this employee');
66
66
  const citation = applied.citation ?? exports.OVERTIME_CITATION;
67
67
  const employee = state.ctx.employeeById.get(pair.employeeId);
68
- const weeklyOrdinary = employee?.contract?.weeklyMinutes ?? applied.ordinaryPerWeekMinutes;
68
+ // The contracted week is resolved once in the model (explicit
69
+ // minutes or `fte` × full-time week), never re-derived here.
70
+ const weeklyOrdinary = state.ctx.contractedWeeklyMinutes.get(pair.employeeId) ?? applied.ordinaryPerWeekMinutes;
69
71
  const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
70
72
  const range = (0, support_1.rangeOf)(inst);
71
73
  const probe = { ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes, tag: inst.shiftTypeTag };
@@ -141,7 +143,7 @@ function overtimeLedger(state) {
141
143
  exports.overtimeLedger = overtimeLedger;
142
144
  /** Working minutes past the pro-rated weekly baseline over the whole period. */
143
145
  function periodOvertimeMinutes(state, employee, rule) {
144
- const weeklyOrdinary = employee.contract?.weeklyMinutes ?? rule.ordinaryPerWeekMinutes;
146
+ const weeklyOrdinary = state.ctx.contractedWeeklyMinutes.get(employee.id) ?? rule.ordinaryPerWeekMinutes;
145
147
  if (weeklyOrdinary === undefined)
146
148
  return 0;
147
149
  const baseline = Math.round((weeklyOrdinary * state.ctx.periodDays) / 7);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Site eligibility — a hard allow-list per employee.
3
+ *
4
+ * When an employee carries `siteIds`, they may only be assigned to shifts whose
5
+ * `siteId` is in that list. Shifts without a site remain open to everyone, and
6
+ * employees without the list remain eligible everywhere, so existing inputs are
7
+ * unaffected.
8
+ */
9
+ import type { SchedulingConstraint } from '../types';
10
+ export declare function siteEligibility(): SchedulingConstraint;
11
+ //# sourceMappingURL=site-eligibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-eligibility.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/site-eligibility.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAkB,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAGlF,wBAAgB,eAAe,IAAI,oBAAoB,CAsCtD"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * Site eligibility — a hard allow-list per employee.
4
+ *
5
+ * When an employee carries `siteIds`, they may only be assigned to shifts whose
6
+ * `siteId` is in that list. Shifts without a site remain open to everyone, and
7
+ * employees without the list remain eligible everywhere, so existing inputs are
8
+ * unaffected.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.siteEligibility = void 0;
12
+ const support_1 = require("./support");
13
+ function siteEligibility() {
14
+ return (0, support_1.fromVerdict)({
15
+ id: 'site-eligibility',
16
+ hardness: 'hard',
17
+ prune(ctx, eligibility) {
18
+ for (const [employeeId, instances] of eligibility) {
19
+ const allowed = ctx.employeeById.get(employeeId)?.siteIds;
20
+ if (!allowed || allowed.length === 0)
21
+ continue;
22
+ for (const instanceId of [...instances]) {
23
+ const inst = ctx.instanceById.get(instanceId);
24
+ if (inst?.siteId && !allowed.includes(inst.siteId)) {
25
+ instances.delete(instanceId);
26
+ }
27
+ }
28
+ }
29
+ },
30
+ verdict(state, pair) {
31
+ const inst = (0, support_1.instanceOf)(state, pair);
32
+ const employee = state.ctx.employeeById.get(pair.employeeId);
33
+ const siteId = inst?.siteId;
34
+ const allowed = employee?.siteIds;
35
+ if (!siteId || !allowed || allowed.length === 0) {
36
+ return (0, support_1.pass)('site-eligibility', 'no site restriction');
37
+ }
38
+ if (allowed.includes(siteId)) {
39
+ return (0, support_1.pass)('site-eligibility', `eligible for site "${siteId}"`);
40
+ }
41
+ return {
42
+ ruleId: 'site-eligibility',
43
+ pass: false,
44
+ severity: 'hard',
45
+ message: `employee "${pair.employeeId}" is not eligible for site "${siteId}"`,
46
+ actual: 0,
47
+ required: 1,
48
+ };
49
+ },
50
+ });
51
+ }
52
+ exports.siteEligibility = siteEligibility;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Home-site preference — a soft objective term.
3
+ *
4
+ * Opt-in via `ScheduleInput.objectives.homeSiteWeight`. The term contributes
5
+ * `weight` points for every assignment where the employee has a `homeSiteId`
6
+ * that differs from the shift's site. It never blocks an assignment; it merely
7
+ * steers the solver toward rosters that keep people at their home site.
8
+ *
9
+ * Like the cost term, this is declared data, not a behavioural or predictive
10
+ * signal, so it does not affect the `profilingFree` provenance claim.
11
+ */
12
+ import type { SchedulingConstraint } from '../types';
13
+ export declare function siteHomePreference(weight: number): SchedulingConstraint;
14
+ //# sourceMappingURL=site-home.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-home.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/site-home.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAkB,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAGlF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CA2BvE"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ /**
3
+ * Home-site preference — a soft objective term.
4
+ *
5
+ * Opt-in via `ScheduleInput.objectives.homeSiteWeight`. The term contributes
6
+ * `weight` points for every assignment where the employee has a `homeSiteId`
7
+ * that differs from the shift's site. It never blocks an assignment; it merely
8
+ * steers the solver toward rosters that keep people at their home site.
9
+ *
10
+ * Like the cost term, this is declared data, not a behavioural or predictive
11
+ * signal, so it does not affect the `profilingFree` provenance claim.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.siteHomePreference = void 0;
15
+ const support_1 = require("./support");
16
+ function siteHomePreference(weight) {
17
+ return (0, support_1.fromVerdict)({
18
+ id: 'site-home',
19
+ hardness: 'soft',
20
+ weight,
21
+ verdict(state, pair) {
22
+ const inst = (0, support_1.instanceOf)(state, pair);
23
+ const employee = state.ctx.employeeById.get(pair.employeeId);
24
+ const shiftSite = inst?.siteId;
25
+ const homeSite = employee?.homeSiteId;
26
+ if (!shiftSite || !homeSite) {
27
+ return (0, support_1.pass)('site-home', 'no home-site preference configured');
28
+ }
29
+ if (shiftSite === homeSite) {
30
+ return (0, support_1.pass)('site-home', `home site (${shiftSite})`);
31
+ }
32
+ return {
33
+ ruleId: 'site-home',
34
+ pass: false,
35
+ severity: 'soft',
36
+ message: `based at site "${homeSite}", shift at site "${shiftSite}"`,
37
+ actual: 1,
38
+ required: 0,
39
+ };
40
+ },
41
+ });
42
+ }
43
+ exports.siteHomePreference = siteHomePreference;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Cross-site travel gap.
3
+ *
4
+ * When a person works two consecutive assignments at different sites, the gap
5
+ * between them must be at least the travel time between those sites. Only the
6
+ * immediate predecessor and successor on the person timeline are judged; a
7
+ * non-adjacent assignment does not create a direct travel obligation.
8
+ *
9
+ * The rule only enforces the gap; it does **not** count travel time as working
10
+ * time (CJEU C-266/14 would require that, but it is out of scope here — the
11
+ * caller models working time through `duty` and break rules).
12
+ *
13
+ * Because the default `min-rest` rule requires 11h between any two assignments,
14
+ * this rule mainly matters in split-shift setups where the caller has relaxed
15
+ * `minRestMinutes` or configured a `dailyRest` rule with a shorter window.
16
+ */
17
+ import type { SchedulingConstraint } from '../types';
18
+ export declare function siteTravelGap(): SchedulingConstraint;
19
+ //# sourceMappingURL=site-travel-gap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"site-travel-gap.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/site-travel-gap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAA+B,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAK/F,wBAAgB,aAAa,IAAI,oBAAoB,CA2EpD"}