Plan service and weekly plan API #114

Member

Maestro task ea48e650-d510-49cc-8485-0f07174ee731 - "Plan service and API" (Feature 14: Weekly Plan Builder).

Done-condition: GET /api/v1/plans/{weekStart} returns the plan (status draft|synced|changed, ai_note, calendar_synced_at, week label) with 7 days {date, dinner {id, name, photo, minutes, method, origin}, is_new, start_by} or 404 if none, with a non-Monday weekStart rejected 400; POST /plans/{weekStart}/draft enqueues a draft_week job from the Regulars + Quest log pool and returns 202 {jobId}, requiring {"confirm": true} over a synced or changed plan (409 otherwise); PUT /plans/{weekStart}/days/{date} {dinner_id} swaps a day, recomputes is_new and moves a synced plan to changed; is_new = the dinner came from the Quest log; start_by = dinner_time minus minutes_total for crock-pot dinners; tests cover draft creation, the confirm rule, swap, status transitions, start_by and the non-Monday 400; Go quality floor passes.

Calls the merged draft_week skill v1 through the harness, uses internal/jobs for the async draft, internal/household for Monday-start week math and internal/dinners for the dinner pool; sqlc regenerated for the new plans queries. The rotation check (a1887d1c) and all UI tasks come later; no calendar calls here (Feature 16 owns Push to Calendar).

Maestro task `ea48e650-d510-49cc-8485-0f07174ee731` - "Plan service and API" (Feature 14: Weekly Plan Builder). Done-condition: GET /api/v1/plans/{weekStart} returns the plan (status draft|synced|changed, ai_note, calendar_synced_at, week label) with 7 days {date, dinner {id, name, photo, minutes, method, origin}, is_new, start_by} or 404 if none, with a non-Monday weekStart rejected 400; POST /plans/{weekStart}/draft enqueues a draft_week job from the Regulars + Quest log pool and returns 202 {jobId}, requiring {"confirm": true} over a synced or changed plan (409 otherwise); PUT /plans/{weekStart}/days/{date} {dinner_id} swaps a day, recomputes is_new and moves a synced plan to changed; is_new = the dinner came from the Quest log; start_by = dinner_time minus minutes_total for crock-pot dinners; tests cover draft creation, the confirm rule, swap, status transitions, start_by and the non-Monday 400; Go quality floor passes. Calls the merged draft_week skill v1 through the harness, uses internal/jobs for the async draft, internal/household for Monday-start week math and internal/dinners for the dinner pool; sqlc regenerated for the new plans queries. The rotation check (a1887d1c) and all UI tasks come later; no calendar calls here (Feature 16 owns Push to Calendar).
orchestrator-agent added 1 commit 2026-10-07 06:19:18 -04:00
Add plan service and weekly plan API
CI / ci (push) Successful in 3m20s
CI / ci (pull_request) Successful in 3m1s
75d6ad4e19
Add internal/plan: a draft_week job that drafts the week through the
harness from every Regular and the Quest log dinners no other current or
later plan holds, given the household context and last week's dinners,
and stores it as the week's plan; plan reads with the week label, is_new
and each crock-pot dinner's start_by (dinner time minus minutes_total,
computed on read); and day swaps that recompute is_new and move a synced
plan to changed. Drafting over a synced or changed plan needs confirm, at
enqueue and again when the job stores the week; a redraft keeps each
day's calendar event id.

Serve GET /api/v1/plans/{weekStart}, POST /api/v1/plans/{weekStart}/draft
(202 {job_id}, single-flight per week) and PUT
/api/v1/plans/{weekStart}/days/{date}; a weekStart that is not a Monday
is 400 invalid_week.

Maestro task ea48e650-d510-49cc-8485-0f07174ee731.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
review_agent requested changes 2026-10-07 06:23:30 -04:00
Dismissed
review_agent left a comment
Member

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.
overseer added 1 commit 2026-10-07 06:32:54 -04:00
Guard plan drafts against swaps and keep confirm on single-flight
CI / ci (push) Successful in 3m20s
CI / ci (pull_request) Successful in 3m6s
7e6e49f6b1
Return the draft job id as jobId, as the plan API contract specifies.

Add a week_plans revision (migration 0013) that every swap and stored
draft raises. A draft_week job reads the revision before draft_week runs
and stores its week only while the plan still has it; a plan edited
while the AI ran is left as it is and the job fails plan_changed, so a
draft never erases the household's swap.

A confirmed draft now joins only a confirmed queued or running job, so a
job asked for without confirm can no longer fail it with
confirm_required after the plan was synced.

Test simultaneous drafts, a swap during a draft, a confirmed draft while
an unconfirmed one runs, impossible calendar dates and start_by across
the end of daylight saving time.

Maestro task ea48e650-d510-49cc-8485-0f07174ee731.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
review_agent requested changes 2026-10-07 06:38:46 -04:00
Dismissed
review_agent left a comment
Member

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.
overseer added 1 commit 2026-10-07 06:46:15 -04:00
Keep one draft in flight per week
CI / ci (push) Successful in 3m26s
CI / ci (pull_request) Successful in 3m10s
45fcd71d27
A confirmed draft asked for while the week's draft job was asked for
without confirm no longer enqueues a second job. With two job workers the
two drafts ran at once, and whichever stored second failed plan_changed,
so the household's confirmed draft could fail. StartDraft now refuses it
with ErrDraftRunning, 409 draft_running, and enqueues nothing; the
household asks again once the running draft finishes. Every other draft
joins the week's queued or running job, so a week has at most one.

The plan tests run the job runner with two workers, as cmd/server does,
and a confirmed draft during a running unconfirmed one is refused while
only the running job drafts.

Maestro task ea48e650-d510-49cc-8485-0f07174ee731.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
review_agent requested changes 2026-10-07 06:52:26 -04:00
Dismissed
review_agent left a comment
Member

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.

Independent Codex gpt-6-sol review: CHANGES_REQUIRED for this exact commit.
overseer added 1 commit 2026-10-07 06:57:56 -04:00
Refuse draft_week jobs on the generic jobs endpoint
CI / ci (push) Successful in 3m28s
CI / ci (pull_request) Successful in 3m10s
1f548c9f1d
A kind can now be made service-only: Runner.Enqueue, and so
POST /api/v1/jobs, refuses it with 400 service_only_kind, and only its
typed Kind enqueues it. draft_week is service-only, so StartDraft and
its one-draft-in-flight-per-week rule is the only way to start a draft;
a confirmed draft_week posted to /api/v1/jobs can no longer run beside
the week's unconfirmed draft.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
review_agent left a comment
Member

Independent Codex gpt-6-sol review: APPROVED for this exact commit.

Independent Codex gpt-6-sol review: APPROVED for this exact commit.
approver_agent merged commit 2ed5f69783 into feature/ca2a118d-0beb-49f9-b2ef-d5ed0ac1fa2a-weekly-plan-builder 2026-10-07 07:04:51 -04:00
Sign in to join this conversation.
No Reviewers
No labels
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Maniacs_Mansion/MealQuest#114