# Planning and the schedule

> How Klarity's auto-planner places tasks on the calendar, what at risk means, and how an AI agent plans a user's week or moves work over MCP.

Use this when the user asks about their week, whether something fits, or to plan or move work.

## How the planner works

- It places open tasks into free time inside the user's work hours, around their calendar events, up to three months ahead.
- Order: priority first (`urgent`, `high`, `medium`, `low`), then due date. A hard deadline goes ahead of softer work at the same priority.
- A task's length is its `estimated_minutes`; without one it is planned at 30 minutes.
- Large tasks are split into blocks of at least 30 minutes (a task can set a shorter minimum in the app), spread over the days before the due date.
- A task blocked by another (`blocked_by` on create_task/update_task) is planned after its blocker. A project's phases run in order: a task in a later phase is planned after the open tasks of the earlier ones. Nothing is placed before a task's start date.
- Only `todo` and `in_progress` tasks are planned. For work waiting on other tasks, set `blocked_by` and keep it `todo`; status `blocked` takes a task off the schedule entirely.
- **At risk**: the plan puts a task's last block after its due date, finds no slot before it, or the task is overdue. `list_at_risk_tasks` returns these from the current plan without changing it.
- **Pinned**: a block with `isAutoScheduled: false` was placed or moved by the user. Replans plan around it and never move it.
- **Replan**: runs in the background, hourly on the server and while the app is open. If a calendar cannot be read, the replan is skipped rather than planning over unseen meetings. `replan_schedule` runs it now, like the Plan week button, and returns what it placed, what does not fit and what is at risk.

## Read the week

1. `list_scheduled_blocks` with `starts_after` and `starts_before`.
2. `list_calendar_events` for the same range (it is slow: a week at most). Read `warnings`: a calendar that failed adds no events, so never call a slot free while warnings is non-empty.
3. `list_work_hours` to tell an evening from free working time.
4. `list_at_risk_tasks` for what will miss its due date.

## Change the plan

Change tasks with `update_task`; the next replan applies it.
- Sooner: raise `priority`, or set an earlier `due_date`.
- Make room: lower other work's priority, cut an estimate, or move a due date out.
- At risk: offer the fixes Resolve offers in the app: extend the due date, make it urgent, or cut the estimate. Let the user pick.
- Not before a time: set a timed `start_date`.
- An exact slot: `move_scheduled_block` moves a block and pins it, like a drag in the app; `create_scheduled_block` adds a pinned block for a task. When the target time is taken by auto-placed blocks, move it anyway and then call `replan_schedule`: unpinned blocks make room. Only ask when the slot is taken by a meeting or another pinned block.
- "Plan my week": call `replan_schedule`, then report the week from its result.

## Pitfalls

- After `update_task`, blocks show the old plan until a replan: call `replan_schedule` or say the plan updates within the hour.
