TaskManager: queue, cancel, and next_for(pawn) selection #67

Closed
opened 2026-09-07 20:37:18 +01:00 by liamjd · 0 comments
Owner

Part of milestone #5. Depends on #66.

The queue every user action feeds, and the thing an idle pawn asks for work. Pure logic node, no rendering, headless-testable with stub tasks.

API:

  • add(task) -> int assigns id and creation sequence, emits task_added
  • cancel(id), complete(id) with matching signals
  • next_for(pawn) -> Task: highest priority first, then oldest first; skips tasks whose can_start(ctx) is false and marks them BLOCKED; returns null when nothing is workable
  • claim(id, pawn) / release(id) so a pawn that fails mid-task hands it back as PENDING
  • all() and by_status() for the debug panel

Design notes:

  • Resolve priority through a single function (task priority combined with a global policy object) rather than reading task.priority directly. The design docs require an Emergency Protocols override that reprioritises all labour in one action; that becomes a swap of the policy, not a rewrite of selection.
  • BLOCKED tasks are re-evaluated on the next next_for call, not left blocked forever; a later issue can add event-driven unblocking.
  • Signals live on the manager (or on GameState if other systems need them without a reference; decide and note in the PR).

AC:

  • Unit tests: ordering by priority then age; blocked tasks skipped and marked; null when empty or all blocked; claim/release round trip; cancel removes from selection
Part of milestone #5. Depends on #66. The queue every user action feeds, and the thing an idle pawn asks for work. Pure logic node, no rendering, headless-testable with stub tasks. API: - `add(task) -> int` assigns id and creation sequence, emits `task_added` - `cancel(id)`, `complete(id)` with matching signals - `next_for(pawn) -> Task`: highest priority first, then oldest first; skips tasks whose `can_start(ctx)` is false and marks them BLOCKED; returns null when nothing is workable - `claim(id, pawn)` / `release(id)` so a pawn that fails mid-task hands it back as PENDING - `all()` and `by_status()` for the debug panel Design notes: - Resolve priority through a single function (task priority combined with a global policy object) rather than reading `task.priority` directly. The design docs require an Emergency Protocols override that reprioritises all labour in one action; that becomes a swap of the policy, not a rewrite of selection. - BLOCKED tasks are re-evaluated on the next `next_for` call, not left blocked forever; a later issue can add event-driven unblocking. - Signals live on the manager (or on `GameState` if other systems need them without a reference; decide and note in the PR). AC: - Unit tests: ordering by priority then age; blocked tasks skipped and marked; null when empty or all blocked; claim/release round trip; cancel removes from selection
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
liamjd/UntitledColonyBuilder#67
No description provided.