Extends can_craft + craft to take a `locale` parameter that describes
WHERE inputs come from and WHERE outputs go. Two forms are accepted;
the v0.1 single-container call signature continues to work unchanged
via a transparent bw-compat shim.
Locale-Schema:
Form 1 (bw-compat): a bare container-entity-handle. Internally
wrapped to {sources={h}, sink=h}; the single
container is both the sole input source AND the
output sink. v0.1 call sites need no migration.
Form 2 (explicit): { sources = {c1, c2, ...}, sink = c_out } where
sources is a non-empty array of container-entity-
handles and sink is a single container-entity-
handle. sink MAY appear in sources (e.g. workbench
buffer as both source and sink).
can_craft aggregates input counts across the union of all sources
before comparing against the recipe's needs. `missing` entries report
the aggregated `have` count across sources.
craft greedy-drains in array-order: for each input.need it walks
sources left-to-right, fully draining matching-template items from
the first source before moving on to the next. The order is stable
and deterministic so callers can encode priority via the array.
A file-local resolve_locale helper centralizes the Form-1-vs-Form-2
dispatch and validates Form 2 with loud errors:
locale == nil → "locale must not be nil"
Form 2, sources not array or empty → "sources must be non-empty array"
Form 2, sink == nil → "sink must not be nil"
The count_by_template helper now takes a sources array and walks each
container's inventory in turn, summing per-template counts.
Manifest bumped 0.1.0 → 0.2.0. Deps unchanged (composition 0.3.0,
inventory-list 0.1.0). README documents both locale forms, the
greedy-drain order, the bw-compat guarantee, and the loud-error
conditions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
169 B
169 B